Merge branch 'en/rebase-x-wo-git-dir-env'

"git rebase -x" by mistake started exporting the GIT_DIR and
GIT_WORK_TREE environment variables when the command was rewritten
in C, which has been corrected.

* en/rebase-x-wo-git-dir-env:
  sequencer: do not export GIT_DIR and GIT_WORK_TREE for 'exec'
This commit is contained in:
Junio C Hamano 2021-12-21 15:03:15 -08:00
Родитель 5a4069a1d8 434e0636db
Коммит 57f28f4094
2 изменённых файлов: 24 добавлений и 8 удалений

Просмотреть файл

@ -3497,17 +3497,12 @@ static int error_failed_squash(struct repository *r,
static int do_exec(struct repository *r, const char *command_line)
{
struct strvec child_env = STRVEC_INIT;
const char *child_argv[] = { NULL, NULL };
int dirty, status;
fprintf(stderr, _("Executing: %s\n"), command_line);
child_argv[0] = command_line;
strvec_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir()));
strvec_pushf(&child_env, "GIT_WORK_TREE=%s",
absolute_path(get_git_work_tree()));
status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL,
child_env.v);
status = run_command_v_opt(child_argv, RUN_USING_SHELL);
/* force re-reading of the cache */
if (discard_index(r->index) < 0 || repo_read_index(r) < 0)
@ -3537,8 +3532,6 @@ static int do_exec(struct repository *r, const char *command_line)
status = 1;
}
strvec_clear(&child_env);
return status;
}

23
t/t3409-rebase-environ.sh Executable file
Просмотреть файл

@ -0,0 +1,23 @@
#!/bin/sh
test_description='git rebase interactive environment'
. ./test-lib.sh
test_expect_success 'setup' '
test_commit one &&
test_commit two &&
test_commit three
'
test_expect_success 'rebase --exec does not muck with GIT_DIR' '
git rebase --exec "printf %s \$GIT_DIR >environ" HEAD~1 &&
test_must_be_empty environ
'
test_expect_success 'rebase --exec does not muck with GIT_WORK_TREE' '
git rebase --exec "printf %s \$GIT_WORK_TREE >environ" HEAD~1 &&
test_must_be_empty environ
'
test_done