All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gummerer <t.gummerer@gmail.com>
To: git@vger.kernel.org
Cc: Marc Strapetz <marc.strapetz@syntevo.com>,
	Junio C Hamano <gitster@pobox.com>,
	Thomas Gummerer <t.gummerer@gmail.com>
Subject: [PATCH v5 3/3] stash push -u: don't create empty stash
Date: Mon, 19 Mar 2018 23:21:56 +0000	[thread overview]
Message-ID: <20180319232156.30916-4-t.gummerer@gmail.com> (raw)
In-Reply-To: <20180319232156.30916-1-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>
---
 git-stash.sh                       | 2 +-
 t/t3905-stash-include-untracked.sh | 6 ++++++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/git-stash.sh b/git-stash.sh
index 5e06f96da5..4e55f278bd 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/t3905-stash-include-untracked.sh b/t/t3905-stash-include-untracked.sh
index 2f9045553e..3ea5b9bb3f 100755
--- a/t/t3905-stash-include-untracked.sh
+++ b/t/t3905-stash-include-untracked.sh
@@ -274,4 +274,10 @@ test_expect_success 'stash -u -- <ignored> leaves ignored file alone' '
 	test_path_is_file ignored.d/bar
 '
 
+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.15.1.33.g3165b24a68


  parent reply	other threads:[~2018-03-19 23:19 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-03  9:44 git stash push -u always warns "pathspec '...' did not match any files" Marc Strapetz
2018-03-03 15:46 ` Thomas Gummerer
2018-03-04 10:44   ` Marc Strapetz
2018-03-09 22:18     ` Junio C Hamano
2018-03-10  9:18       ` Marc Strapetz
2018-03-10 11:12         ` Thomas Gummerer
2018-03-14 21:46           ` [PATCH v2 1/2] stash push: avoid printing errors Thomas Gummerer
2018-03-14 21:46             ` [PATCH v2 2/2] stash push -u: don't create empty stash Thomas Gummerer
2018-03-15 20:09               ` Junio C Hamano
2018-03-16 20:10                 ` Thomas Gummerer
2018-03-15  8:51             ` [PATCH v2 1/2] stash push: avoid printing errors Marc Strapetz
2018-03-16 20:12               ` Thomas Gummerer
2018-03-16 20:43             ` [PATCH v3 0/2] stash push -u -- <pathspec> fixes Thomas Gummerer
2018-03-16 20:43               ` [PATCH v3 1/2] stash push: avoid printing errors Thomas Gummerer
2018-03-16 21:31                 ` Junio C Hamano
2018-03-16 20:43               ` [PATCH v3 2/2] stash push -u: don't create empty stash Thomas Gummerer
2018-03-16 22:37               ` [PATCH v4 0/3] stash push -u -- <pathspec> fixes Junio C Hamano
2018-03-16 22:37                 ` [PATCH v4 1/3] stash: fix nonsense pipeline Junio C Hamano
2018-03-16 22:37                 ` [PATCH v4 2/3] stash push: avoid printing errors Junio C Hamano
2018-03-16 22:37                 ` [PATCH v4 3/3] stash push -u: don't create empty stash Junio C Hamano
2018-03-17 11:36                 ` [PATCH v4 0/3] stash push -u -- <pathspec> fixes Thomas Gummerer
2018-03-19 23:21                 ` [PATCH v5 " Thomas Gummerer
2018-03-19 23:21                   ` [PATCH v5 1/3] stash: fix nonsense pipeline Thomas Gummerer
2018-03-19 23:21                   ` [PATCH v5 2/3] stash push: avoid printing errors Thomas Gummerer
2018-03-20 16:54                     ` Junio C Hamano
2018-03-21 21:36                       ` Thomas Gummerer
2018-03-21 21:53                         ` [PATCH] stash: drop superfluos pathspec parameter (was: Re: [PATCH v5 2/3] stash push: avoid printing errors) Thomas Gummerer
2018-03-21 22:07                           ` [PATCH] stash: drop superfluos pathspec parameter Junio C Hamano
2018-03-21 21:56                         ` [PATCH v5 2/3] stash push: avoid printing errors Junio C Hamano
2018-03-19 23:21                   ` Thomas Gummerer [this message]
2018-03-20 10:06                   ` [PATCH v5 0/3] stash push -u -- <pathspec> fixes Marc Strapetz
2018-03-19 15:44               ` [PATCH v3 0/2] " Marc Strapetz
2018-03-19 21:51                 ` Thomas Gummerer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180319232156.30916-4-t.gummerer@gmail.com \
    --to=t.gummerer@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=marc.strapetz@syntevo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.