Skip to content

Commit

Permalink
handle_alias: provide GIT_PREFIX to !alias
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Michael J Gruber authored and Junio C Hamano committed Apr 27, 2011
1 parent 0daed41 commit 7cf16a1
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,8 @@ it will be treated as a shell command. For example, defining
"gitk --all --not ORIG_HEAD". Note that shell commands will be
executed from the top-level directory of a repository, which may
not necessarily be the current directory.
'GIT_PREFIX' is set as returned by running 'git rev-parse --show-prefix'
from the original current directory. See linkgit:git-rev-parse[1].

am.keepcr::
If true, git-am will call git-mailsplit for patches in mbox format
Expand Down
10 changes: 9 additions & 1 deletion git.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ static int handle_alias(int *argcp, const char ***argv)
if (alias_string[0] == '!') {
const char **alias_argv;
int argc = *argcp, i;
struct strbuf sb = STRBUF_INIT;
const char *env[2];

commit_pager_choice();

Expand All @@ -189,7 +191,13 @@ static int handle_alias(int *argcp, const char ***argv)
alias_argv[i] = (*argv)[i];
alias_argv[argc] = NULL;

ret = run_command_v_opt(alias_argv, RUN_USING_SHELL);
strbuf_addstr(&sb, "GIT_PREFIX=");
if (subdir)
strbuf_addstr(&sb, subdir);
env[0] = sb.buf;
env[1] = NULL;
ret = run_command_v_opt_cd_env(alias_argv, RUN_USING_SHELL, NULL, env);
strbuf_release(&sb);
if (ret >= 0) /* normal exit */
exit(ret);

Expand Down
10 changes: 10 additions & 0 deletions t/t1020-subdirectory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,16 @@ test_expect_success '!alias expansion' '
test_cmp expect actual
'

test_expect_success 'GIT_PREFIX for !alias' '
printf "dir/" >expect &&
(
git config alias.test "!sh -c \"printf \$GIT_PREFIX\"" &&
cd dir &&
git test >../actual
) &&
test_cmp expect actual
'

test_expect_success 'no file/rev ambiguity check inside .git' '
git commit -a -m 1 &&
(
Expand Down

0 comments on commit 7cf16a1

Please sign in to comment.