Skip to content

Fix submodules being incorrectly classified as linked worktrees#52507

Merged
rtfeldman merged 2 commits intomainfrom
AI-102/submodule-worktree-detection
Mar 31, 2026
Merged

Fix submodules being incorrectly classified as linked worktrees#52507
rtfeldman merged 2 commits intomainfrom
AI-102/submodule-worktree-detection

Conversation

@rtfeldman
Copy link
Copy Markdown
Contributor

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_abs_path — 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_abs_path is simply work_directory_abs_path.

Also fixes the misleading doc comment on common_dir_abs_path in LocalRepositoryEntry and adds test assertions for original_repo_abs_path and linked_worktree_path() on both worktrees and submodules.

Closes AI-102

Release Notes:

  • Fixed git submodules being incorrectly classified as linked worktrees, which could cause issues with worktree-related operations.

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 rtfeldman self-assigned this Mar 26, 2026
@cla-bot cla-bot bot added the cla-signed The user has signed the Contributor License Agreement label Mar 26, 2026
@zed-community-bot zed-community-bot bot added the staff Pull requests authored by a current member of Zed staff label Mar 26, 2026
// 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 =
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Note to self: we now have a helper function called is_linked_worktree which we can use for this instead.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rtfeldman rtfeldman force-pushed the AI-102/submodule-worktree-detection branch 3 times, most recently from 8c8a3f4 to 380c6d7 Compare March 31, 2026 16:03
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.
@rtfeldman rtfeldman force-pushed the AI-102/submodule-worktree-detection branch from 380c6d7 to 050d0eb Compare March 31, 2026 16:07
@Anthony-Eid Anthony-Eid marked this pull request as ready for review March 31, 2026 16:12
@zed-codeowner-coordinator zed-codeowner-coordinator bot requested review from a team, cameron1024, cole-miller, kubkon and reflectronic and removed request for a team March 31, 2026 16:12
@rtfeldman rtfeldman merged commit 7cf26f4 into main Mar 31, 2026
31 checks passed
@rtfeldman rtfeldman deleted the AI-102/submodule-worktree-detection branch March 31, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed The user has signed the Contributor License Agreement staff Pull requests authored by a current member of Zed staff

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants