sequencer: pass absolute GIT_WORK_TREE to exec commands

The sequencer currently passes GIT_DIR, but not GIT_WORK_TREE, to exec commands. In that configuration, we assume that whatever directory we're in is the top level of the work tree, and git rev-parse --show-toplevel responds accordingly. However, when we're in a subdirectory, that isn't correct: we respond with the subdirectory as the top level, resulting in unexpected behavior. Ensure that we pass GIT_WORK_TREE as well as GIT_DIR so that git operations within subdirectories work correctly. Note that we are guaranteed to have a work tree in this case: the relevant sequencer functions are called only from revert, cherry-pick, and rebase--helper; all of these commands require a working tree. Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Jul 14, 2018 at 18:38 UTC ab5e67d7513ac6efb4c0ee9787aeaa41604c0566
2 files changed +11
sequencer.c
+2
@@ -1883,6 +1883,8 @@ static int do_exec(const char *command_line)
1883 fprintf(stderr, "Executing: %s\n", command_line);
1884 child_argv[0] = command_line;
1885 argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
1886 + argv_array_pushf(&child_env, "GIT_WORK_TREE=%s",
1887 + absolute_path(get_git_work_tree()));
1888 status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
1889 child_env.argv);
1890
t/t3404-rebase-interactive.sh
+9
@@ -119,6 +119,15 @@ test_expect_success 'rebase -i with exec allows git commands in subdirs' '
119 )
120 '
121
122 +test_expect_success 'rebase -i sets work tree properly' '
123 + test_when_finished "rm -rf subdir" &&
124 + test_when_finished "test_might_fail git rebase --abort" &&
125 + mkdir subdir &&
126 + git rebase -x "(cd subdir && git rev-parse --show-toplevel)" HEAD^ \
127 + >actual &&
128 + ! grep "/subdir$" actual
129 +'
130 +
131 test_expect_success 'rebase -i with the exec command checks tree cleanness' '
132 git checkout master &&
133 set_fake_editor &&