git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 0/4] Link worktrees with relative paths

From
Caleb White <cdwhite3@pm.me>
Date
Oct 6, 2024, 04:59 UTC
Message-ID
<20241006045847.159937-1-cdwhite3@pm.me>
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
Next: Caleb White
Message 1 of 23 in “Link worktrees with relative paths”
  1. 0/4 Link worktrees with relative pathsCaleb White, Oct 6, 2024
  2. 1/4 worktree: refactor infer_backlink() to use *strbufCaleb White, Oct 6, 2024
  3. 2/4 worktree: link worktrees with relative pathsCaleb White, Oct 6, 2024
  4. 3/4 worktree: sync worktree paths after gitdir moveCaleb White, Oct 6, 2024
  5. 4/4 worktree: prevent null pointer dereferenceCaleb White, Oct 6, 2024
  6. Eric SunshineOct 6, 2024
  7. Caleb WhiteOct 6, 2024
  8. Eric SunshineOct 6, 2024
  9. Eric SunshineOct 6, 2024
  10. Eric SunshineOct 6, 2024
  11. Caleb WhiteOct 6, 2024
  12. Eric SunshineOct 6, 2024
  13. Caleb WhiteOct 6, 2024
  14. Eric SunshineOct 6, 2024
  15. Caleb WhiteOct 6, 2024
  16. Eric SunshineOct 6, 2024
  17. Caleb WhiteOct 6, 2024
  18. Eric SunshineOct 6, 2024
  19. Kristoffer HaugsbakkOct 6, 2024
  20. Caleb WhiteOct 6, 2024
  21. Caleb WhiteOct 6, 2024
  22. Eric SunshineOct 6, 2024
  23. Caleb WhiteOct 6, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.