@@ -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+
5188docker_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
93130docker_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"
0 commit comments