zed-industries / zed

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
https://zed.dev
Other
47.96k stars 2.83k forks source link

Git diff and blame do not work in git submodule #13570

Open phkorn opened 3 months ago

phkorn commented 3 months ago

Check for existing issues

Describe the bug / provide steps to reproduce it

Do the following

mkdir gitsubmoduletest
cd gitsubmoduletest/
git init
git submodule add https://github.com/rust-unofficial/awesome-rust
cd awesome-rust/
zed .

When editing any file, no blame or git_diff indicators appear.

Environment

Zed: v0.141.2 (Zed) OS: macOS 14.5.0 Memory: 16 GiB Architecture: aarch64

If applicable, add mockups / screenshots to help explain present your vision of the feature

No response

If applicable, attach your ~/Library/Logs/Zed/Zed.log file to this issue.

Zed.log


notpeter commented 3 months ago

I am able to reproduce this following your instructions.

Git blame works on submodules if the workspace includes the parent. Git blame does not work on submodules if you open that as the root of your workspace.

Thanks for reporting.

phkorn commented 1 month ago

I took a look at the code and the problem is the following:

The ancestor directory, which is not in the worktree, gets added to the git_repositories as ProjectEntryId(0) due to work_dir_path being set to "". When it scans the current worktree and finds the .git folder it gets also treated as ProjectEntryId(0) since again the work_dir_path is "". CodePath: https://github.com/zed-industries/zed/blob/c1872e9cb09c72c9378908a0f8b33fe2c4fc3e07/crates/worktree/src/worktree.rs#L2852

Scanning ancestor git folders of the worktree and treating them as being part of the worktree is the culprit here.