<feed xmlns='http://www.w3.org/2005/Atom'>
<title>git/worktree.h, branch v2.48.2</title>
<subtitle>Mirror of https://git.kernel.org/pub/scm/git/git.git/
</subtitle>
<id>https://git.shady.money/git/atom?h=v2.48.2</id>
<link rel='self' href='https://git.shady.money/git/atom?h=v2.48.2'/>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/'/>
<updated>2024-12-02T00:36:17Z</updated>
<entry>
<title>worktree: add relative cli/config options to `repair` command</title>
<updated>2024-12-02T00:36:17Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:23:10Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=e6df1ee2c13405ef7077256fef49424f69d61125'/>
<id>urn:sha1:e6df1ee2c13405ef7077256fef49424f69d61125</id>
<content type='text'>
This teaches the `worktree repair` command to respect the
`--[no-]relative-paths` CLI option and `worktree.useRelativePaths`
config setting. If an existing worktree with an absolute path is repaired
with `--relative-paths`, the links will be replaced with relative paths,
even if the original path was correct. This allows a user to covert
existing worktrees between absolute/relative as desired.

To simplify things, both linking files are written when one of the files
needs to be repaired. In some cases, this fixes the other file before it
is checked, in other cases this results in a correct file being written
with the same contents.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: add relative cli/config options to `move` command</title>
<updated>2024-12-02T00:36:17Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:23:03Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=298d2917e26520791b47ba5d38c1866e21894cc7'/>
<id>urn:sha1:298d2917e26520791b47ba5d38c1866e21894cc7</id>
<content type='text'>
This teaches the `worktree move` command to respect the
`--[no-]relative-paths` CLI option and `worktree.useRelativePaths`
config setting. If an existing worktree is moved with `--relative-paths`
the new path will be relative (and visa-versa).

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: add `write_worktree_linking_files()` function</title>
<updated>2024-12-02T00:36:17Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-11-29T22:22:47Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=4dac9e3c01cf056edd315e0ed26e6df1c4d94571'/>
<id>urn:sha1:4dac9e3c01cf056edd315e0ed26e6df1c4d94571</id>
<content type='text'>
A new helper function, `write_worktree_linking_files()`, centralizes
the logic for computing and writing either relative or absolute
paths, based on the provided configuration. This function accepts
`strbuf` pointers to both the worktree’s `.git` link and the
repository’s `gitdir`, and then writes the appropriate path to each.
The `relativeWorktrees` extension is automatically set when a worktree
is linked with relative paths.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: link worktrees with relative paths</title>
<updated>2024-10-08T18:49:22Z</updated>
<author>
<name>Caleb White</name>
<email>cdwhite3@pm.me</email>
</author>
<published>2024-10-08T03:12:31Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=717af916cd69d2565aa2a7b7d73d895aa92ff392'/>
<id>urn:sha1:717af916cd69d2565aa2a7b7d73d895aa92ff392</id>
<content type='text'>
Git currently stores absolute paths to both the main repository and
linked worktrees. However, this causes problems when moving repositories
or working in containerized environments where absolute paths differ
between systems. The worktree links break, and users are required to
manually execute `worktree repair` to repair them, leading to workflow
disruptions. Additionally, mapping repositories inside of containerized
environments renders the repository unusable inside the containers, and
this is not repairable as repairing the worktrees inside the containers
will result in them being broken outside the containers.

To address this, this patch makes Git always write relative paths when
linking worktrees. Relative paths increase the resilience of the
worktree links across various systems and environments, particularly
when the worktrees are self-contained inside the main repository (such
as when using a bare repository with worktrees). This improves
portability, workflow efficiency, and reduces overall breakages.

Although Git now writes relative paths, existing repositories with
absolute paths are still supported. There are no breaking changes
to workflows based on absolute paths, ensuring backward compatibility.

At a low level, the changes involve modifying functions in `worktree.c`
and `builtin/worktree.c` to use `relative_path()` when writing the
worktree’s `.git` file and the main repository’s `gitdir` reference.
Instead of hardcoding absolute paths, Git now computes the relative path
between the worktree and the repository, ensuring that these links are
portable. Locations where these respective file are read have also been
updated to properly handle both absolute and relative paths. Generally,
relative paths are always resolved into absolute paths before any
operations or comparisons are performed.

Additionally, `repair_worktrees_after_gitdir_move()` has been introduced
to address the case where both the `&lt;worktree&gt;/.git` and
`&lt;repo&gt;/worktrees/&lt;id&gt;/gitdir` links are broken after the gitdir is
moved (such as during a re-initialization). This function repairs both
sides of the worktree link using the old gitdir path to reestablish the
correct paths after a move.

