From: Anthony Sottile <asottile@umich.edu>
To: Jeff King <peff@peff.net>
Cc: Junio C Hamano <gitster@pobox.com>,
Git Mailing List <git@vger.kernel.org>
Subject: Re: git rev-parse --show-toplevel inside `.git` returns 0 and prints nothing
Date: Mon, 18 Nov 2019 20:13:02 -0800 [thread overview]
Message-ID: <CA+dzEBmekzDVdqy=4GDF+Wm8e-YTPEdbh0oVowZNQYO67vEhEg@mail.gmail.com> (raw)
In-Reply-To: <20191119033311.GA18613@sigill.intra.peff.net>
On Mon, Nov 18, 2019 at 7:33 PM Jeff King <peff@peff.net> wrote:
>
> On Tue, Nov 19, 2019 at 11:52:54AM +0900, Junio C Hamano wrote:
>
> > 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.
>
> Do you mean to do this even in when the cwd is inside .git?
>
> I think that's confusing, because you don't actually have a working tree
> at all. E.g.:
>
> $ git rev-parse --show-toplevel
> /home/peff/tmp
> $ git status -b --short
> ## No commits yet on master
>
> $ cd .git
> $ git rev-parse --show-toplevel
> $ git status -b --short
> fatal: this operation must be run in a work tree
>
> So internal commands like status accept that we have no working tree in
> this situation. But "--show-toplevel" just prints nothing. I'd amend
> your second point to be "If we are in the working tree of a repository,
> show the path to the top-level of that working tree and exit with zero
> status".
>
> And then that leaves another case: we are not in the working tree of the
> repository. In which case I think it should be the same as the bare
> repository.
>
> And from that, your multi-working-tree case falls out naturally:
>
> > 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?
>
> There may be multiple working trees, but we can only be in one of them
> at a time. So that's the one that we show.
>
> And the only real change here is that "--show-toplevel" prints an error
> and exits non-zero when we won't have a working tree. Something like:
>
> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c
> index 3857fd1b8a..81161f2dfb 100644
> --- a/builtin/rev-parse.c
> +++ b/builtin/rev-parse.c
> @@ -805,6 +805,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
> const char *work_tree = get_git_work_tree();
> if (work_tree)
> puts(work_tree);
> + else
> + die("this operation must be run in a work tree");
> continue;
> }
> if (!strcmp(arg, "--show-superproject-working-tree")) {
>
>
> I think the reason this hasn't come up until now is callers are expected
> to use require_work_tree() or "rev-parse --is-inside-work-tree" first.
>
> It would probably make sense for the rev-parse documentation to also
> clarify what "the top-level directory" is.
>
> -Peff
I realize I forgot to include the X to my Y :) -- this was a totally
silly case that I got as a bug report:
https://github.com/pre-commit/pre-commit/issues/1219
I *expected* an error case but didn't get one
Anthony
next prev parent reply other threads:[~2019-11-19 4:13 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
2019-11-19 3:33 ` Jeff King
2019-11-19 4:13 ` Anthony Sottile [this message]
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='CA+dzEBmekzDVdqy=4GDF+Wm8e-YTPEdbh0oVowZNQYO67vEhEg@mail.gmail.com' \
--to=asottile@umich.edu \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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).