mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Eric Sunshine <>
To: Ingo Wolf <>
Cc: Git List <>
Subject: Re: worktree add already exists
Date: Sun, 2 Jun 2019 03:07:45 -0400	[thread overview]
Message-ID: <> (raw)
In-Reply-To: <>

On Mon, May 27, 2019 at 11:32 AM Ingo Wolf <> 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

    if (file_exists(path) && !is_empty_dir(path))
        die(_("'%s' already exists"), path);


    if (opts->checkout && file_exists(path) && !is_empty_dir(path))
        die(_("'%s' already exists"), path);

or something.

  reply	other threads:[~2019-06-02  7:07 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 [this message]
2019-06-03  9:46   ` Duy Nguyen
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:

  List information:

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='' \ \ \ \

* 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

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).