<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/Documentation/git-worktree.txt, branch v2.32.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.32.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.32.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2021-01-30T17:57:40Z</updated>
<entry>
<title>worktree: teach `list` verbose mode</title>
<updated>2021-01-30T17:57:40Z</updated>
<author>
<name>Rafael Silva</name>
<email>rafaeloliveira.cs@gmail.com</email>
</author>
<published>2021-01-27T08:03:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=076b444a6206bd69370efabb5d6d273d4b383a0b'/>
<id>urn:sha1:076b444a6206bd69370efabb5d6d273d4b383a0b</id>
<content type='text'>
"git worktree list" annotates each worktree according to its state such
as "prunable" or "locked", however it is not immediately obvious why
these worktrees are being annotated. For prunable worktrees a reason
is available that is returned by should_prune_worktree() and for locked
worktrees a reason might be available provided by the user via `lock`
command.

Let's teach "git worktree list" a --verbose mode that outputs the reason
why the worktrees are being annotated. The reason is a text that can take
virtually any size and appending the text on the default columned format
will make it difficult to extend the command with other annotations and
not fit nicely on the screen. In order to address this shortcoming the
annotation is then moved to the next line indented followed by the reason
If the reason is not available the annotation stays on the same line as
the worktree itself.

The output of "git worktree list" with verbose becomes like so:

    $ git worktree list --verbose
    ...
    /path/to/locked-no-reason    acb124 [branch-a] locked
    /path/to/locked-with-reason  acc125 [branch-b]
        locked: worktree with a locked reason
    /path/to/prunable-reason     ace127 [branch-d]
        prunable: gitdir file points to non-existent location
    ...

Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Rafael Silva &lt;rafaeloliveira.cs@gmail.com&gt;
Reviewed-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 `list` to annotate prunable worktree</title>
<updated>2021-01-30T17:57:35Z</updated>
<author>
<name>Rafael Silva</name>
<email>rafaeloliveira.cs@gmail.com</email>
</author>
<published>2021-01-27T08:03:09Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=9b19a58f66946c5022fbd1dac6384ca3c86b08ff'/>
<id>urn:sha1:9b19a58f66946c5022fbd1dac6384ca3c86b08ff</id>
<content type='text'>
The "git worktree list" command shows the absolute path to the worktree,
the commit that is checked out, the name of the branch, and a "locked"
annotation if the worktree is locked, however, it does not indicate
whether the worktree is prunable.

The "prune" command will remove a worktree if it is prunable unless
`--dry-run` option is specified. This could lead to a worktree being
removed without the user realizing before it is too late, in case the
user forgets to pass --dry-run for instance. If the "list" command shows
which worktree is prunable, the user could verify before running
"git worktree prune" and hopefully prevents the working tree to be
removed "accidentally" on the worse case scenario.

Let's teach "git worktree list" to show when a worktree is a prunable
candidate for both default and porcelain format.

In the default format a "prunable" text is appended:

    $ git worktree list
    /path/to/main      aba123 [main]
    /path/to/linked    123abc [branch-a]
    /path/to/prunable  ace127 (detached HEAD) prunable

In the --porcelain format a prunable label is added followed by
its reason:

    $ git worktree list --porcelain
    ...
    worktree /path/to/prunable
    HEAD abc1234abc1234abc1234abc1234abc1234abc12
    detached
    prunable gitdir file points to non-existent location
    ...

Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Rafael Silva &lt;rafaeloliveira.cs@gmail.com&gt;
Reviewed-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 `list --porcelain` to annotate locked worktree</title>
<updated>2021-01-30T17:57:29Z</updated>
<author>
<name>Rafael Silva</name>
<email>rafaeloliveira.cs@gmail.com</email>
</author>
<published>2021-01-27T08:03:08Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=862c723d18ddc6be183abc450a9fb220ba4efb0b'/>
<id>urn:sha1:862c723d18ddc6be183abc450a9fb220ba4efb0b</id>
<content type='text'>
Commit c57b3367be (worktree: teach `list` to annotate locked worktree,
2020-10-11) taught "git worktree list" to annotate locked worktrees by
appending "locked" text to its output, however, this is not listed in
the --porcelain format.

Teach "list --porcelain" to do the same and add a "locked" attribute
followed by its reason, thus making both default and porcelain format
consistent. If the locked reason is not available then only "locked"
is shown.

The output of the "git worktree list --porcelain" becomes like so:

    $ git worktree list --porcelain
    ...
    worktree /path/to/locked
    HEAD 123abcdea123abcd123acbd123acbda123abcd12
    detached
    locked

    worktree /path/to/locked-with-reason
    HEAD abc123abc123abc123abc123abc123abc123abc1
    detached
    locked reason why it is locked
    ...

In porcelain mode, if the lock reason contains special characters
such as newlines, they are escaped with backslashes and the entire
reason is enclosed in double quotes. For example:

   $ git worktree list --porcelain
   ...
   locked "worktree's path mounted in\nremovable device"
   ...

