git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: phillip.wood123@gmail.com
Cc: Eric Sunshine <sunshine@sunshineco.com>,
	 phillip.wood@dunelm.org.uk,
	Russell Stuart <russell+git.vger.kernel.org@stuart.id.au>,
	git@vger.kernel.org
Subject: Re: "git worktree repair" modifies the wrong repository
Date: Fri, 04 Oct 2024 08:50:26 -0700	[thread overview]
Message-ID: <xmqqo73zg94t.fsf@gitster.g> (raw)
In-Reply-To: <6c0b8681-95ca-4224-ba89-7582fd731565@gmail.com> (phillip's message of "Fri, 4 Oct 2024 10:15:55 +0100")

phillip.wood123@gmail.com writes:

> "git clone --mirror" sets up a fetch refspec that forcibly update
> "refs/heads/*" when fetching. This means fetching overwrites your
> local branches and I think the fetch fails if you have a branch
> checked out that it wants to update. "git clone --bare" does not set
> up any fetch refspec. In both cases there are no remote tracking
> branches to base your local work on.
>
>> Regarding core.bare: That's one of the settings which is special-cased
>> (hard-coded) to work "properly" when extensions.worktreeConfig is not
>> enabled, so it's not clear what problem you were experiencing in that
>> regard. In my testing, `git rev-parse --is-bare-repository` correctly
>> reported "true" in the bare repository, and "false" in a worktree
>> hanging off the bare repository even when extensions.worktreeConfig
>> was not enabled.
>
> I've a feeling I thought I needed to set it because I didn't realize
> that core.bare was special cased rather than doing so in response to a
> particular problem but I can't remember for sure.

I recently encountered a funny behaviour in a worktree linked to a
bare repository.

    $ git clone --bare file://$(pwd)/git.git victim-00.git
    $ git -C victim-00.git worktree add ../victim-01
    $ cd victim-01
    $ git grep -i -e subscribe
    fatal: this operation must be run in a work tree

Of course, "git grep -i subscribe HEAD" works (as it does not
require a working tree and works on a proper bare repository).

What is curious is that this also works:

    $ git grep -i -e subscribe --cached

That mode of operation can work only when the index exists,
which means it needs a working tree.  Perhaps the working tree
version is written in a more strict way to avoid unexpected
behaviour (and gets the implementation of strictness wrong), while
the index version has no such protection?  Running the index version
in the bare repository

    $ git -C ../victim-00.git -i -e subscribe --cached; echo $?
    1

seems to confirm.  The command does not fail, but in a bare
repository, the in-core the_index has 0 elements, so it thinks it
successfully looked for the needle in the haystack and found
nothing, without complaining "hey, there is no haystack".

With the extensions.worktreeConfig things work as expected in the
worktree linked to the bare repository, like so:

    $ cd ../victim-01
    $ git config set extensions.worktreeConfig true
    $ git config set core.bare false
    $ git grep -i -e subscribe

So, I dunno.  Is core.bare really "special cased"?  It seems to me
that any halfway special case harms users more than helps.



  reply	other threads:[~2024-10-04 15:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-19  1:12 "git worktree repair" modifies the wrong repository Russell Stuart
2024-09-19  8:58 ` Eric Sunshine
2024-09-19 10:16   ` Russell Stuart
2024-09-19 10:47     ` Eric Sunshine
2024-09-19 11:40       ` Russell Stuart
2024-09-23 18:52         ` Eric Sunshine
2024-09-24 13:53           ` Phillip Wood
2024-10-03  6:28             ` Eric Sunshine
2024-10-04  9:15               ` phillip.wood123
2024-10-04 15:50                 ` Junio C Hamano [this message]
2024-09-25  9:31           ` Russell Stuart

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=xmqqo73zg94t.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=phillip.wood123@gmail.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=russell+git.vger.kernel.org@stuart.id.au \
    --cc=sunshine@sunshineco.com \
    /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).