Skip to content

Commit c7fb556

Browse files
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 b7e53c2 + baa8cd0 commit c7fb556

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
@@ -1068,13 +1068,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
10681068
*/
10691069

10701070
if (!use_builtin_rebase()) {
1071-
const char *path = mkpath("%s/git-legacy-rebase",
1072-
git_exec_path());
1073-
1074-
if (sane_execvp(path, (char **)argv) < 0)
1075-
die_errno(_("could not exec %s"), path);
1076-
else
1077-
BUG("sane_execvp() returned???");
1071+
struct argv_array args = ARGV_ARRAY_INIT;
1072+
int code;
1073+
1074+
argv_array_push(&args, mkpath("%s/git-legacy-rebase",
1075+
git_exec_path()));
1076+
argv_array_pushv(&args, argv + 1);
1077+
code = run_command_v_opt(args.argv, 0);
1078+
if (code < 0)
1079+
die_errno(_("could not exec %s"), args.argv[0]);
1080+
argv_array_clear(&args);
1081+
exit(code);
10781082
}
10791083

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

builtin/stash.c

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

15111511
if (!use_builtin_stash()) {
1512-
const char *path = mkpath("%s/git-legacy-stash",
1513-
git_exec_path());
1514-
1515-
if (sane_execvp(path, (char **)argv) < 0)
1516-
die_errno(_("could not exec %s"), path);
1517-
else
1518-
BUG("sane_execvp() returned???");
1512+
struct argv_array args = ARGV_ARRAY_INIT;
1513+
int code;
1514+
1515+
argv_array_push(&args, mkpath("%s/git-legacy-stash",
1516+
git_exec_path()));
1517+
argv_array_pushv(&args, argv + 1);
1518+
code = run_command_v_opt(args.argv, 0);
1519+
if (code < 0)
1520+
die_errno(_("could not exec %s"), args.argv[0]);
1521+
argv_array_clear(&args);
1522+
exit(code);
15191523
}
15201524

15211525
prefix = setup_git_directory();

0 commit comments

Comments
 (0)