Skip to content

Commit 06b724f

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 a8feffd + fb1a595 commit 06b724f

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

11441144
if (!use_builtin_rebase()) {
1145-
const char *path = mkpath("%s/git-legacy-rebase",
1146-
git_exec_path());
1147-
1148-
if (sane_execvp(path, (char **)argv) < 0)
1149-
die_errno(_("could not exec %s"), path);
1150-
else
1151-
BUG("sane_execvp() returned???");
1145+
struct argv_array args = ARGV_ARRAY_INIT;
1146+
int code;
1147+
1148+
argv_array_push(&args, mkpath("%s/git-legacy-rebase",
1149+
git_exec_path()));
1150+
argv_array_pushv(&args, argv + 1);
1151+
code = run_command_v_opt(args.argv, 0);
1152+
if (code < 0)
1153+
die_errno(_("could not exec %s"), args.argv[0]);
1154+
argv_array_clear(&args);
1155+
exit(code);
11521156
}
11531157

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

builtin/stash.c

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

15571557
if (!use_builtin_stash()) {
1558-
const char *path = mkpath("%s/git-legacy-stash",
1559-
git_exec_path());
1560-
1561-
if (sane_execvp(path, (char **)argv) < 0)
1562-
die_errno(_("could not exec %s"), path);
1563-
else
1564-
BUG("sane_execvp() returned???");
1558+
struct argv_array args = ARGV_ARRAY_INIT;
1559+
int code;
1560+
1561+
argv_array_push(&args, mkpath("%s/git-legacy-stash",
1562+
git_exec_path()));
1563+
argv_array_pushv(&args, argv + 1);
1564+
code = run_command_v_opt(args.argv, 0);
1565+
if (code < 0)
1566+
die_errno(_("could not exec %s"), args.argv[0]);
1567+
argv_array_clear(&args);
1568+
exit(code);
15651569
}
15661570

15671571
prefix = setup_git_directory();

0 commit comments

Comments
 (0)