Re: git stash push -u always warns "pathspec '...' did not match any files"

2018-03-10 Thread Thomas Gummerer
On 03/10, Marc Strapetz wrote:
> On 09.03.2018 23:18, Junio C Hamano wrote:
> >Marc Strapetz  writes:
> >
> >>Thanks, I can confirm that the misleading warning message is fixed.
> >>
> >>What I've noticed now is that when using -u option, Git won't warn if
> >>the pathspec is actually not matching a file. Also, an empty stash may
> >>be created.
> >
> >S..., does it mean that the patch Thomas posted and you
> >confirmed trades one issue with another issue with a similar
> >graveness?

I've been meaning to follow up on this, but haven't found the time to
do so yet, sorry.

> From my understanding these are two separate problems for which the new one
> was somewhat hidden by the one Thomas has fixed: Thomas has fixed
> post-processing code after the stash has already been saved away. The
> problem I'm referring to is a missing check for invalid paths before the
> stash is saved away.

Yeah, just to demonstrate what the new problem Marc describes is,
currently 'git stash push -u ' would produce the following
output, and create a new stash:

$ git stash push -u unknown
Saved working directory and index state WIP on master: 7e31236f65 Sixth 
batch for 2.17
fatal: pathspec 'unknown' did not match any files
error: unrecognized input
$

With the patch I posted it would just print 

$ git stash push -u unknown
Saved working directory and index state WIP on master: 7e31236f65 Sixth 
batch for 2.17
$

and produce a new stash as before.  Both of those end up confusing to
the user, dunno which one is better.  What really should happen is

$ git stash push -u unknown
No local changes to save
$

and not creating a stash.  So these were many words to basically say
that I think my patch is still the right thing to do, but it may or
may not confuse the user more if they are hitting the other bug Marc
noted.  Either way I'll try to address this as soon as I can get some
time to look at it.

> -Marc


Re: git stash push -u always warns "pathspec '...' did not match any files"

2018-03-10 Thread Marc Strapetz

On 09.03.2018 23:18, Junio C Hamano wrote:

Marc Strapetz  writes:


Thanks, I can confirm that the misleading warning message is fixed.

What I've noticed now is that when using -u option, Git won't warn if
the pathspec is actually not matching a file. Also, an empty stash may
be created.


S..., does it mean that the patch Thomas posted and you
confirmed trades one issue with another issue with a similar
graveness?


From my understanding these are two separate problems for which the new 
one was somewhat hidden by the one Thomas has fixed: Thomas has fixed 
post-processing code after the stash has already been saved away. The 
problem I'm referring to is a missing check for invalid paths before the 
stash is saved away.


-Marc


Re: git stash push -u always warns "pathspec '...' did not match any files"

2018-03-09 Thread Junio C Hamano
Marc Strapetz  writes:

> Thanks, I can confirm that the misleading warning message is fixed.
>
> What I've noticed now is that when using -u option, Git won't warn if
> the pathspec is actually not matching a file. Also, an empty stash may
> be created.

S..., does it mean that the patch Thomas posted and you
confirmed trades one issue with another issue with a similar
graveness?  Is this something we want to "fix" without adding
another breakage?



Re: git stash push -u always warns "pathspec '...' did not match any files"

2018-03-04 Thread Marc Strapetz

On 03.03.2018 16:46, Thomas Gummerer wrote:

On 03/03, Marc Strapetz wrote:

Reproducible in a test repository with following steps:

$ touch untracked
$ git stash push -u -- untracked
Saved working directory and index state WIP on master: 0096475 init
fatal: pathspec 'untracked' did not match any files
error: unrecognized input

The file is stashed correctly, though.

Tested with Git 2.16.2 on Linux and Windows.


Thanks for the bug report and the reproduction recipe.  The following
patch should fix it:


Thanks, I can confirm that the misleading warning message is fixed.

What I've noticed now is that when using -u option, Git won't warn if 
the pathspec is actually not matching a file. Also, an empty stash may 
be created. For example:


$ git stash push -u -- nonexisting
Saved working directory and index state WIP on master: 171081d initial 
import


I would probably expect to see an error message as for:

$ git stash push -- nonexisting
error: pathspec 'nonexisting' did not match any file(s) known to git.
Did you forget to 'git add'?

That said, this is no problem for us, because I know that the paths I'm 
providing to "git stash push" do exist. I just wanted to point out.


-Marc



Re: git stash push -u always warns "pathspec '...' did not match any files"

2018-03-03 Thread Thomas Gummerer
On 03/03, Marc Strapetz wrote:
> Reproducible in a test repository with following steps:
> 
> $ touch untracked
> $ git stash push -u -- untracked
> Saved working directory and index state WIP on master: 0096475 init
> fatal: pathspec 'untracked' did not match any files
> error: unrecognized input
> 
> The file is stashed correctly, though.
> 
> Tested with Git 2.16.2 on Linux and Windows.

Thanks for the bug report and the reproduction recipe.  The following
patch should fix it:

--- >8 ---
Subject: [PATCH] stash push: avoid printing errors

Currently 'git stash push -u -- ' prints the following errors
if  only matches untracked files:

fatal: pathspec 'untracked' did not match any files
error: unrecognized input

This is because we first clean up the untracked files using 'git clean
', and then use a command chain involving 'git add -u
' and 'git apply' to clear the changes to files that are in
the index and were stashed.

As the  only includes untracked files that were already
removed by 'git clean', the 'git add' call will barf, and so will 'git
apply', as there are no changes that need to be applied.

Fix this by making sure to only call this command chain if there are
still files that match  after the call to 'git clean'.

Reported-by: Marc Strapetz 
Signed-off-by: Thomas Gummerer 
---
 git-stash.sh | 2 +-
 t/t3903-stash.sh | 7 +++
 2 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/git-stash.sh b/git-stash.sh
index fc8f8ae640..058ad0bed8 100755
--- a/git-stash.sh
+++ b/git-stash.sh
@@ -320,7 +320,7 @@ push_stash () {
git clean --force --quiet -d $CLEAN_X_OPTION -- "$@"
fi
 
-   if test $# != 0
+   if test $# != 0 && git ls-files --error-unmatch -- "$@" 
>/dev/null 2>/dev/null
then
git add -u -- "$@" |
git checkout-index -z --force --stdin
diff --git a/t/t3903-stash.sh b/t/t3903-stash.sh
index aefde7b172..506004aece 100755
--- a/t/t3903-stash.sh
+++ b/t/t3903-stash.sh
@@ -1096,4 +1096,11 @@ test_expect_success 'stash --  works with binary 
files' '
test_path_is_file subdir/untracked
 '
 
+test_expect_success 'stash --  doesnt print error' '
+   >untracked &&
+   git stash push -u -- untracked 2>actual&&
+   test_path_is_missing untracked &&
+   test_line_count = 0 actual
+'
+
 test_done
-- 
2.16.2.395.g2e18187dfd



git stash push -u always warns "pathspec '...' did not match any files"

2018-03-03 Thread Marc Strapetz

Reproducible in a test repository with following steps:

$ touch untracked
$ git stash push -u -- untracked
Saved working directory and index state WIP on master: 0096475 init
fatal: pathspec 'untracked' did not match any files
error: unrecognized input

The file is stashed correctly, though.

Tested with Git 2.16.2 on Linux and Windows.

-Marc