git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] [kernel] completion: silence "fatal: Not a git repository" error
@ 2014-10-14 10:49 John Szakmeister
  2014-10-14 13:58 ` John Szakmeister
  2014-10-14 18:29 ` Junio C Hamano
  0 siblings, 2 replies; 5+ messages in thread
From: John Szakmeister @ 2014-10-14 10:49 UTC (permalink / raw)
  To: git; +Cc: John Szakmeister

It is possible that a user is trying to run a git command and fail to realize
that they are not in a git repository or working tree.  When trying to complete
an operation, __git_refs would fall to a degenerate case and attempt to use
"git for-each-ref", which would emit the error.

Let's fix this by shunting the error message coming from "git for-each-ref".

Signed-off-by: John Szakmeister <john@szakmeister.net>
---
 contrib/completion/git-completion.bash | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash
index 5ea5b82..31b4739 100644
--- a/contrib/completion/git-completion.bash
+++ b/contrib/completion/git-completion.bash
@@ -388,7 +388,8 @@ __git_refs ()
 		;;
 	*)
 		echo "HEAD"
-		git for-each-ref --format="%(refname:short)" -- "refs/remotes/$dir/" | sed -e "s#^$dir/##"
+		git for-each-ref --format="%(refname:short)" -- \
+			"refs/remotes/$dir/" 2>/dev/null | sed -e "s#^$dir/##"
 		;;
 	esac
 }
-- 
2.0.1

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] [kernel] completion: silence "fatal: Not a git repository" error
  2014-10-14 10:49 [PATCH] [kernel] completion: silence "fatal: Not a git repository" error John Szakmeister
@ 2014-10-14 13:58 ` John Szakmeister
  2014-10-14 18:29 ` Junio C Hamano
  1 sibling, 0 replies; 5+ messages in thread
From: John Szakmeister @ 2014-10-14 13:58 UTC (permalink / raw)
  To: git

On Tue, Oct 14, 2014 at 6:49 AM, John Szakmeister <john@szakmeister.net> wrote:
> It is possible that a user is trying to run a git command and fail to realize
> that they are not in a git repository or working tree.  When trying to complete
> an operation, __git_refs would fall to a degenerate case and attempt to use
> "git for-each-ref", which would emit the error.
>
> Let's fix this by shunting the error message coming from "git for-each-ref".
>
> Signed-off-by: John Szakmeister <john@szakmeister.net>
> ---

Sorry for the "[kernel]" in the subject.  I must have forgotten to
remove that off of my format-patch invocation.  If you need me to
resubmit without it, I can do that.

Thanks!

-John

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [kernel] completion: silence "fatal: Not a git repository" error
  2014-10-14 10:49 [PATCH] [kernel] completion: silence "fatal: Not a git repository" error John Szakmeister
  2014-10-14 13:58 ` John Szakmeister
@ 2014-10-14 18:29 ` Junio C Hamano
  2014-10-14 19:18   ` John Szakmeister
  1 sibling, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2014-10-14 18:29 UTC (permalink / raw)
  To: John Szakmeister; +Cc: git

John Szakmeister <john@szakmeister.net> writes:

> It is possible that a user is trying to run a git command and fail to realize
> that they are not in a git repository or working tree.  When trying to complete
> an operation, __git_refs would fall to a degenerate case and attempt to use
> "git for-each-ref", which would emit the error.
>
> Let's fix this by shunting the error message coming from "git for-each-ref".

Hmph, do you mean this one?

    $ cd /var/tmp ;# not a git repository
    $ git checkout <TAB>

->

    $ git checkout fatal: Not a git repository (or any of the parent directories): .git
    HEAD 

I agree it is ugly, but would it be an improvement for the end user,
who did not realize that she was not in a directory where "git checkout"
makes sense, not to tell her that she is not in a git repository in
some way?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [kernel] completion: silence "fatal: Not a git repository" error
  2014-10-14 18:29 ` Junio C Hamano
@ 2014-10-14 19:18   ` John Szakmeister
  2014-10-14 22:14     ` Junio C Hamano
  0 siblings, 1 reply; 5+ messages in thread
From: John Szakmeister @ 2014-10-14 19:18 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

