Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,43 @@ docker_git_git_subcommand() {
return 1
}

docker_git_git_resolve_repo_root() {
local -a git_context=()
local expect_value="0"
local arg=""

for arg in "$@"; do
if [[ "$expect_value" == "1" ]]; then
git_context+=("$arg")
expect_value="0"
continue
fi

case "$arg" in
-c|-C|--git-dir|--work-tree|--namespace|--exec-path|--super-prefix|--config-env)
git_context+=("$arg")
expect_value="1"
continue
;;
--git-dir=*|--work-tree=*|--namespace=*|--exec-path=*|--super-prefix=*|--config-env=*|--bare|--no-pager|--paginate|--literal-pathspecs|--no-literal-pathspecs|--glob-pathspecs|--noglob-pathspecs|--icase-pathspecs|--no-optional-locks|--no-lazy-fetch)
git_context+=("$arg")
continue
;;
--)
break
;;
-*)
continue
;;
*)
break
;;
esac
done

"$DOCKER_GIT_REAL_GIT_BIN" "${"${"}git_context[@]}" rev-parse --show-toplevel 2>/dev/null
}

docker_git_git_push_is_dry_run() {
local expect_value="0"
local parsing_push_args="0"
Expand Down Expand Up @@ -91,12 +128,18 @@ docker_git_git_push_is_dry_run() {
}

docker_git_post_push_action() {
local repo_root=""

if [[ "${"${"}DOCKER_GIT_SKIP_POST_PUSH_ACTION:-}" == "1" ]]; then
return 0
fi

if [[ -x "$DOCKER_GIT_POST_PUSH_ACTION" ]]; then
DOCKER_GIT_SKIP_POST_PUSH_ACTION=1 "$DOCKER_GIT_POST_PUSH_ACTION" || true
if repo_root="$(docker_git_git_resolve_repo_root "$@")" && [[ -n "$repo_root" ]]; then
DOCKER_GIT_POST_PUSH_REPO_ROOT="$repo_root" DOCKER_GIT_SKIP_POST_PUSH_ACTION=1 "$DOCKER_GIT_POST_PUSH_ACTION" || true
else
DOCKER_GIT_SKIP_POST_PUSH_ACTION=1 "$DOCKER_GIT_POST_PUSH_ACTION" || true
fi
fi
}

Expand All @@ -109,7 +152,7 @@ if subcommand="$(docker_git_git_subcommand "$@")" && [[ "$subcommand" == "push"
fi

if [[ "$status" -eq 0 ]] && ! docker_git_git_push_is_dry_run "$@"; then
docker_git_post_push_action
docker_git_post_push_action "$@"
fi

exit "$status"
Expand Down
5 changes: 4 additions & 1 deletion packages/lib/src/core/templates-entrypoint/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,10 @@ cat <<'EOF' > "$POST_PUSH_ACTION"
set -euo pipefail

# 5) Run session backup after successful push
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
REPO_ROOT="${"${"}DOCKER_GIT_POST_PUSH_REPO_ROOT:-}"
if [[ -z "$REPO_ROOT" || ! -d "$REPO_ROOT" ]]; then
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
fi
cd "$REPO_ROOT"

# CHANGE: keep post-push backup logic in a reusable action script
Expand Down
Loading