Re: [PATCH v2 2/2] stash push -u: don't create empty stash

2018-03-16 Thread Thomas Gummerer
On 03/15, Junio C Hamano wrote:
> Thomas Gummerer  writes:
> 
> >  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 $@)")
> 
> Don't you need a pair of double-quotes around that $@?

Ah yes indeed.  Will fix, thanks!


Re: [PATCH v2 2/2] stash push -u: don't create empty stash

2018-03-15 Thread Junio C Hamano
Thomas Gummerer  writes:

>  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 $@)")

Don't you need a pair of double-quotes around that $@?


[PATCH v2 2/2] stash push -u: don't create empty stash

2018-03-14 Thread Thomas Gummerer
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 --
' 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 
Signed-off-by: Thomas Gummerer 
---
 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 058ad0bed8..7a4ec98f6b 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 fbfda4b243..5e7078c083 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1103,4 +1103,10 @@ test_expect_success 'stash -u --  doesnt 
print error' '
test_line_count = 0 actual
 '
 
+test_expect_success 'stash -u --  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.16.2.804.g6dcf76e11