From 7ab70d4d2dc1c4e969e6a29bc644cd6514c2ffa4 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sun, 24 Mar 2019 19:55:08 +0100 Subject: [PATCH] legacy stash -p: respect the add.interactive.usebuiltin setting As `git add` traditionally did not expose the `--patch=` modes via command-line options, the scripted version of `git stash` had to call `git add--interactive` directly. But this prevents the built-in `add -p` from kicking in, as `add--interactive` is the scripted version (which does not have a "fall-back" to the built-in version). So let's introduce support for internal switch for `git add` that the scripted `git stash` can use to call the appropriate backend (scripted or built-in, depending on `add.interactive.useBuiltin`). Signed-off-by: Johannes Schindelin --- builtin/add.c | 15 +++++++++++++++ git-legacy-stash.sh | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/builtin/add.c b/builtin/add.c index 3cc341d961..27cd8d0881 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -31,6 +31,7 @@ static int take_worktree_changes; static int add_renormalize; static int pathspec_file_nul; static const char *pathspec_from_file; +static int legacy_stash_p; /* support for the scripted `git stash` */ struct update_callback_data { int flags; @@ -339,6 +340,8 @@ static struct option builtin_add_options[] = { N_("warn when adding an embedded repository")), OPT_PATHSPEC_FROM_FILE(&pathspec_from_file), OPT_PATHSPEC_FILE_NUL(&pathspec_file_nul), + OPT_HIDDEN_BOOL(0, "legacy-stash-p", &legacy_stash_p, + N_("backend for `git stash -p`")), OPT_END(), }; @@ -439,6 +442,18 @@ int cmd_add(int argc, const char **argv, const char *prefix) exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive)); } + if (legacy_stash_p) { + struct pathspec pathspec; + + parse_pathspec(&pathspec, 0, + PATHSPEC_PREFER_FULL | + PATHSPEC_SYMLINK_LEADING_PATH | + PATHSPEC_PREFIX_ORIGIN, + prefix, argv); + + return run_add_interactive(NULL, "--patch=stash", &pathspec); + } + if (edit_interactive) { if (pathspec_from_file) die(_("--pathspec-from-file is incompatible with --edit")); diff --git a/git-legacy-stash.sh b/git-legacy-stash.sh index 53fa574301..4d4ebb4f2b 100755 --- a/git-legacy-stash.sh +++ b/git-legacy-stash.sh @@ -207,7 +207,7 @@ create_stash () { # find out what the user wants GIT_INDEX_FILE="$TMP-index" \ - git add--interactive --patch=stash -- "$@" && + git add --legacy-stash-p -- "$@" && # state of the working tree w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) ||