Skip to content

Commit

Permalink
Merge pull request #36 Avoid sane_execvp in git rebase and `git s…
Browse files Browse the repository at this point in the history
…tash`

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
derrickstolee authored and dscho committed Mar 29, 2019
2 parents c99f315 + 23af81f commit 44727d0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
18 changes: 11 additions & 7 deletions builtin/rebase.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,13 +1142,17 @@ int cmd_rebase(int argc, const char **argv, const char *prefix)
*/

if (!use_builtin_rebase()) {
const char *path = mkpath("%s/git-legacy-rebase",
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-rebase",
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);
}

if (argc == 2 && !strcmp(argv[1], "-h"))
Expand Down
18 changes: 11 additions & 7 deletions builtin/stash.c
Original file line number Diff line number Diff line change
Expand Up @@ -1555,13 +1555,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 44727d0

Please sign in to comment.