From: Eric Sunshine <sunshine@sunshineco.com>
To: Toru Okugawa <castor.4bit@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: Unexpected behavior with the rev-parse operation
Date: Sun, 28 Apr 2024 14:08:47 -0400 [thread overview]
Message-ID: <CAPig+cQ39Z+WjThqkxCKgOUfkZyB6PG-6RhHBYhinp-ZY4dxKA@mail.gmail.com> (raw)
In-Reply-To: <CANHPH1-6mbWdt_FLsrDEB_XVb4r3yTYMLLPUyDrL6tmS7jZgqQ@mail.gmail.com>
On Mon, Apr 15, 2024 at 9:58 AM Toru Okugawa <castor.4bit@gmail.com> wrote:
> I have encountered some unexpected behavior with the rev-parse operation.
> ---
> $ ls -a
> . ..
> $ git rev-parse --is-inside-work-tree
> fatal: not a git repository (or any of the parent directories): .git
>
> What did you expect to happen? (Expected behavior)
>
> If the current working directory is outside the work tree, the
> documentation says that `git rev-parse --is-inside-work-tree` will
> output false.
> https://git-scm.com/docs/git-rev-parse#Documentation/git-rev-parse.txt---is-inside-work-tree
I think this is working as intended, but the documentation is lacking
or misleading. With very few exceptions[1], `git rev-parse` expects to
be run either within a Git working tree or within a Git repository
(i.e. the .git/ directory or a bare repository). Options such as
--is-inside-work-tree, --is-bare-repository, etc. are meant to report
upon aspects of the worktree or repository in which the command is
invoked.
Looking at the source code for `git rev-parse`, it does appear that it
has explicit support for the case of checking whether or not the
current directory is a Git worktree or repository. The way to do that
is to run `git rev-parse` without any arguments. However, even in that
case, it will print the "fatal: not a git repository" error. This
means it is your responsibility, as a script writer, to suppress or
capture the error message (whichever is appropriate for your case).
For instance:
if test git rev-parse >/dev/null 2>&1
then
echo "in a Git directory or repository"
else
echo "not in a Git directory or repository"
fi
[1]: --sh-quote, --parse-opt, --local-env-vars, --resolve-git-dir
next prev parent reply other threads:[~2024-04-28 18:09 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-15 13:58 Unexpected behavior with the rev-parse operation Toru Okugawa
2024-04-28 18:08 ` Eric Sunshine [this message]
2024-04-28 23:07 ` Re* " Junio C Hamano
2024-04-30 14:26 ` Toru Okugawa
2024-04-30 18:46 ` Junio C Hamano
2024-05-01 4:55 ` Toru Okugawa
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPig+cQ39Z+WjThqkxCKgOUfkZyB6PG-6RhHBYhinp-ZY4dxKA@mail.gmail.com \
--to=sunshine@sunshineco.com \
--cc=castor.4bit@gmail.com \
--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.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
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 read-only IMAP folder(s) and NNTP newsgroup(s).