Skip to content

Commit 9b6dfd4

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 cfce4ec + 9636624 commit 9b6dfd4

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

builtin/stash.c

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

15661566
if (!use_builtin_stash()) {
1567-
const char *path = mkpath("%s/git-legacy-stash",
1568-
git_exec_path());
1569-
1570-
if (sane_execvp(path, (char **)argv) < 0)
1571-
die_errno(_("could not exec %s"), path);
1572-
else
1573-
BUG("sane_execvp() returned???");
1567+
struct argv_array args = ARGV_ARRAY_INIT;
1568+
int code;
1569+
1570+
argv_array_push(&args, mkpath("%s/git-legacy-stash",
1571+
git_exec_path()));
1572+
argv_array_pushv(&args, argv + 1);
1573+
code = run_command_v_opt(args.argv, 0);
1574+
if (code < 0)
1575+
die_errno(_("could not exec %s"), args.argv[0]);
1576+
argv_array_clear(&args);
1577+
exit(code);
15741578
}
15751579

15761580
prefix = setup_git_directory();

0 commit comments

Comments
 (0)