git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Caleb White <cdwhite3@pm.me>
To: git@vger.kernel.org
Cc: Caleb White <cdwhite3@pm.me>
Subject: [PATCH 0/4] Link worktrees with relative paths
Date: Sun, 06 Oct 2024 04:59:02 +0000	[thread overview]
Message-ID: <20241006045847.159937-1-cdwhite3@pm.me> (raw)

[-- Attachment #1: Type: text/plain, Size: 2305 bytes --]

Hello,

This patch series modifies Git's handling of worktree linking to use
relative paths instead of absolute paths. The motivation behind this
change is to enhance the robustness of worktree links when the main
repository is moved, or when used in environments like containerized
development where absolute paths differ across systems.

Currently, Git stores absolute paths to both the main repository and
the linked worktrees. This causes issues when the repository is moved
because the hardcoded paths become invalid, leading to broken worktree
links. Developers are then required to manually repair the links by
running `git worktree repair`, which can be cumbersome.

By switching to relative paths for worktrees, this patch improves the
resilience of worktree links. For self-contained repositories (e.g.,
bare repositories with worktrees), the links will continue to function
properly when the repository is moved or mapped inside a containerized
environment. While relativ
e paths do not completely eliminate the need
for repairs (as links external to the repository can still break), the
likelihood is reduced, and Git continues to provide mechanisms to repair
broken links when needed.

I have included tests to verify that:
- worktree links are created with relative paths.
- moving the repository does not break worktree links.

Note that absolute paths are still supported, and the code handles both
types of paths. There should be no breaking changes introduced with this
patch. I considered adding a configuration option
(e.g., `worktree.useRelativePaths`) to control path type, but decided to
keep it simple. However, if there is interest, I can add this feature.

This series is based on top of 111e864d69.

Thanks!

Caleb

Caleb White (4):
  worktree: refactor infer_backlink() to use *strbuf
  worktree: link worktrees with relative paths
  worktree: sync worktree paths after gitdir move
  worktree: prevent null pointer dereference


 builtin/worktree.c           |  17 +--
 setup.c                      |   2 +-
 t/t2408-worktree-relative.sh |  39 ++++++
 worktree.c                   | 235 +++++++++++++++++++++++++++--------
 worktree.h                   |  10 ++
 5 files changed, 240 insertions(+), 63 deletions(-)
 create mode 100755 t/t2408-worktree-relative.sh

-- 
2.46.2


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 509 bytes --]

             reply	other threads:[~2024-10-06  4:59 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-06  4:59 Caleb White [this message]
2024-10-06  4:59 ` [PATCH 1/4] worktree: refactor infer_backlink() to use *strbuf Caleb White
2024-10-06  4:59 ` [PATCH 2/4] worktree: link worktrees with relative paths Caleb White
2024-10-06  4:59 ` [PATCH 3/4] worktree: sync worktree paths after gitdir move Caleb White
2024-10-06  4:59 ` [PATCH 4/4] worktree: prevent null pointer dereference Caleb White
2024-10-06  5:04 ` [PATCH 0/4] Link worktrees with relative paths Eric Sunshine
2024-10-06  5:11   ` Caleb White
2024-10-06  5:14     ` Eric Sunshine
2024-10-06  5:16       ` Eric Sunshine
     [not found]         ` <TEfKiit-RYyr0ZuiQszaKaM64iSonfaQwWRqExOgXyPR1tVWyAzR3kVKmCd3aREZwDGuS5VXcHjCvneY-gCg2OuZyv2N2EkfARlZu4AVSsU=@pm.me>
     [not found]           ` <CAPig+cTE0gaD=7dwSqY4S+7AqRoU9yOrS4sdBoybj0Pfyk9vxA@mail.gmail.com>
2024-10-06  5:41             ` Caleb White
2024-10-06  5:50               ` Eric Sunshine
2024-10-06  6:05                 ` Caleb White
2024-10-06  6:16                   ` Eric Sunshine
2024-10-06  6:23                     ` Caleb White
2024-10-06  7:45                       ` Eric Sunshine
2024-10-06  9:00                         ` Kristoffer Haugsbakk
2024-10-06 22:10                           ` Caleb White
2024-10-06 22:08                         ` Caleb White
2024-10-06 22:24                           ` Eric Sunshine
2024-10-06 22:32                             ` Caleb White
2024-10-06  5:11   ` Eric Sunshine
2024-10-06 22:01     ` Caleb White
2024-10-06 22:19       ` Eric Sunshine

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

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

  git send-email \
    --in-reply-to=20241006045847.159937-1-cdwhite3@pm.me \
    --to=cdwhite3@pm.me \
    --cc=git@vger.kernel.org \
    /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.
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 NNTP newsgroup(s).