git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Anthony Sottile <asottile@umich.edu>
Cc: Git Mailing List <git@vger.kernel.org>
Subject: Re: git rev-parse --show-toplevel inside `.git` returns 0 and prints nothing
Date: Tue, 19 Nov 2019 11:52:54 +0900	[thread overview]
Message-ID: <xmqqk17wziex.fsf@gitster-ct.c.googlers.com> (raw)
In-Reply-To: <CA+dzEBmrMavFJeyPSQr2wA9kFZwz_Kfr6PFBLRfLJ-EuCVXJnA@mail.gmail.com> (Anthony Sottile's message of "Mon, 18 Nov 2019 14:26:53 -0800")

Anthony Sottile <asottile@umich.edu> writes:

> I would expect it to either:
> - exit nonzero
> - produce the full path to the root of the repository
>
> would a patch be accepted which changes it to do one of those two
> things? I'd be happy to contribute such a patch

The most important invariant for the "--show-toplevel" and the
"--show-prefix" options was that when they are concatenated the
result matches the current directory in a working tree.  So I think
the result is undefined when you are not anywhere in the working
tree.

Having said that, as scripts that want to know if they are inside
.git directory (either directly in it, or in its subdirectories)
should not be relying on the behaviour, and instead be using the
"--is-inside-git-dir" option, I suspect that it won't be too
disruptive to change the behaviour after all these years.  

But it is no longer year 2007 and with widespread use of Git, it is
almost guaranteed to break somebody's script ;-)

If I were designing the feature today, with today's rest-of-git in
mind, I would say

 - In a bare repository, exit with non-zero status after giving an
   error message "no working tree".

 - In a repository that has a single associated working tree, show
   the path to the top-level of that working tree and exit with zero
   status.

In a repository that has more than one working trees (which is one
of the things "todasy's rest-of-git" has that did not exist back
when --show-prefix/--show-toplevel etc. were invented), then what?
Would it make sense to show the primary working tree?  What if the
worktree(s) were made off of a bare repository, in which case nobody
is the primary?

If we were changing "--show-toplevel", we may need to make changes
to "--show-prefix" to things consistent, but I am not sure what it
should say when run outside a working tree.  It should continue to
give nothing; it may make sense to exit with non-zero status, but
I'd rather let sleeping dogs lie.  Nobody is hurting by the command
exiting with zero status (the same question applies to the
"--show-toplevel" option, for that matter, though), when the result
is undefined.

So...  I dunno.




  reply	other threads:[~2019-11-19  2:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-18 22:26 git rev-parse --show-toplevel inside `.git` returns 0 and prints nothing Anthony Sottile
2019-11-19  2:52 ` Junio C Hamano [this message]
2019-11-19  3:33   ` Jeff King
2019-11-19  4:13     ` Anthony Sottile
2019-11-19  7:37       ` Jeff King
2019-11-19  8:05     ` Jeff King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqqk17wziex.fsf@gitster-ct.c.googlers.com \
    --to=gitster@pobox.com \
    --cc=asottile@umich.edu \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).