git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] [kernel] completion: silence "fatal: Not a git repository" error

From
John Szakmeister <john@szakmeister.net>
Date
Oct 14, 2014, 19:18 UTC
Message-ID
<CAEBDL5V_Mzxwc4fnybg9=fmeotGV91XerzTccHMWLV79bE+mVA@mail.gmail.com>
In-Reply-To
<xmqqfveqzeqy.fsf@gitster.dls.corp.google.com>
On Tue, Oct 14, 2014 at 2:29 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 23 quoted lines
> 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
Previous: Junio C HamanoNext: Junio C Hamano
Message 4 of 5 in “[kernel] completion: silence "fatal: Not a git repository" error”
  1. [kernel] completion: silence "fatal: Not a git repository" errorJohn Szakmeister, Oct 14, 2014
  2. John SzakmeisterOct 14, 2014
  3. Junio C HamanoOct 14, 2014
  4. John SzakmeisterOct 14, 2014
  5. Junio C HamanoOct 14, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.