Skip to content

fix: handle relative worktree linking files#2599

Draft
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
relative-workree-path
Draft

fix: handle relative worktree linking files#2599
Sebastian Thiel (Byron) wants to merge 1 commit into
mainfrom
relative-workree-path

Conversation

@Byron
Copy link
Copy Markdown
Member

Tasks

  • refackiew

Created by Codex on behalf of Byron. Byron will review before this is ready to merge.

Summary

Handle Git 2.48 relative linked-worktree metadata by resolving plain backlink files relative to their containing gitdir file, and use filesystem-aware realpath resolution for worktree backlinks so symlinked repository access keeps Git-compatible semantics.

Reported issue

Can you check that we can handle relative worktree paths, which are available as of Git 2.48?
For reference, here is the location of Git source code: /Users/byron/dev/github.com/git/git .

Git Reference

Git's worktree.c::write_worktree_linking_files() writes both sides of relative worktree links with relative_path(): the checkout .git file points to the private git dir, and .git/worktrees/<id>/gitdir points back to the checkout. Git's t/t2400-worktree-add.sh covers the resulting relative files for git worktree add --relative-paths.

Changes

  • Add a gix-discover helper for plain path files whose relative values are anchored at the containing file.
  • Use it for linked-worktree backlink resolution during discovery and Repository::worktrees() proxy base lookup.
  • Preserve symlink semantics by resolving backlink paths with filesystem-aware realpath behavior.
  • Add Git-2.48-gated regression tests for direct and symlinked relative linked worktrees.

Validation

  • cargo fmt --all --check
  • cargo test -p gix-discover --test discover
  • cargo test -p gix --test gix repository::worktree
  • git diff --check
  • codex review --commit 0a6aa7f870c6f4ad20f9af6932d4c78a738fbc2d

Git 2.48 can link worktrees with relative paths. In that layout the checkout .git file points at the private git dir relative to the checkout, while worktrees/<id>/gitdir points back to the checkout relative to the private git dir.

Discovery already handled the checkout-side gitdir file, but paths read from the private git dir were treated as-is. That made discovery from .git/worktrees/<id> and Repository::worktrees() proxy base resolution produce relative paths anchored to the process cwd instead of the gitdir file location.

Add a plain-path reader that resolves relative values against the containing file, use it for worktree backlinks, and resolve those backlinks with filesystem-aware realpath behavior so symlinked repository paths keep Git semantics. Add regressions that exercise Git-2.48-style relative linking files, including symlinked access coverage, while constructing the fixture in a way that also runs on CI images with older Git.

Git reference: /Users/byron/dev/github.com/git/git worktree.c:write_worktree_linking_files writes both relative links with `relative_path()`, and t/t2400-worktree-add.sh covers the resulting relative files.

Validation:
- cargo fmt --all --check
- cargo test -p gix-discover --test discover
- cargo test -p gix --test gix repository::worktree
- git diff --check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants