mirror of
https://github.com/git-for-windows/git.git
synced 2026-03-17 04:23:29 -05:00
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 Perl script. So let's introduce support for an optional `<mode>` argument in `git add --patch[=<mode>]`, and use that in the scripted version of `git stash -p`, so that the built-in interactive add can do its job if configured. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
@@ -26,7 +26,8 @@ static const char * const builtin_add_usage[] = {
|
||||
N_("git add [<options>] [--] <pathspec>..."),
|
||||
NULL
|
||||
};
|
||||
static int patch_interactive, add_interactive, edit_interactive;
|
||||
static const char *patch_interactive;
|
||||
static int add_interactive, edit_interactive;
|
||||
static int take_worktree_changes;
|
||||
static int add_renormalize;
|
||||
|
||||
@@ -228,9 +229,11 @@ int run_add_interactive(const char *revision, const char *patch_mode,
|
||||
return status;
|
||||
}
|
||||
|
||||
int interactive_add(int argc, const char **argv, const char *prefix, int patch)
|
||||
int interactive_add(int argc, const char **argv, const char *prefix,
|
||||
const char *patch_mode)
|
||||
{
|
||||
struct pathspec pathspec;
|
||||
char buffer[64];
|
||||
|
||||
parse_pathspec(&pathspec, 0,
|
||||
PATHSPEC_PREFER_FULL |
|
||||
@@ -238,9 +241,13 @@ int interactive_add(int argc, const char **argv, const char *prefix, int patch)
|
||||
PATHSPEC_PREFIX_ORIGIN,
|
||||
prefix, argv);
|
||||
|
||||
return run_add_interactive(NULL,
|
||||
patch ? "--patch" : NULL,
|
||||
&pathspec);
|
||||
if (patch_mode) {
|
||||
xsnprintf(buffer, sizeof(buffer), "--patch%s%s",
|
||||
*patch_mode ? "=" : "", patch_mode);
|
||||
patch_mode = buffer;
|
||||
}
|
||||
|
||||
return run_add_interactive(NULL, patch_mode, &pathspec);
|
||||
}
|
||||
|
||||
static int edit_patch(int argc, const char **argv, const char *prefix)
|
||||
@@ -318,7 +325,9 @@ static struct option builtin_add_options[] = {
|
||||
OPT__VERBOSE(&verbose, N_("be verbose")),
|
||||
OPT_GROUP(""),
|
||||
OPT_BOOL('i', "interactive", &add_interactive, N_("interactive picking")),
|
||||
OPT_BOOL('p', "patch", &patch_interactive, N_("select hunks interactively")),
|
||||
{ OPTION_STRING, 'p', "patch", &patch_interactive, N_("patch-mode"),
|
||||
N_("select hunks interactively"), PARSE_OPT_OPTARG, NULL,
|
||||
(intptr_t) "" },
|
||||
OPT_BOOL('e', "edit", &edit_interactive, N_("edit current diff and apply")),
|
||||
OPT__FORCE(&ignored_too, N_("allow adding otherwise ignored files"), 0),
|
||||
OPT_BOOL('u', "update", &take_worktree_changes, N_("update tracked files")),
|
||||
|
||||
@@ -358,7 +358,8 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix
|
||||
old_index_env = xstrdup_or_null(getenv(INDEX_ENVIRONMENT));
|
||||
setenv(INDEX_ENVIRONMENT, get_lock_file_path(&index_lock), 1);
|
||||
|
||||
if (interactive_add(argc, argv, prefix, patch_interactive) != 0)
|
||||
if (interactive_add(argc, argv, prefix,
|
||||
patch_interactive ? "" : NULL) != 0)
|
||||
die(_("interactive add failed"));
|
||||
|
||||
if (old_index_env && *old_index_env)
|
||||
|
||||
3
commit.h
3
commit.h
@@ -295,7 +295,8 @@ int delayed_reachability_test(struct shallow_info *si, int c);
|
||||
void prune_shallow(unsigned options);
|
||||
extern struct trace_key trace_shallow;
|
||||
|
||||
int interactive_add(int argc, const char **argv, const char *prefix, int patch);
|
||||
int interactive_add(int argc, const char **argv, const char *prefix,
|
||||
const char *patch_mode);
|
||||
int run_add_interactive(const char *revision, const char *patch_mode,
|
||||
const struct pathspec *pathspec);
|
||||
|
||||
|
||||
@@ -206,7 +206,7 @@ create_stash () {
|
||||
|
||||
# find out what the user wants
|
||||
GIT_INDEX_FILE="$TMP-index" \
|
||||
git add--interactive --patch=stash -- "$@" &&
|
||||
git add --patch=stash -- "$@" &&
|
||||
|
||||
# state of the working tree
|
||||
w_tree=$(GIT_INDEX_FILE="$TMP-index" git write-tree) ||
|
||||
|
||||
Reference in New Issue
Block a user