Skip to content

Commit ddd7630

Browse files
committed
Handle files not existing
1 parent da5bd29 commit ddd7630

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

asyncgit/src/sync/diff.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,25 +371,30 @@ pub fn get_diff(
371371
gix_repo
372372
.head_tree()?
373373
.lookup_entry_by_path(p)
374+
.map(|entry| {
375+
entry.map_or_else(
376+
|| ObjectId::null(gix::hash::Kind::Sha1),
377+
|entry| entry.object_id(),
378+
)
379+
})
380+
.unwrap_or(ObjectId::null(gix::hash::Kind::Sha1)),
374381
None,
375382
)
376383
} else {
377384
(
378-
gix_repo
379-
.index()?
380-
.entry_by_path(p.into())
381-
.expect("TODO")
382-
.id,
385+
gix_repo.index()?.entry_by_path(p.into()).map_or(
386+
ObjectId::null(gix::hash::Kind::Sha1),
387+
|entry| entry.id,
388+
),
383389
None,
384390
)
385391
};
386392
let (new_blob_id, new_root) = if stage {
387393
(
388-
gix_repo
389-
.index()?
390-
.entry_by_path(p.into())
391-
.expect("TODO")
392-
.id,
394+
gix_repo.index()?.entry_by_path(p.into()).map_or(
395+
ObjectId::null(gix::hash::Kind::Sha1),
396+
|entry| entry.id,
397+
),
393398
None,
394399
)
395400
} else {

0 commit comments

Comments
 (0)