The `worktree.path` struct member has also been updated to always store
the absolute path of a worktree. This ensures that worktree consumers
never have to worry about trying to resolve the absolute path themselves.

Signed-off-by: Caleb White &lt;cdwhite3@pm.me&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'jc/worktree-git-path'</title>
<updated>2024-06-24T23:39:15Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-06-24T23:39:15Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=107ed551030713e25933dc8e92ad8d67cff28ff6'/>
<id>urn:sha1:107ed551030713e25933dc8e92ad8d67cff28ff6</id>
<content type='text'>
Code cleanup.

* jc/worktree-git-path:
  worktree_git_path(): move the declaration to path.h
</content>
</entry>
<entry>
<title>worktree_git_path(): move the declaration to path.h</title>
<updated>2024-06-08T18:42:37Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2024-06-08T18:39:01Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=bf6a86236e829d08c92356e5c861193ccb516ef7'/>
<id>urn:sha1:bf6a86236e829d08c92356e5c861193ccb516ef7</id>
<content type='text'>
The definition of this function is in path.c but its declaration is
in worktree.h, which is something unexpected.  The function is
explained as "Similar to git_path()"; declaring it next to where
git_path() is declared would make more sense.

Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>refs: retrieve worktree ref stores via associated repository</title>
<updated>2024-05-17T17:33:38Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-05-17T08:18:44Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=dc7fb4f72c2e39ffbb98aee55ad7ea4c3f8e12fc'/>
<id>urn:sha1:dc7fb4f72c2e39ffbb98aee55ad7ea4c3f8e12fc</id>
<content type='text'>
Similar as with the preceding commit, the worktree ref stores are always
looked up via `the_repository`. Also, again, those ref stores are stored
in a global map.

Refactor the code so that worktrees have a pointer to their repository.
Like this, we can move the global map into `struct repository` and stop
using `the_repository`. With this change, we can now in theory look up
worktree ref stores for repositories other than `the_repository`. In
practice, the worktree code will need further changes to look up
arbitrary worktrees.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>worktree: expose interface to look up worktree by name</title>
<updated>2024-01-08T21:17:30Z</updated>
<author>
<name>Patrick Steinhardt</name>
<email>ps@pks.im</email>
</author>
<published>2024-01-08T10:05:43Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=b8a846b2e03610e6f550d364c75e514532ef7adf'/>
<id>urn:sha1:b8a846b2e03610e6f550d364c75e514532ef7adf</id>
<content type='text'>
Our worktree interfaces do not provide a way to look up a worktree by
its name. Expose `get_linked_worktree()` to allow for this usecase. As
callers are responsible for freeing this worktree, introduce a new
function `free_worktree()` that does so.

Signed-off-by: Patrick Steinhardt &lt;ps@pks.im&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
<entry>
<title>Merge branch 'rj/avoid-switching-to-already-used-branch'</title>
<updated>2023-03-19T22:03:11Z</updated>
<author>
<name>Junio C Hamano</name>
<email>gitster@pobox.com</email>
</author>
<published>2023-03-19T22:03:11Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=96a806f87a379fbc54b5cdb889518e9540d954c9'/>
<id>urn:sha1:96a806f87a379fbc54b5cdb889518e9540d954c9</id>
<content type='text'>
A few subcommands have been taught to stop users from working on a
branch that is being used in another worktree linked to the same
repository.

* rj/avoid-switching-to-already-used-branch:
  switch: reject if the branch is already checked out elsewhere (test)
  rebase: refuse to switch to a branch already checked out elsewhere (test)
  branch: fix die_if_checked_out() when ignore_current_worktree
  worktree: introduce is_shared_symref()
</content>
</entry>
<entry>
<title>worktree: introduce is_shared_symref()</title>
<updated>2023-02-25T21:05:23Z</updated>
<author>
<name>Rubén Justo</name>
<email>rjusto@gmail.com</email>
</author>
<published>2023-02-25T14:21:51Z</published>
<link rel='alternate' type='text/html' href='https://git.shady.money/git/commit/?id=662078caacd450f93faa72e0e7d8580c42621415'/>
<id>urn:sha1:662078caacd450f93faa72e0e7d8580c42621415</id>
<content type='text'>
Add a new function, is_shared_symref(), which contains the heart of
find_shared_symref().  Refactor find_shared_symref() to use the new
function is_shared_symref().

Soon, we will use is_shared_symref() to search for symref beyond
the first worktree that matches.

Signed-off-by: Rubén Justo &lt;rjusto@gmail.com&gt;
Signed-off-by: Junio C Hamano &lt;gitster@pobox.com&gt;
</content>
</entry>
</feed>
