<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/builtin/worktree.c, branch v2.22.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.22.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.22.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2019-04-09T17:14:24Z</updated>
<entry>
<title>Merge branch 'ms/worktree-add-atomic-mkdir'</title>
<updated>2019-04-09T17:14:24Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2019-04-09T17:14:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=20fe798b1bf301f78485a56381ad8dad48b2c670'/>
<id>urn:sha1:20fe798b1bf301f78485a56381ad8dad48b2c670</id>
<content type='text'>
"git worktree add" used to do a "find an available name with stat
and then mkdir", which is race-prone.  This has been fixed by using
mkdir and reacting to EEXIST in a loop.

* ms/worktree-add-atomic-mkdir:
  worktree: fix worktree add race
</content>
</entry>
<entry>
<title>worktree: fix worktree add race</title>
<updated>2019-03-12T06:56:11Z</updated>
<author>
<name>Michal Suchanek</name>
<email>msuchanek@suse.de</email>
</author>
<published>2019-02-20T16:16:48Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=7af01f23678dbaeed37773e37737f2ef3db1cb49'/>
<id>urn:sha1:7af01f23678dbaeed37773e37737f2ef3db1cb49</id>
<content type='text'>
Git runs a stat loop to find a worktree name that's available and
then does mkdir on the found name. Turn it to mkdir loop to avoid
another invocation of worktree add finding the same free name and
creating the directory first.

Signed-off-by: Michal Suchanek &lt;msuchanek@suse.de&gt;
Acked-by: Nguyễn Thái Ngọc Duy &lt;pclouds@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>trace2:data: add trace2 hook classification</title>
<updated>2019-02-22T23:28:21Z</updated>
<author>
<name>Jeff Hostetler</name>
<email>jeffhost@microsoft.com</email>
</author>
<published>2019-02-22T22:25:06Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=6206286e49b88bd4bb709c62e7b7455685c1993a'/>
<id>urn:sha1:6206286e49b88bd4bb709c62e7b7455685c1993a</id>
<content type='text'>
Classify certain child processes as hooks.

Signed-off-by: Jeff Hostetler &lt;jeffhost@microsoft.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: allow to (re)move worktrees with uninitialized submodules</title>
<updated>2019-01-07T17:26:33Z</updated>
<author>
<name>Nguyễn Thái Ngọc Duy</name>
<email>pclouds@gmail.com</email>
</author>
<published>2019-01-05T05:08:40Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=00a6d4d1d2260a07ca1372acfae692d9821f165f'/>
<id>urn:sha1:00a6d4d1d2260a07ca1372acfae692d9821f165f</id>
<content type='text'>
Uninitialized submodules have nothing valueable for us to be worried
about. They are just SHA-1. Let "worktree remove" and "worktree move"
continue in this case so that people can still use multiple worktrees
on repos with optional submodules that are never populated, like
sha1collisiondetection in git.git when checked out by doc-diff script.

Note that for "worktree remove", it is possible that a user
initializes a submodule (*), makes some commits (but not push), then
deinitializes it. At that point, the submodule is unpopulated, but the
precious new commits are still in

    $GIT_COMMON_DIR/worktrees/&lt;worktree&gt;/modules/&lt;submodule&gt;

directory and we should not allow removing the worktree or we lose
those commits forever. The new directory check is added to prevent
this.

(*) yes they are screwed anyway by doing this since "git submodule"
    would add submodule.* in $GIT_COMMON_DIR/config, which is shared
    across multiple worktrees. But it does not mean we let them be
    screwed even more.

Signed-off-by: Nguyễn Thái Ngọc Duy &lt;pclouds@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: rename is_worktree_locked to worktree_lock_reason</title>
<updated>2018-10-31T02:41:47Z</updated>
<author>
<name>Nickolai Belakovski</name>
<email>nbelakovski@gmail.com</email>
</author>
<published>2018-10-30T06:24:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=d236f12bdeb478bbaabf056bc611c34cf9218ca8'/>
<id>urn:sha1:d236f12bdeb478bbaabf056bc611c34cf9218ca8</id>
<content type='text'>
A function prefixed with 'is_' would be expected to return a boolean,
however this function returns a string.

Signed-off-by: Nickolai Belakovski &lt;nbelakovski@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: delete .git/worktrees if empty after 'remove'</title>
<updated>2018-08-30T16:28:02Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2018-08-28T21:20:26Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=3a5404333c6c8b5897e78c9dcb711d623035791b'/>
<id>urn:sha1:3a5404333c6c8b5897e78c9dcb711d623035791b</id>
<content type='text'>
For cleanliness, "git worktree prune" deletes the .git/worktrees
directory if it is empty after pruning is complete.

