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

Re: Re* Unexpected behavior with the rev-parse operation

From
Junio C Hamano <gitster@pobox.com>
Date
Apr 30, 2024, 18:46 UTC
Message-ID
<xmqqedamzo17.fsf@gitster.g>
In-Reply-To
<CANHPH19FCWUAMZLFZEY+_+zv0KUkuVGNQS26WmEPjnPtjrK8KQ@mail.gmail.com>
Toru Okugawa <castor.4bit@gmail.com> writes:
> However, if determining the presence of a Git repository by checking
> for errors is the appropriate approach, I'm interested in
> understanding the intended use of the `--is-inside-work-tree` option.
> I had thought it was meant to suppress errors in exceptional cases.
    $ rm -fr mine
    $ git init mine ;# notice the lack of --bare
    $ cd mine
    $ git commit --allow-empty -m 'initial'
    $ git rev-parse --is-inside-work-tree; echo $?
    true
    0
    $ cd .git
    $ git rev-parse --is-inside-work-tree; echo $?
    false
    0
    $ cd ../..
    $ git --bare init mine.bare ;# this time bare
    $ cd mine.bare
    false
    0

When you write a script that you might want to use as a part of a hook, for example, you may end up running it inside .git/ and it may be necessary (depending on what the script does and how it is written) to tell where you are in the working tree (or if you are in the working tree in the first place).

Previous: Toru OkugawaNext: Toru Okugawa
Message 5 of 6 in “Unexpected behavior with the rev-parse operation”
  1. Toru OkugawaApr 15, 2024
  2. Eric SunshineApr 28, 2024
  3. Re* Unexpected behavior with the rev-parse operationJunio C Hamano, Apr 28, 2024
  4. Toru OkugawaApr 30, 2024
  5. Junio C HamanoApr 30, 2024
  6. Toru OkugawaMay 1, 2024

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.