Skip to content

Commit cddc2cb

Browse files
committed
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 <[email protected]>
1 parent 846cf16 commit cddc2cb

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

builtin/add.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ static const char * const builtin_add_usage[] = {
2929
static int patch_interactive, add_interactive, edit_interactive;
3030
static int take_worktree_changes;
3131
static int add_renormalize;
32+
static int legacy_stash_p; /* support for the scripted `git stash` */
3233

3334
struct update_callback_data {
3435
int flags;
@@ -335,6 +336,8 @@ static struct option builtin_add_options[] = {
335336
N_("override the executable bit of the listed files")),
336337
OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
337338
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`")),
338341
OPT_END(),
339342
};
340343

@@ -431,6 +434,17 @@ int cmd_add(int argc, const char **argv, const char *prefix)
431434
add_interactive = 1;
432435
if (add_interactive)
433436
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+
}
434448

435449
if (edit_interactive)
436450
return(edit_patch(argc, argv, prefix));

git-legacy-stash.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ create_stash () {
206206

207207
# find out what the user wants
208208
GIT_INDEX_FILE="$TMP-index" \
209-
git add--interactive --patch=stash -- "$@" &&
209+
git add --legacy-stash-p -- "$@" &&
210210

211211
# state of the working tree
212212
w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) ||

0 commit comments

Comments
 (0)