For consistency, make "git worktree remove &lt;path&gt;" likewise delete
.git/worktrees if it is empty after the removal.

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: teach 'remove' to override lock when --force given twice</title>
<updated>2018-08-30T16:28:02Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2018-08-28T21:20:25Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=f4143101cbb26d189f63f2d29875f4acc07b2730'/>
<id>urn:sha1:f4143101cbb26d189f63f2d29875f4acc07b2730</id>
<content type='text'>
For consistency with "add -f -f" and "move -f -f" which override
the lock on a worktree, allow "remove -f -f" to do so, as well, as a
convenience.

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: teach 'move' to override lock when --force given twice</title>
<updated>2018-08-30T16:28:02Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2018-08-28T21:20:24Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=68a6b3a1bd45eb1814a0c1cedfe347692c3f2ff7'/>
<id>urn:sha1:68a6b3a1bd45eb1814a0c1cedfe347692c3f2ff7</id>
<content type='text'>
For consistency with "add -f -f", which allows a missing but locked
worktree path to be re-used, allow "move -f -f" to override a lock,
as well, as a convenience.

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: teach 'add' to respect --force for registered but missing path</title>
<updated>2018-08-30T16:28:02Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2018-08-28T21:20:23Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e19831c94f91fd410fe001c0372b9c88b40d335b'/>
<id>urn:sha1:e19831c94f91fd410fe001c0372b9c88b40d335b</id>
<content type='text'>
For safety, "git worktree add &lt;path&gt;" will refuse to add a new
worktree at &lt;path&gt; if &lt;path&gt; is already associated with a worktree
entry, even if &lt;path&gt; is missing (for instance, has been deleted or
resides on non-mounted removable media or network share). The typical
way to re-create a worktree at &lt;path&gt; in such a situation is either to
prune all "broken" entries ("git worktree prune") or to selectively
remove the worktree entry manually ("git worktree remove &lt;path&gt;").

However, neither of these approaches ("prune" nor "remove") is
especially convenient, and they may be unsuitable for scripting when a
tool merely wants to re-use a worktree if it exists or create it from
scratch if it doesn't (much as a tool might use "mkdir -p" to re-use
or create a directory).

Therefore, teach 'add' to respect --force as a convenient way to
re-use a path already associated with a worktree entry if the path is
non-existent. For a locked worktree, require --force to be specified
twice.

Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: disallow adding same path multiple times</title>
<updated>2018-08-30T16:28:02Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2018-08-28T21:20:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=cb56f55c16c128e18449c9417dc045f787c1b663'/>
<id>urn:sha1:cb56f55c16c128e18449c9417dc045f787c1b663</id>
<content type='text'>
A given path should only ever be associated with a single registered
worktree. This invariant is enforced by refusing to create a new
worktree at a given path if that path already exists. For example:

    $ git worktree add -q --detach foo
    $ git worktree add -q --detach foo
    fatal: 'foo' already exists

However, the check can be fooled, and the invariant broken, if the
path is missing. Continuing the example:

    $ rm -fr foo
    $ git worktree add -q --detach foo
    $ git worktree list
    ...      eadebfe [master]
    .../foo  eadebfe (detached HEAD)
    .../foo  eadebfe (detached HEAD)

This "corruption" leads to the unfortunate situation in which the
worktree can not be removed:

    $ git worktree remove foo
    fatal: validation failed, cannot remove working tree: '.../foo'
    does not point back to '.git/worktrees/foo'

Nor can the bogus entry be pruned:

    $ git worktree prune -v
    $ git worktree list
    ...      eadebfe [master]
    .../foo  eadebfe (detached HEAD)
    .../foo  eadebfe (detached HEAD)

without first deleting the worktree directory manually:

    $ rm -fr foo
    $ git worktree prune -v
    Removing .../foo: gitdir file points to non-existent location
    Removing .../foo1: gitdir file points to non-existent location
    $ git worktree list
    ...  eadebfe [master]

or by manually deleting the worktree entry in .git/worktrees.

To address this problem, upgrade "git worktree add" validation to
allow worktree creation only if the given path is not already
associated with an existing worktree (even if the path itself is
non-existent), thus preventing such bogus worktree entries from being
created in the first place.

Reported-by: Jeff King &lt;peff@peff.net&gt;
Signed-off-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
