Skip to content

Commit c613242

Browse files
authored
Merge pull request #202 from skulidropek/issue-201
fix(core): preserve post-push repo context for git -C push
2 parents b85446c + af088b8 commit c613242

File tree

4 files changed

+410
-3
lines changed

4 files changed

+410
-3
lines changed

packages/lib/src/core/templates-entrypoint/git-post-push-wrapper.ts

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,43 @@ docker_git_git_subcommand() {
4848
return 1
4949
}
5050
51+
docker_git_git_resolve_repo_root() {
52+
local -a git_context=()
53+
local expect_value="0"
54+
local arg=""
55+
56+
for arg in "$@"; do
57+
if [[ "$expect_value" == "1" ]]; then
58+
git_context+=("$arg")
59+
expect_value="0"
60+
continue
61+
fi
62+
63+
case "$arg" in
64+
-c|-C|--git-dir|--work-tree|--namespace|--exec-path|--super-prefix|--config-env)
65+
git_context+=("$arg")
66+
expect_value="1"
67+
continue
68+
;;
69+
--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)
70+
git_context+=("$arg")
71+
continue
72+
;;
73+
--)
74+
break
75+
;;
76+
-*)
77+
continue
78+
;;
79+
*)
80+
break
81+
;;
82+
esac
83+
done
84+
85+
"$DOCKER_GIT_REAL_GIT_BIN" "${"${"}git_context[@]}" rev-parse --show-toplevel 2>/dev/null
86+
}
87+
5188
docker_git_git_push_is_dry_run() {
5289
local expect_value="0"
5390
local parsing_push_args="0"
@@ -91,12 +128,18 @@ docker_git_git_push_is_dry_run() {
91128
}
92129
93130
docker_git_post_push_action() {
131+
local repo_root=""
132+
94133
if [[ "${"${"}DOCKER_GIT_SKIP_POST_PUSH_ACTION:-}" == "1" ]]; then
95134
return 0
96135
fi
97136
98137
if [[ -x "$DOCKER_GIT_POST_PUSH_ACTION" ]]; then
99-
DOCKER_GIT_SKIP_POST_PUSH_ACTION=1 "$DOCKER_GIT_POST_PUSH_ACTION" || true
138+
if repo_root="$(docker_git_git_resolve_repo_root "$@")" && [[ -n "$repo_root" ]]; then
139+
DOCKER_GIT_POST_PUSH_REPO_ROOT="$repo_root" DOCKER_GIT_SKIP_POST_PUSH_ACTION=1 "$DOCKER_GIT_POST_PUSH_ACTION" || true
140+
else
141+
DOCKER_GIT_SKIP_POST_PUSH_ACTION=1 "$DOCKER_GIT_POST_PUSH_ACTION" || true
142+
fi
100143
fi
101144
}
102145
@@ -109,7 +152,7 @@ if subcommand="$(docker_git_git_subcommand "$@")" && [[ "$subcommand" == "push"
109152
fi
110153
111154
if [[ "$status" -eq 0 ]] && ! docker_git_git_push_is_dry_run "$@"; then
112-
docker_git_post_push_action
155+
docker_git_post_push_action "$@"
113156
fi
114157
115158
exit "$status"

packages/lib/src/core/templates-entrypoint/git.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,10 @@ cat <<'EOF' > "$POST_PUSH_ACTION"
263263
set -euo pipefail
264264
265265
# 5) Run session backup after successful push
266-
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
266+
REPO_ROOT="${"${"}DOCKER_GIT_POST_PUSH_REPO_ROOT:-}"
267+
if [[ -z "$REPO_ROOT" || ! -d "$REPO_ROOT" ]]; then
268+
REPO_ROOT="$(git rev-parse --show-toplevel 2>/dev/null || pwd)"
269+
fi
267270
cd "$REPO_ROOT"
268271
269272
# CHANGE: keep post-push backup logic in a reusable action script

0 commit comments

Comments
 (0)