Fix submodules being incorrectly classified as linked worktrees#52507
Merged
Fix submodules being incorrectly classified as linked worktrees#52507
Conversation
For submodules, common_dir_abs_path equals repository_dir_abs_path (since submodules don't have a commondir file). The previous code passed this path to original_repo_path_from_common_dir unconditionally, which returned the .git/modules/<name> path as the original repo — causing linked_worktree_path() to return a false positive for submodules. Now we detect linked worktrees by checking whether common_dir differs from repository_dir (only true for actual linked worktrees that have a commondir file). For normal repos and submodules, original_repo is simply the work directory.
rtfeldman
commented
Mar 30, 2026
crates/project/src/git_store.rs
Outdated
| // directory from it. For normal repos and submodules, | ||
| // common_dir equals repository_dir, and the original repo is | ||
| // simply the work directory itself. | ||
| let is_linked_worktree = |
Contributor
Author
There was a problem hiding this comment.
Note to self: we now have a helper function called is_linked_worktree which we can use for this instead.
Contributor
There was a problem hiding this comment.
8c8a3f4 to
380c6d7
Compare
The concept is already documented on RepositorySnapshot::is_linked_worktree, so the 6-line explanatory comment and intermediate variable are no longer needed. Inline the condition directly.
380c6d7 to
050d0eb
Compare
Anthony-Eid
approved these changes
Mar 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
For submodules,
common_dir_abs_pathequalsrepository_dir_abs_path(since submodules don't have acommondirfile). The previous code passed this path tooriginal_repo_path_from_common_dirunconditionally, which returned the.git/modules/<name>path as theoriginal_repo_abs_path— causinglinked_worktree_path()to return a false positive for submodules.Now we detect linked worktrees by checking whether
common_dirdiffers fromrepository_dir(only true for actual linked worktrees that have acommondirfile). For normal repos and submodules,original_repo_abs_pathis simplywork_directory_abs_path.Also fixes the misleading doc comment on
common_dir_abs_pathinLocalRepositoryEntryand adds test assertions fororiginal_repo_abs_pathandlinked_worktree_path()on both worktrees and submodules.Closes AI-102
Release Notes: