git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/7] legacy stash -p: respect the add.interactive.usebuiltin setting

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 17, 2019, 10:41 UTC
Message-ID
<cddc2cb9de645ecc49a74e94a73bcdf843035024.1576579264.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.174.git.1576579264.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

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>
---
 builtin/add.c       | 14 ++++++++++++++
 git-legacy-stash.sh |  2 +-
 2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/builtin/add.c b/builtin/add.c
index 583d8aab0d..f238e8b623 100644
--- a/builtin/add.c
+++ b/builtin/add.c
@@ -29,6 +29,7 @@ static const char * const builtin_add_usage[] = {
 static int patch_interactive, add_interactive, edit_interactive;
 static int take_worktree_changes;
 static int add_renormalize;
+static int legacy_stash_p; /* support for the scripted `git stash` */
 
 struct update_callback_data {
 	int flags;
@@ -335,6 +336,8 @@ static struct option builtin_add_options[] = {
 		   N_("override the executable bit of the listed files")),
 	OPT_HIDDEN_BOOL(0, "warn-embedded-repo", &warn_on_embedded_repo,
 			N_("warn when adding an embedded repository")),
+	OPT_HIDDEN_BOOL(0, "legacy-stash-p", &legacy_stash_p,
+			N_("backend for `git stash -p`")),
 	OPT_END(),
 };
 
@@ -431,6 +434,17 @@ int cmd_add(int argc, const char **argv, const char *prefix)
 		add_interactive = 1;
 	if (add_interactive)
 		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)
 		return(edit_patch(argc, argv, prefix));
diff --git a/git-legacy-stash.sh b/git-legacy-stash.sh
index 07ad4a5459..ed039dfcbb 100755
--- a/git-legacy-stash.sh
+++ b/git-legacy-stash.sh
@@ -206,7 +206,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) ||
-- 
gitgitgadget
Previous: Johannes Schindelin via GitGitGadgetNext: Johannes Schindelin via GitGitGadget
Message 2 of 23 in “stash/reset/checkout -p: optionally use the add --patch backend written in pure C”
  1. 0/7 stash/reset/checkout -p: optionally use the add --patch backend written in pure CJohannes Schindelin via GitGitGadget, Dec 17, 2019
  2. 3/7 legacy stash -p: respect the add.interactive.usebuiltin settingJohannes Schindelin via GitGitGadget, Dec 17, 2019
  3. 1/7 built-in add -p: prepare for patch modes other than "stage"Johannes Schindelin via GitGitGadget, Dec 17, 2019
  4. Junio C HamanoDec 17, 2019
  5. Johannes SchindelinDec 21, 2019
  6. 2/7 built-in add -p: implement the "stash" and "reset" patch modesJohannes Schindelin via GitGitGadget, Dec 17, 2019
  7. Junio C HamanoDec 17, 2019
  8. Johannes SchindelinDec 21, 2019
  9. 4/7 built-in stash: use the built-in `git add -p` if so configuredJohannes Schindelin via GitGitGadget, Dec 17, 2019
  10. Junio C HamanoDec 17, 2019
  11. Johannes SchindelinDec 21, 2019
  12. 5/7 built-in add -p: implement the "checkout" patch modesJohannes Schindelin via GitGitGadget, Dec 17, 2019
  13. 7/7 commit --interactive: make it work with the built-in `add -i`Johannes Schindelin via GitGitGadget, Dec 17, 2019
  14. 6/7 built-in add -p: implement the "worktree" patch modesJohannes Schindelin via GitGitGadget, Dec 17, 2019
  15. Junio C HamanoDec 17, 2019
  16. 0/7 stash/reset/checkout -p: optionally use the add --patch backend written in pure CJohannes Schindelin via GitGitGadget, Dec 21, 2019
  17. 1/7 built-in add -p: prepare for patch modes other than "stage"Johannes Schindelin via GitGitGadget, Dec 21, 2019
  18. 3/7 legacy stash -p: respect the add.interactive.usebuiltin settingJohannes Schindelin via GitGitGadget, Dec 21, 2019
  19. 2/7 built-in add -p: implement the "stash" and "reset" patch modesJohannes Schindelin via GitGitGadget, Dec 21, 2019
  20. 7/7 commit --interactive: make it work with the built-in `add -i`Johannes Schindelin via GitGitGadget, Dec 21, 2019
  21. 5/7 built-in add -p: implement the "checkout" patch modesJohannes Schindelin via GitGitGadget, Dec 21, 2019
  22. 4/7 built-in stash: use the built-in `git add -p` if so configuredJohannes Schindelin via GitGitGadget, Dec 21, 2019
  23. 6/7 built-in add -p: implement the "worktree" patch modesJohannes Schindelin via GitGitGadget, Dec 21, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.