legacy stash -p: respect the add.interactive.usebuiltin setting
As `git add` traditionally did not expose the `--patch=<mode>` 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 <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
Dec 21, 2019 at 21:57 UTC
90a6bb98d11a664f729dbb86c90d9c7a38ea825a
2 files changed
+15
-1
builtin/add.c
+14
@@ -29,6 +29,7 @@ static const char * const builtin_add_usage[] = {
29
static int patch_interactive, add_interactive, edit_interactive;
30
static int take_worktree_changes;
31
static int add_renormalize;
32
+static int legacy_stash_p; /* support for the scripted `git stash` */
33
34
struct update_callback_data {
35
int flags;
@@ -335,6 +336,8 @@ static struct option builtin_add_options[] = {
336
N_("override the executable bit of the listed files")),
337
OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
338
N_("warn when adding an embedded repository")),
339
+ OPT_HIDDEN_BOOL(0, "legacy-stash-p", &legacy_stash_p,
340
+ N_("backend for `git stash -p`")),
341
OPT_END(),
342
};
343
@@ -431,6 +434,17 @@ int cmd_add(int argc, const char **argv, const char *prefix)
434
add_interactive = 1;
435
if (add_interactive)
436
exit(interactive_add(argc - 1, argv + 1, prefix, patch_interactive));
437
+ if (legacy_stash_p) {
438
+ struct pathspec pathspec;
439
+
440
+ parse_pathspec(&pathspec, 0,
441
+ PATHSPEC_PREFER_FULL |
442
+ PATHSPEC_SYMLINK_LEADING_PATH |
443
+ PATHSPEC_PREFIX_ORIGIN,
444
+ prefix, argv);
445
+
446
+ return run_add_interactive(NULL, "--patch=stash", &pathspec);
447
+ }
448
449
if (edit_interactive)
450
return(edit_patch(argc, argv, prefix));
git-legacy-stash.sh
+1
-1
@@ -206,7 +206,7 @@ create_stash () {
206
207
# find out what the user wants
208
GIT_INDEX_FILE="$TMP-index" \
209
- git add--interactive --patch=stash -- "$@" &&
209
+ git add --legacy-stash-p -- "$@" &&
210
211
# state of the working tree
212
w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) ||