Skip to content

Commit 77eefa1

Browse files
derrickstoleedscho
authored andcommitted
Merge pull request #36 Avoid sane_execvp in git rebase and git stash
William Baker reported that the non-built-in rebase and stash fail to run the post-command hook (which is important for VFS for Git, though). The reason is that an `exec()` will replace the current process by the newly-exec'ed one (our Windows-specific emulation cannot do that, and does not even try, so this is only an issue on Linux/macOS). As a consequence, not even the atexit() handlers are run, including the one running the post-command hook. To work around that, let's spawn the legacy rebase/stash and exit with the reported exit code.
2 parents cf4c1ae + 7709e5e commit 77eefa1

File tree

2 files changed

+22
-14
lines changed

2 files changed

+22
-14
lines changed

builtin/rebase.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,13 +1114,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
11141114
*/
11151115

11161116
if (!use_builtin_rebase()) {
1117-
const char *path = mkpath("%s/git-legacy-rebase",
1118-
git_exec_path());
1119-
1120-
if (sane_execvp(path, (char **)argv) < 0)
1121-
die_errno(_("could not exec %s"), path);
1122-
else
1123-
BUG("sane_execvp() returned???");
1117+
struct argv_array args = ARGV_ARRAY_INIT;
1118+
int code;
1119+
1120+
argv_array_push(&args, mkpath("%s/git-legacy-rebase",
1121+
git_exec_path()));
1122+
argv_array_pushv(&args, argv + 1);
1123+
code = run_command_v_opt(args.argv, 0);
1124+
if (code < 0)
1125+
die_errno(_("could not exec %s"), args.argv[0]);
1126+
argv_array_clear(&args);
1127+
exit(code);
11241128
}
11251129

11261130
if (argc == 2 && !strcmp(argv[1], "-h"))

builtin/stash.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,13 +1550,17 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
15501550
};
15511551

15521552
if (!use_builtin_stash()) {
1553-
const char *path = mkpath("%s/git-legacy-stash",
1554-
git_exec_path());
1555-
1556-
if (sane_execvp(path, (char **)argv) < 0)
1557-
die_errno(_("could not exec %s"), path);
1558-
else
1559-
BUG("sane_execvp() returned???");
1553+
struct argv_array args = ARGV_ARRAY_INIT;
1554+
int code;
1555+
1556+
argv_array_push(&args, mkpath("%s/git-legacy-stash",
1557+
git_exec_path()));
1558+
argv_array_pushv(&args, argv + 1);
1559+
code = run_command_v_opt(args.argv, 0);
1560+
if (code < 0)
1561+
die_errno(_("could not exec %s"), args.argv[0]);
1562+
argv_array_clear(&args);
1563+
exit(code);
15601564
}
15611565

15621566
prefix = setup_git_directory();

0 commit comments

Comments
 (0)