Skip to content

Commit f522f1b

Browse files
derrickstoleedscho
authored andcommitted
Merge pull request git-for-windows#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 ae9c428 + dbdf264 commit f522f1b

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

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

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

builtin/stash.c

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

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

15221526
prefix = setup_git_directory();

0 commit comments

Comments
 (0)