git: Fix unwrap in git2::Index::get_path (#44059)

Fixes ZED-1VR

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-12-03 11:56:16 +00:00
committed by GitHub
parent 0f67f08795
commit 4e8f6ddae9
+9 -1
View File
@@ -967,7 +967,15 @@ impl GitRepository for RealGitRepository {
index.read(false)?;
const STAGE_NORMAL: i32 = 0;
let oid = match index.get_path(path.as_std_path(), STAGE_NORMAL) {
let path = path.as_std_path();
// `RepoPath` contains a `RelPath` which normalizes `.` into an empty path
// `get_path` unwraps on empty paths though, so undo that normalization here
let path = if path.components().next().is_none() {
".".as_ref()
} else {
path
};
let oid = match index.get_path(path, STAGE_NORMAL) {
Some(entry) if entry.mode != GIT_MODE_SYMLINK => entry.id,
_ => return Ok(None),
};