Furthermore, let's update the documentation to state that some
attributes in the porcelain format might be listed alone or together
with its value depending whether the value is available or not. Thus
documenting the case of the new "locked" attribute.

Helped-by: Phillip Wood &lt;phillip.wood@dunelm.org.uk&gt;
Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Rafael Silva &lt;rafaeloliveira.cs@gmail.com&gt;
Reviewed-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 `repair` to fix multi-directional breakage</title>
<updated>2020-12-21T21:44:28Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-12-21T08:16:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=cf76baea41bb7f6431dbfa5744c861fdb844d20b'/>
<id>urn:sha1:cf76baea41bb7f6431dbfa5744c861fdb844d20b</id>
<content type='text'>
`git worktree repair` knows how to repair the two-way links between the
repository and a worktree as long as a link in one or the other
direction is sound. For instance, if a linked worktree is moved (without
using `git worktree move`), repair is possible because the worktree
still knows the location of the repository even though the repository no
longer knows where the worktree is. Similarly, if the repository is
moved, repair is possible since the repository still knows the locations
of the worktrees even though the worktrees no longer know where the
repository is.

However, if both the repository and the worktrees are moved, then links
are severed in both directions, and no repair is possible. This is the
case even when the new worktree locations are specified as arguments to
`git worktree repair`. The reason for this limitation is twofold. First,
when `repair` consults the worktree's gitfile (/path/to/worktree/.git)
to determine the corresponding &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir file to fix,
&lt;repo&gt; is the old path to the repository, thus it is unable to fix the
`gitdir` file at its new location since it doesn't know where it is.
Second, when `repair` consults &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir to find the
location of the worktree's gitfile (/path/to/worktree/.git), the path
recorded in `gitdir` is the old location of the worktree's gitfile, thus
it is unable to repair the gitfile since it doesn't know where it is.

Fix these shortcomings by teaching `repair` to attempt to infer the new
location of the &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir file when the location
recorded in the worktree's gitfile has become stale but the file is
otherwise well-formed. The inference is intentionally simple-minded.
For each worktree path specified as an argument, `git worktree repair`
manually reads the ".git" gitfile at that location and, if it is
well-formed, extracts the &lt;id&gt;. It then searches for a corresponding
&lt;id&gt; in &lt;repo&gt;/worktrees/ and, if found, concludes that there is a
reasonable match and updates &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir to point at
the specified worktree path. In order for &lt;repo&gt; to be known, `git
worktree repair` must be run in the main worktree or bare repository.

`git worktree repair` first attempts to repair each incoming
/path/to/worktree/.git gitfile to point at the repository, and then
attempts to repair outgoing &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir files to point
at the worktrees. This sequence was chosen arbitrarily when originally
implemented since the order of fixes is immaterial as long as one side
of the two-way link between the repository and a worktree is sound.
However, for this new repair technique to work, the order must be
reversed. This is because the new inference mechanism, when it is
successful, allows the outgoing &lt;repo&gt;/worktrees/&lt;id&gt;/gitdir file to be
repaired, thus fixing one side of the two-way link. Once that side is
fixed, the other side can be fixed by the existing repair mechanism,
hence the order of repairs is now significant.

Two safeguards are employed to avoid hijacking a worktree from a
different repository if the user accidentally specifies a foreign
worktree as an argument. The first, as described above, is that it
requires an &lt;id&gt; match between the repository and the worktree. That
itself is not foolproof for preventing hijack, so the second safeguard
is that the inference will only kick in if the worktree's
/path/to/worktree/.git gitfile does not point at a repository.

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 `list` to annotate locked worktree</title>
<updated>2020-10-12T19:24:29Z</updated>
<author>
<name>Rafael Silva</name>
<email>rafaeloliveira.cs@gmail.com</email>
</author>
<published>2020-10-11T10:11:52Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c57b3367bed488469d24a21446731e9e71846ded'/>
<id>urn:sha1:c57b3367bed488469d24a21446731e9e71846ded</id>
<content type='text'>
The "git worktree list" shows the absolute path to the working tree,
the commit that is checked out and the name of the branch. It is not
immediately obvious which of the worktrees, if any, are locked.

"git worktree remove" refuses to remove a locked worktree with
an error message. If "git worktree list" told which worktrees
are locked in its output, the user would not even attempt to
remove such a worktree, or would realize that
"git worktree remove -f -f &lt;path&gt;" is required.

Teach "git worktree list" to append "locked" to its output.
The output from the command becomes like so:

    $ git worktree list
    /path/to/main             abc123 [master]
    /path/to/worktree         456def (detached HEAD)
    /path/to/locked-worktree  123abc (detached HEAD) locked

