Skip to content

Commit 09d7b6c

Browse files
jacob-kellergitster
authored andcommitted
sequencer: pass absolute GIT_DIR to exec commands
When we replaced the old shell script based interactive rebase in commmit 18633e1 ("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 <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 098ed50 commit 09d7b6c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

sequencer.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,12 +1821,15 @@ static int error_failed_squash(struct commit *commit,
18211821

18221822
static int do_exec(const char *command_line)
18231823
{
1824+
struct argv_array child_env = ARGV_ARRAY_INIT;
18241825
const char *child_argv[] = { NULL, NULL };
18251826
int dirty, status;
18261827

18271828
fprintf(stderr, "Executing: %s\n", command_line);
18281829
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);
18301833

18311834
/* force re-reading of the cache */
18321835
if (discard_cache() < 0 || read_cache() < 0)
@@ -1856,6 +1859,8 @@ static int do_exec(const char *command_line)
18561859
status = 1;
18571860
}
18581861

1862+
argv_array_clear(&child_env);
1863+
18591864
return status;
18601865
}
18611866

t/t3404-rebase-interactive.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,17 @@ test_expect_success 'rebase -i with the exec command runs from tree root' '
108108
rm -fr subdir
109109
'
110110

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+
111122
test_expect_success 'rebase -i with the exec command checks tree cleanness' '
112123
git checkout master &&
113124
set_fake_editor &&

0 commit comments

Comments
 (0)