Skip to content

fix: use absolute path for git repository discovery in worktrees#123

Merged
agavra merged 1 commit intoagavra:mainfrom
villads-valur:fix/worktree-detection
Jan 20, 2026
Merged

fix: use absolute path for git repository discovery in worktrees#123
agavra merged 1 commit intoagavra:mainfrom
villads-valur:fix/worktree-detection

Conversation

@villads-valur
Copy link
Copy Markdown
Contributor

Summary

  • Fixes incorrect diff display when running tuicr inside a git worktree
  • Files were appearing as "deleted" and diffs compared against the wrong commit

Root Cause

Repository::discover(".") with a relative path can cause git2 to resolve paths incorrectly in worktrees, where .git is a file pointing to the main repo's gitdir.

Solution

Use std::env::current_dir() to get the canonical path before calling Repository::discover(), ensuring git2 properly follows worktree gitdir references.

Fixes #119

When running inside a git worktree, Repository::discover(".") with a
relative path can cause git2 to resolve paths incorrectly. This resulted
in files appearing as deleted and incorrect diff comparisons.

Using the canonical current working directory ensures git2 properly
follows worktree gitdir references.

Fixes agavra#119
Copy link
Copy Markdown
Owner

@agavra agavra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, thanks for the fix @villads-valur

@agavra agavra merged commit ae090f1 into agavra:main Jan 20, 2026
4 checks passed
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.

Worktree shows incorrect diff - compares against initial commit instead of recent commits

2 participants