git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: Cameron Gunnin <cameron.gunnin@synopsys.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: BUG: git worktree add directory-path fails due to over-aggressive disallowing of worktrees with same suffix
Date: Tue, 12 Feb 2019 17:44:41 -0500	[thread overview]
Message-ID: <CAPig+cQh8hxeoVjLHDKhAcZVQPpPT5v0AUY8gsL9=qfJ7z-L2A@mail.gmail.com> (raw)
In-Reply-To: <0308570E-AAA3-43B8-A592-F4DA9760DBED@synopsys.com>

On Mon, Feb 11, 2019 at 6:50 PM Cameron Gunnin
<cameron.gunnin@synopsys.com> wrote:
> The bug:
>   cd unique-path-1
>   git --git-dir=../worktree-test-repo/.git worktree add subdir branch1
>   cd ../unique-path-2
>   git --git-dir=../worktree-test-repo/.git worktree add subdir branch2
>   # FAILS WITH: fatal: 'subdir' is a missing but already registered worktree; use 'add -f' to override, or 'prune' or 'remove' to clear
>
> This appears to have been introduced by the following commit:
>       worktree: disallow adding same path multiple times
>
> The fix, I think, should be applied to builtin/worktree.c to the
> validate_worktree_add method. After finding a worktree that matches
> the suffix (via find_worktree), it should check that the absolute
> path of the found worktree is the same as the absolute path of the
> worktree being added, and allow the add when they are different. Or,
> perhaps there should be a way to invoke 'find_worktree' such that it
> only finds absolute path matches.

When crafting cb56f55c16 (worktree: disallow adding same path multiple
times, 2018-08-28), I flip-flopped between two implementations: (1)
using find_worktree(), and (2) manually scanning the worktree list
with absolute path comparison. The latter approach, would not have
suffered from this problem. The one ugly bit of the manual scan was
that it was a bit too cozy with the underlying worktree
implementation, so I eventually went with the find_worktree() approach
despite its obvious drawback of doing suffix matching (though, I
didn't feel particularly comfortable with the decision).

A likely reasonable approach to fixing it would probably be to
introduce new worktree API to find a worktree without magic suffix
matching (i.e. literal absolute path matching) which would avoid
having to imbue the higher-level "git worktree" command with that
low-level knowledge, and then take advantage of that new API.

  reply	other threads:[~2019-02-12 22:44 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-11 23:50 BUG: git worktree add directory-path fails due to over-aggressive disallowing of worktrees with same suffix Cameron Gunnin
2019-02-12 22:44 ` Eric Sunshine [this message]
2020-02-24  9:08   ` [PATCH 0/3] git-worktree: fix "add" being fooled by suffix matching Eric Sunshine
2020-02-24  9:08     ` [PATCH 1/3] worktree: improve find_worktree() documentation Eric Sunshine
2020-02-24  9:08     ` [PATCH 2/3] worktree: add utility to find worktree by pathname Eric Sunshine
2020-02-24  9:08     ` [PATCH 3/3] worktree: don't allow "add" validation to be fooled by suffix matching Eric Sunshine
2020-02-24 21:06       ` Junio C Hamano
2020-02-24 21:02     ` [PATCH 0/3] git-worktree: fix "add" being " Junio C Hamano

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+cQh8hxeoVjLHDKhAcZVQPpPT5v0AUY8gsL9=qfJ7z-L2A@mail.gmail.com' \
    --to=sunshine@sunshineco.com \
    --cc=cameron.gunnin@synopsys.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).