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

[PATCH 2/2] built-in stash: handle :(glob) pathspecs again

From
Johannes Schindelin via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 7, 2019, 15:29 UTC
Message-ID
<7b5cca61dea4f01f9bcdcb6d5d2a913d58a341d3.1551972571.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.159.git.gitgitgadget@gmail.com>
From: Johannes Schindelin <johannes.schindelin@gmx.de>

When passing a list of pathspecs to, say, `git add`, we need to be careful to use the original form, not the parsed form of the pathspecs.

This makes a difference e.g. when calling
	git stash -- ':(glob)**/*.txt'

where the original form includes the `:(glob)` prefix while the parsed form does not.

However, in the built-in `git stash`, we passed the parsed (i.e. incorrect) form, and `git add` would fail with the error message:

	fatal: pathspec '**/*.txt' did not match any files

at the stage where `git stash` drops the changes from the worktree, even if `refs/stash` has been actually updated successfully.

This fixes https://github.com/git-for-windows/git/issues/2037
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 builtin/stash.c                    | 5 +++--
 t/t3905-stash-include-untracked.sh | 6 ++++++
 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/builtin/stash.c b/builtin/stash.c
index 1bfa24030c..2f29d037c8 100644
--- a/builtin/stash.c
+++ b/builtin/stash.c
@@ -830,7 +830,7 @@ static void add_pathspecs(struct argv_array *args,
 	int i;
 
 	for (i = 0; i < ps.nr; i++)
-		argv_array_push(args, ps.items[i].match);
+		argv_array_push(args, ps.items[i].original);
 }
 
 /*
@@ -1466,7 +1466,8 @@ static int push_stash(int argc, const char **argv, const char *prefix)
 				     git_stash_push_usage,
 				     0);
 
-	parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv);
+	parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL | PATHSPEC_PREFIX_ORIGIN,
+		       prefix, argv);
 	return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode,
 			     include_untracked);
 }
diff --git a/t/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index cc1c8a7bb2..29ca76f2fb 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -283,4 +283,10 @@ test_expect_success 'stash -u -- <non-existant> shows no changes when there are
 	test_i18ncmp expect actual
 '
 
+test_expect_success 'stash -u with globs' '
+	>untracked.txt &&
+	git stash -u -- ":(glob)**/*.txt" &&
+	test_path_is_missing untracked.txt
+'
+
 test_done
-- 
gitgitgadget
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 13 in “stash: handle pathspec magic again”
  1. 0/2 stash: handle pathspec magic againJohannes Schindelin via GitGitGadget, Mar 7, 2019
  2. 1/2 legacy stash: fix "rudimentary backport of -q"Johannes Schindelin via GitGitGadget, Mar 7, 2019
  3. Junio C HamanoMar 11, 2019
  4. 2/2 built-in stash: handle :(glob) pathspecs againJohannes Schindelin via GitGitGadget, Mar 7, 2019
  5. Junio C HamanoMar 11, 2019
  6. Johannes SchindelinMar 11, 2019
  7. Thomas GummererMar 11, 2019
  8. Junio C HamanoMar 8, 2019
  9. Johannes SchindelinMar 8, 2019
  10. Junio C HamanoMar 10, 2019
  11. Johannes SchindelinMar 11, 2019
  12. Junio C HamanoMar 18, 2019
  13. Junio C HamanoMar 18, 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.