sequencer: pass absolute GIT_DIR to exec commands

When we replaced the old shell script based interactive rebase in commmit 18633e1a22a6 ("rebase -i: use the rebase--helper builtin", 2017-02-09) we introduced a regression of functionality in that the GIT_DIR would be sent to the environment of the exec command as-is. This generally meant that it would be passed as "GIT_DIR=.git", which causes problems for any exec command that wants to run git commands in a subdirectory. This isn't a very large regression, since it is not that likely that the exec command will run a git command, and even less likely that it will need to do so in a subdir. This regression was discovered by a build system which uses git-describe to find the current version of the build system, and happened to do so from the src/ sub directory of the project. Fix this by passing in the absolute path of the git directory into the child environment. Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Acked-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Keller committed Oct 31, 2017 at 16:07 UTC 09d7b6c6fab3ad131b71016b61c80d39d532befd
2 files changed +17 -1
sequencer.c
+6 -1
@@ -1821,12 +1821,15 @@ static int error_failed_squash(struct commit *commit,
1821
1822 static int do_exec(const char *command_line)
1823 {
1824 + struct argv_array child_env = ARGV_ARRAY_INIT;
1825 const char *child_argv[] = { NULL, NULL };
1826 int dirty, status;
1827
1828 fprintf(stderr, "Executing: %s\n", command_line);
1829 child_argv[0] = command_line;
1829 - status = run_command_v_opt(child_argv, RUN_USING_SHELL);
1830 + argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
1831 + status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
1832 + child_env.argv);
1833
1834 /* force re-reading of the cache */
1835 if (discard_cache() < 0 || read_cache() < 0)
@@ -1856,6 +1859,8 @@ static int do_exec(const char *command_line)
1859 status = 1;
1860 }
1861
1862 + argv_array_clear(&child_env);
1863 +
1864 return status;
1865 }
1866
t/t3404-rebase-interactive.sh
+11
@@ -108,6 +108,17 @@ test_expect_success 'rebase -i with the exec command runs from tree root' '
108 rm -fr subdir
109 '
110
111 +test_expect_success 'rebase -i with exec allows git commands in subdirs' '
112 + test_when_finished "rm -rf subdir" &&
113 + test_when_finished "git rebase --abort ||:" &&
114 + git checkout master &&
115 + mkdir subdir && (cd subdir &&
116 + set_fake_editor &&
117 + FAKE_LINES="1 exec_cd_subdir_&&_git_rev-parse_--is-inside-work-tree" \
118 + git rebase -i HEAD^
119 + )
120 +'
121 +
122 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
123 git checkout master &&
124 set_fake_editor &&