stash push -u: don't create empty stash
authorThomas Gummerer <t.gummerer@gmail.com>
Mon, 19 Mar 2018 23:21:56 +0000 (23:21 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Mar 2018 16:08:34 +0000 (09:08 -0700)
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
t/t3905-stash-include-untracked.sh
index 5e06f96da592e87ecf590cdd8e8d5c1ba2ccaed0..4e55f278bd41abc009539e61d125475b4bdfdee6 100755 (executable)
@@ -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 () {
index 2f9045553eb3b864fa603fe52cfe26f9d975efae..3ea5b9bb3ff0a4e439b1fc6cd8f9df86386f4126 100755 (executable)
@@ -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