Skip to content

Commit adfc49e

Browse files
committed
Merge branch 'jk/rebase-i-exec-gitdir-fix' into maint
A recent regression in "git rebase -i" that broke execution of git commands from subdirectories via "exec" insn has been fixed. * jk/rebase-i-exec-gitdir-fix: sequencer: pass absolute GIT_DIR to exec commands
2 parents fd7c38c + 09d7b6c commit adfc49e

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
@@ -1862,12 +1862,15 @@ static int error_failed_squash(struct commit *commit,
18621862

18631863
static int do_exec(const char *command_line)
18641864
{
1865+
struct argv_array child_env = ARGV_ARRAY_INIT;
18651866
const char *child_argv[] = { NULL, NULL };
18661867
int dirty, status;
18671868

18681869
fprintf(stderr, "Executing: %s\n", command_line);
18691870
child_argv[0] = command_line;
1870-
status = run_command_v_opt(child_argv, RUN_USING_SHELL);
1871+
argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
1872+
status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
1873+
child_env.argv);
18711874

18721875
/* force re-reading of the cache */
18731876
if (discard_cache() < 0 || read_cache() < 0)
@@ -1897,6 +1900,8 @@ static int do_exec(const char *command_line)
18971900
status = 1;
18981901
}
18991902

1903+
argv_array_clear(&child_env);
1904+
19001905
return status;
19011906
}
19021907

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)