Skip to content

Commit e4db47e

Browse files
committed
Merge branch 'jk/rebase-i-exec-gitdir-fix'
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 662ac3b + 09d7b6c commit e4db47e

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

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

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

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

1902+
argv_array_clear(&child_env);
1903+
18991904
return status;
19001905
}
19011906

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)