@matheusbsbs / matheus-bagliano / commits / 7cf16a14f5
Fork 0

handle_alias: provide GIT_PREFIX to !alias

Provide an environment variable GIT_PREFIX which contains the subdirectory from which a !alias was called (i.e. 'git rev-parse --show-prefix') since these cd to the to level directory before they are executed. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michael J Gruber committed Apr 27, 2011 at 10:36 UTC 7cf16a14f5c070f7b14cf28023769450133172ae
3 files changed +21 -1
Documentation/config.txt
+2
@@ -589,6 +589,8 @@ it will be treated as a shell command. For example, defining
589 "gitk --all --not ORIG_HEAD". Note that shell commands will be
590 executed from the top-level directory of a repository, which may
591 not necessarily be the current directory.
592 +'GIT_PREFIX' is set as returned by running 'git rev-parse --show-prefix'
593 +from the original current directory. See linkgit:git-rev-parse[1].
594
595 am.keepcr::
596 If true, git-am will call git-mailsplit for patches in mbox format
git.c
+9 -1
@@ -179,6 +179,8 @@ static int handle_alias(int *argcp, const char ***argv)
179 if (alias_string[0] == '!') {
180 const char **alias_argv;
181 int argc = *argcp, i;
182 + struct strbuf sb = STRBUF_INIT;
183 + const char *env[2];
184
185 commit_pager_choice();
186
@@ -189,7 +191,13 @@ static int handle_alias(int *argcp, const char ***argv)
191 alias_argv[i] = (*argv)[i];
192 alias_argv[argc] = NULL;
193
192 - ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
194 + strbuf_addstr(&sb, "GIT_PREFIX=");
195 + if (subdir)
196 + strbuf_addstr(&sb, subdir);
197 + env[0] = sb.buf;
198 + env[1] = NULL;
199 + ret = run_command_v_opt_cd_env(alias_argv, RUN_USING_SHELL, NULL, env);
200 + strbuf_release(&sb);
201 if (ret >= 0) /* normal exit */
202 exit(ret);
203
t/t1020-subdirectory.sh
+10
@@ -129,6 +129,16 @@ test_expect_success '!alias expansion' '
129 test_cmp expect actual
130 '
131
132 +test_expect_success 'GIT_PREFIX for !alias' '
133 + printf "dir/" >expect &&
134 + (
135 + git config alias.test "!sh -c \"printf \$GIT_PREFIX\"" &&
136 + cd dir &&
137 + git test >../actual
138 + ) &&
139 + test_cmp expect actual
140 +'
141 +
142 test_expect_success 'no file/rev ambiguity check inside .git' '
143 git commit -a -m 1 &&
144 (