On Tue, Oct 14, 2014 at 2:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
> John Szakmeister <john@szakmeister.net> writes:
>
>> It is possible that a user is trying to run a git command and fail to realize
>> that they are not in a git repository or working tree.  When trying to complete
>> an operation, __git_refs would fall to a degenerate case and attempt to use
>> "git for-each-ref", which would emit the error.
>>
>> Let's fix this by shunting the error message coming from "git for-each-ref".
>
> Hmph, do you mean this one?
>
>     $ cd /var/tmp ;# not a git repository
>     $ git checkout <TAB>
>
> ->
>
>     $ git checkout fatal: Not a git repository (or any of the parent directories): .git
>     HEAD
>
> I agree it is ugly, but would it be an improvement for the end user,
> who did not realize that she was not in a directory where "git checkout"
> makes sense, not to tell her that she is not in a git repository in
> some way?

I had thought about that too, but I think--for me--it comes down to two things:

1) We're not intentionally trying to inform the user anywhere else
that they are not in a git repo.  We simply fail to complete anything,
which I think is an established behavior.
2) It mingles with the stuff already on the command line, making it
confusing to know what you typed.  Then you end up ctrl-c'ing your way
out of it and starting over--which is the frustrating part.

For me, I thought it better to just be more well-behaved.  I've also
run across this issue when I legitimately wanted to do something--I
wish I could remember what it was--with a remote repo and didn't
happen to be in a git working tree.  It was frustrating to see this
error message then too, for the same reason as above.  I use tab
completion quite extensively, so spitting things like this out making
it difficult to move forward is a problem.

Would it be better to check that "$dir" is non-empty and then provide
the extra bits of information?  We could then avoid giving the user
anything in that case.

-John

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] [kernel] completion: silence "fatal: Not a git repository" error
  2014-10-14 19:18   ` John Szakmeister
@ 2014-10-14 22:14     ` Junio C Hamano
  0 siblings, 0 replies; 5+ messages in thread
From: Junio C Hamano @ 2014-10-14 22:14 UTC (permalink / raw)
  To: John Szakmeister; +Cc: git

John Szakmeister <john@szakmeister.net> writes:

> On Tue, Oct 14, 2014 at 2:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
> ...
>> Hmph, do you mean this one?
>>
>>     $ cd /var/tmp ;# not a git repository
>>     $ git checkout <TAB>
>>
>> ->
>>
>>     $ git checkout fatal: Not a git repository (or any of the parent directories): .git
>>     HEAD
>>
>> I agree it is ugly, but would it be an improvement for the end user,
>> who did not realize that she was not in a directory where "git checkout"
>> makes sense, not to tell her that she is not in a git repository in
>> some way?
>
> I had thought about that too, but I think--for me--it comes down to two things:
>
> 1) We're not intentionally trying to inform the user anywhere else
> that they are not in a git repo.  We simply fail to complete anything,
> which I think is an established behavior.
> 2) It mingles with the stuff already on the command line, making it
> confusing to know what you typed.  Then you end up ctrl-c'ing your way
> out of it and starting over--which is the frustrating part.

It is not that I am unsympathetic.  It's just it looks to me that
the patch is potentially adding one more failed step by hiding the
error message to further frustrate the user.

    $ git checkout <TAB>
    ... completes nothing; puzzled but decides not to be worried for now
    $ git checkout master<RET>
    fatal: not a git repository

As you noticed, however, we do not show the ugly error message by
design.  It is not done consistently, either (happens only when we
try to complete refnames).

I was just hoping that somebody (not necessarily you) could suggest
a way to do better than hide the error message only because it looks
ugly (iow, perhaps show it not in the middle of the command line,
and do so more consistently).  Yes I would imagine it would be a lot
harder, but the end user experience _might_ become so much better to
make it worthwhile.  I dunno.

I am not strongly opposed to queuing the patch.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2014-10-14 22:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-10-14 10:49 [PATCH] [kernel] completion: silence "fatal: Not a git repository" error John Szakmeister
2014-10-14 13:58 ` John Szakmeister
2014-10-14 18:29 ` Junio C Hamano
2014-10-14 19:18   ` John Szakmeister
2014-10-14 22:14     ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).