git: Fix panic in git2 due to empty repo paths (#42304)

Fixes ZED-1VR

Release Notes:

- Fixed sporadic panic in git features
This commit is contained in:
Lukas Wirth
2025-11-10 09:27:51 +00:00
committed by GitHub
parent 359160c8b1
commit 0149de4b54
13 changed files with 90 additions and 84 deletions
+2 -2
View File
@@ -272,7 +272,7 @@ impl GitRepository for FakeGitRepository {
.ok()
.map(|content| String::from_utf8(content).unwrap())?;
let repo_path = RelPath::new(repo_path, PathStyle::local()).ok()?;
Some((repo_path.into(), (content, is_ignored)))
Some((RepoPath::from_rel_path(&repo_path), (content, is_ignored)))
})
.collect();
@@ -436,7 +436,7 @@ impl GitRepository for FakeGitRepository {
state
.blames
.get(&path)
.with_context(|| format!("failed to get blame for {:?}", path.0))
.with_context(|| format!("failed to get blame for {:?}", path))
.cloned()
})
}
+2 -1
View File
@@ -1792,7 +1792,8 @@ impl FakeFs {
for (path, content) in workdir_contents {
use util::{paths::PathStyle, rel_path::RelPath};
let repo_path: RepoPath = RelPath::new(path.strip_prefix(&workdir_path).unwrap(), PathStyle::local()).unwrap().into();
let repo_path = RelPath::new(path.strip_prefix(&workdir_path).unwrap(), PathStyle::local()).unwrap();
let repo_path = RepoPath::from_rel_path(&repo_path);
let status = statuses
.iter()
.find_map(|(p, status)| (*p == repo_path.as_unix_str()).then_some(status));