From: Duy Nguyen <pclouds@gmail.com>
To: Eric Sunshine <sunshine@sunshineco.com>
Cc: Ingo Wolf <ingo.wolf@gmx.de>, Git List <git@vger.kernel.org>
Subject: Re: worktree add already exists
Date: Mon, 3 Jun 2019 16:46:50 +0700 [thread overview]
Message-ID: <CACsJy8CxSN90-EfTpkd6RUHFVp2iGjZXokpMqw7Tf0EMXT5LfQ@mail.gmail.com> (raw)
In-Reply-To: <CAPig+cSsNQDe-3GLnmvA+EPior=RSPETJDjkCc7X1qi6gWSGDQ@mail.gmail.com>
On Sun, Jun 2, 2019 at 2:11 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
>
> On Mon, May 27, 2019 at 11:32 AM Ingo Wolf <ingo.wolf@gmx.de> wrote:
> > $ ls -a barework
> > ./ ../ test.txt
> > $ git -C bare worktree add --no-checkout ../barework
> > Preparing worktree (new branch 'barework')
> > fatal: '../barework' already exists
> > $ git -C bare branch
> > barework
> > * master
> > Why this doesn't just work and if not why is barework branch made then,
> > why at all ?
>
> It is by design that "git worktree add" (in general) fails if the
> target directory already exists and is non-empty. This is consistent
> with how "git clone" behaves. As for why your particular use-case
> isn't directly supported, it's likely that nobody has yet asked for
> it, and nobody thought about this particular case when --no-checkout
> was added (which came some time after basic "git worktree add" itself
> was implemented).
>
> It is an accident of implementation that the new branch gets created
> before "git worktree add" errors out due to the existing non-empty
> directory (and, likely, nobody complained about it, so it went
> unnoticed). This particular issue probably can be easily fixed now
> that the logic for checking if the target directory can be a valid
> worktree has been factored out of the code which actually creates the
> new directory[1].
>
> [1]: 45059e6468 (worktree: prepare for more checks of whether path can
> become worktree, 2018-08-28)
>
> > I would like to attach an existing dir to git (make it a workdir) and
> > then update the index with git reset and checkin the differences.
>
> I haven't thought through the possible ramifications, but the actual
> implementation might be as simple as changing this code in
> builtin/worktree.c:validate_worktree_add():
>
> if (file_exists(path) && !is_empty_dir(path))
> die(_("'%s' already exists"), path);
>
> to:
>
> if (opts->checkout && file_exists(path) && !is_empty_dir(path))
> die(_("'%s' already exists"), path);
>
> or something.
Coming from "git clone" background I would still expect --no-checkout
to abort on non-empty directory (i.e. we always start at a good known
state). Maybe another option can be used in combination with
--no-checkout for this. And do we want the same option in "git clone"?
--
Duy
next prev parent reply other threads:[~2019-06-03 9:47 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-27 15:32 worktree add already exists Ingo Wolf
2019-06-02 7:07 ` Eric Sunshine
2019-06-03 9:46 ` Duy Nguyen [this message]
2019-06-03 18:32 ` Eric Sunshine
2019-06-05 10:17 ` Duy Nguyen
2019-06-05 15:30 ` Ingo Wolf
2019-06-06 9:34 ` Duy Nguyen
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=CACsJy8CxSN90-EfTpkd6RUHFVp2iGjZXokpMqw7Tf0EMXT5LfQ@mail.gmail.com \
--to=pclouds@gmail.com \
--cc=git@vger.kernel.org \
--cc=ingo.wolf@gmx.de \
--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.
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).