Skip to content

Commit 76f4f74

Browse files
committed
Merge branch 'mg/alias-expose-prefix'
* mg/alias-expose-prefix: handle_alias: provide GIT_PREFIX to !alias t1020: test !alias in subdirectory
2 parents 12b99a3 + 7cf16a1 commit 76f4f74

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

Documentation/config.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,8 @@ it will be treated as a shell command. For example, defining
587587
"gitk --all --not ORIG_HEAD". Note that shell commands will be
588588
executed from the top-level directory of a repository, which may
589589
not necessarily be the current directory.
590+
'GIT_PREFIX' is set as returned by running 'git rev-parse --show-prefix'
591+
from the original current directory. See linkgit:git-rev-parse[1].
590592

591593
am.keepcr::
592594
If true, git-am will call git-mailsplit for patches in mbox format

git.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ static int handle_alias(int *argcp, const char ***argv)
179179
if (alias_string[0] == '!') {
180180
const char **alias_argv;
181181
int argc = *argcp, i;
182+
struct strbuf sb = STRBUF_INIT;
183+
const char *env[2];
182184

183185
commit_pager_choice();
184186

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

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);
193201
if (ret >= 0) /* normal exit */
194202
exit(ret);
195203

t/t1020-subdirectory.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,27 @@ test_expect_success 'alias expansion' '
118118
git ss
119119
)
120120
'
121+
122+
test_expect_success '!alias expansion' '
123+
pwd >expect &&
124+
(
125+
git config alias.test !pwd &&
126+
cd dir &&
127+
git test >../actual
128+
) &&
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+
121142
test_expect_success 'no file/rev ambiguity check inside .git' '
122143
git commit -a -m 1 &&
123144
(

0 commit comments

Comments
 (0)