Merge branch 'mg/alias-expose-prefix'
authorJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2011 17:49:57 +0000 (10:49 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 6 May 2011 17:49:57 +0000 (10:49 -0700)
* mg/alias-expose-prefix:
handle_alias: provide GIT_PREFIX to !alias
t1020: test !alias in subdirectory

Documentation/config.txt
git.c
t/t1020-subdirectory.sh
index 0c0f54c30e4db1db326aa468bbef90a379f478ad..c96aec10d8124f77f558e4ee5fa0f277ccb7b3d3 100644 (file)
@@ -587,6 +587,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
diff --git a/git.c b/git.c
index ef598c3e7053b8dd2859f4d582ce2917a804fe42..ed899512f9c4220f7d7a2b9e28e1a0eb23c06b8c 100644 (file)
--- a/git.c
+++ b/git.c
@@ -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();
 
@@ -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);
 
index 1fd187c5eb188671934f6afe85ca5003c529a942..ddc3921ac6a009dfc706cd19ad94f2b29af4b1cc 100755 (executable)
@@ -118,6 +118,27 @@ test_expect_success 'alias expansion' '
                git ss
        )
 '
+
+test_expect_success '!alias expansion' '
+       pwd >expect &&
+       (
+               git config alias.test !pwd &&
+               cd dir &&
+               git test >../actual
+       ) &&
+       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 &&
        (