Helped-by: Junio C Hamano &lt;gitster@pobox.com&gt;
Helped-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Rafael Silva &lt;rafaeloliveira.cs@gmail.com&gt;
Reviewed-by: Eric Sunshine &lt;sunshine@sunshineco.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'es/wt-add-detach'</title>
<updated>2020-09-19T00:58:04Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2020-09-19T00:58:04Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=45f462b5c5a55039c35fc7001f2256329220bf4f'/>
<id>urn:sha1:45f462b5c5a55039c35fc7001f2256329220bf4f</id>
<content type='text'>
"git worktree add" learns that the "-d" is a synonym to "--detach"
option to create a new worktree without being on a branch.

* es/wt-add-detach:
  git-worktree.txt: discuss branch-based vs. throwaway worktrees
  worktree: teach `add` to recognize -d as shorthand for --detach
  git-checkout.txt: document -d short option for --detach
</content>
</entry>
<entry>
<title>git-worktree.txt: discuss branch-based vs. throwaway worktrees</title>
<updated>2020-09-07T01:53:56Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-09-07T00:02:22Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dccadad736c801e924c7c14e8c6bd1a6e15e70e5'/>
<id>urn:sha1:dccadad736c801e924c7c14e8c6bd1a6e15e70e5</id>
<content type='text'>
By default, `git worktree add` creates a new worktree associated with a
particular branch (which may have been created automatically if not
specified explicitly on the command-line). It is also convenient to
create throwaway worktrees not associated with any branch, which can be
handy when making experimental changes or doing testing. However, the
latter use-case may not be obvious to newcomers since the high-level
description of worktrees talks only about checking out "more than one
branch at a time". Therefore, enhance the description to to discuss both
use-cases.

A secondary goal of highlighting the distinction between branch-based
and throwaway worktrees is to help newcomers understand that the
simplest form `git worktree add &lt;path&gt;` automatically creates a new
branch. Stating this early in the description, may help newcomers avoid
creating branches without realizing they are doing so, and later
wondering why `git branch --list` shows branches the user did not
intentionally create.

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 recognize -d as shorthand for --detach</title>
<updated>2020-09-07T01:53:56Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-09-07T00:02:21Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=c670aa47dff9829360cc69174f8dd0d82f096011'/>
<id>urn:sha1:c670aa47dff9829360cc69174f8dd0d82f096011</id>
<content type='text'>
Like `git switch` and `git checkout`, `git worktree add` can check out a
branch or set up a detached HEAD. However, unlike those other commands,
`git worktree add` does not understand -d as shorthand for --detach,
which may confound users accustomed to using -d for this purpose.
Address this shortcoming by teaching `add` to recognize -d for --detach,
thus bringing it in line with the other commands.

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 "repair" to fix outgoing links to worktrees</title>
<updated>2020-08-31T18:47:45Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-08-31T06:57:58Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b214ab5aa597e748c228e657d4eb7c18960e6a67'/>
<id>urn:sha1:b214ab5aa597e748c228e657d4eb7c18960e6a67</id>
<content type='text'>
The .git/worktrees/&lt;id&gt;/gitdir file points at the location of a linked
worktree's .git file. Its content must be of the form
/path/to/worktree/.git (from which the location of the worktree itself
can be derived by stripping the "/.git" suffix). If the gitdir file is
deleted or becomes corrupted or outdated, then Git will be unable to
find the linked worktree. An easy way for the gitdir file to become
outdated is for the user to move the worktree manually (without using
"git worktree move"). Although it is possible to manually update the
gitdir file to reflect the new linked worktree location, doing so
requires a level of knowledge about worktree internals beyond what a
user should be expected to know offhand.

Therefore, teach "git worktree repair" how to repair broken or outdated
.git/worktrees/&lt;id&gt;/gitdir files automatically. (For this to work, the
command must either be invoked from within the worktree whose gitdir
file requires repair, or from within the main or any linked worktree by
providing the path of the broken worktree as an argument to "git
worktree repair".)

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 "repair" to fix worktree back-links to main worktree</title>
<updated>2020-08-31T18:47:45Z</updated>
<author>
<name>Eric Sunshine</name>
<email>sunshine@sunshineco.com</email>
</author>
<published>2020-08-31T06:57:57Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bdd1f3e4da716012a52194cdfbc9c80dfdce87d4'/>
<id>urn:sha1:bdd1f3e4da716012a52194cdfbc9c80dfdce87d4</id>
<content type='text'>
The .git file in a linked worktree is a "gitfile" which points back to
the .git/worktrees/&lt;id&gt; entry in the main worktree or bare repository.
If a worktree's .git file is deleted or becomes corrupted or outdated,
then the linked worktree won't know how to find the repository or any of
its own administrative files (such as 'index', 'HEAD', etc.). An easy
way for the .git file to become outdated is for the user to move the
main worktree or bare repository. Although it is possible to manually
update each linked worktree's .git file to reflect the new repository
location, doing so requires a level of knowledge about worktree
internals beyond what a user should be expected to know offhand.

Therefore, teach "git worktree repair" how to repair broken or outdated
worktree .git files automatically. (For this to work, the command must
be invoked from within the main worktree or bare repository, or from
within a worktree which has not become disconnected from the repository
-- such as one which was created after the repository was moved.)

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