Skip to content

Commit

Permalink
rebase/stash: make post-command hook work again
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
dscho authored and derrickstolee committed Mar 23, 2020
1 parent 58f09e4 commit e299835
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions builtin/stash.c
Expand Up @@ -1593,13 +1593,17 @@ int cmd_stash(int argc, const char **argv, const char *prefix)
};

if (!use_builtin_stash()) {
const char *path = mkpath("%s/git-legacy-stash",
git_exec_path());

if (sane_execvp(path, (char **)argv) < 0)
die_errno(_("could not exec %s"), path);
else
BUG("sane_execvp() returned???");
struct argv_array args = ARGV_ARRAY_INIT;
int code;

argv_array_push(&args, mkpath("%s/git-legacy-stash",
git_exec_path()));
argv_array_pushv(&args, argv + 1);
code = run_command_v_opt(args.argv, 0);
if (code < 0)
die_errno(_("could not exec %s"), args.argv[0]);
argv_array_clear(&args);
exit(code);
}

prefix = setup_git_directory();
Expand Down

0 comments on commit e299835

Please sign in to comment.