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

[PATCH v4 3/3] stash push -u: don't create empty stash

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2018, 22:37 UTC
Message-ID
<20180316223715.108044-4-gitster@pobox.com>
In-Reply-To
<20180316223715.108044-1-gitster@pobox.com>
From: Thomas Gummerer <t.gummerer@gmail.com>

When introducing the stash push feature, and thus allowing users to pass in a pathspec to limit the files that would get stashed in df6bba0937 ("stash: teach 'push' (and 'create_stash') to honor pathspec", 2017-02-28), this developer missed one place where the pathspec should be passed in.

Namely in the call to the 'untracked_files()' function in the 'no_changes()' function. This resulted in 'git stash push -u -- <non-existant>' creating an empty stash when there are untracked files in the repository other that don't match the pathspec.

As 'git stash' never creates empty stashes, this behaviour is wrong and confusing for users. Instead it should just show a message "No local changes to save", and not create a stash.

Luckily the 'untracked_files()' function already correctly respects pathspecs that are passed to it, so the fix is simply to pass the pathspec along to the function.

Reported-by: Marc Strapetz <marc.strapetz@syntevo.com>
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 git-stash.sh     | 2 +-
 t/t3903-stash.sh | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)
diff --git a/git-stash.sh b/git-stash.sh
index fa61151548..1652f64b5c 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -39,7 +39,7 @@ fi
 no_changes () {
 	git diff-index --quiet --cached HEAD --ignore-submodules -- "$@" &&
 	git diff-files --quiet --ignore-submodules -- "$@" &&
-	(test -z "$untracked" || test -z "$(untracked_files)")
+	(test -z "$untracked" || test -z "$(untracked_files "$@")")
 }
 
 untracked_files () {
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index f5b102a958..7e0b1c248c 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1019,4 +1019,10 @@ test_expect_success 'stash -u -- <untracked> leaves rest of working tree in plac
 	test_path_is_file tracked
 '
 
+test_expect_success 'stash -u -- <non-existant> shows no changes when there are none' '
+	git stash push -u -- non-existant >actual &&
+	echo "No local changes to save" >expect &&
+	test_i18ncmp expect actual
+'
+
 test_done
-- 
2.17.0-rc0
Previous: Junio C HamanoNext: Thomas Gummerer
Message 20 of 33 in “git stash push -u always warns "pathspec '...' did not match any files"”
  1. Marc StrapetzMar 3, 2018
  2. Thomas GummererMar 3, 2018
  3. Marc StrapetzMar 4, 2018
  4. Junio C HamanoMar 9, 2018
  5. Marc StrapetzMar 10, 2018
  6. Thomas GummererMar 10, 2018
  7. 1/2 stash push: avoid printing errorsThomas Gummerer, Mar 14, 2018
  8. 2/2 stash push -u: don't create empty stashThomas Gummerer, Mar 14, 2018
  9. Junio C HamanoMar 15, 2018
  10. Thomas GummererMar 16, 2018
  11. Marc StrapetzMar 15, 2018
  12. Thomas GummererMar 16, 2018
  13. 0/2 stash push -u -- <pathspec> fixesThomas Gummerer, Mar 16, 2018
  14. 2/2 stash push -u: don't create empty stashThomas Gummerer, Mar 16, 2018
  15. 1/2 stash push: avoid printing errorsThomas Gummerer, Mar 16, 2018
  16. Junio C HamanoMar 16, 2018
  17. 0/3 stash push -u -- <pathspec> fixesJunio C Hamano, Mar 16, 2018
  18. 2/3 stash push: avoid printing errorsJunio C Hamano, Mar 16, 2018
  19. 1/3 stash: fix nonsense pipelineJunio C Hamano, Mar 16, 2018
  20. 3/3 stash push -u: don't create empty stashJunio C Hamano, Mar 16, 2018
  21. Thomas GummererMar 17, 2018
  22. 0/3 stash push -u -- <pathspec> fixesThomas Gummerer, Mar 19, 2018
  23. 1/3 stash: fix nonsense pipelineThomas Gummerer, Mar 19, 2018
  24. 2/3 stash push: avoid printing errorsThomas Gummerer, Mar 19, 2018
  25. Junio C HamanoMar 20, 2018
  26. Thomas GummererMar 21, 2018
  27. stash: drop superfluos pathspec parameter (was: Re: [PATCH v5 2/3] stash push: avoid printing errors)Thomas Gummerer, Mar 21, 2018
  28. Junio C HamanoMar 21, 2018
  29. Junio C HamanoMar 21, 2018
  30. 3/3 stash push -u: don't create empty stashThomas Gummerer, Mar 19, 2018
  31. Marc StrapetzMar 20, 2018
  32. Marc StrapetzMar 19, 2018
  33. Thomas GummererMar 19, 2018

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.