Skip to content

Commit 2cd5054

Browse files
committed
fix: When removing all shallow commits from shallow file, delete it.
Previously it would leave an empty file, which will be ignored by the implementation but might be confusing to users.
1 parent f37a930 commit 2cd5054

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

gix/src/shallow.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ pub mod write {
3636
ShallowUpdate::Unshallow(id) => shallow_commits.retain(|oid| oid != id),
3737
}
3838
}
39+
if shallow_commits.is_empty() {
40+
std::fs::remove_file(file.resource_path())?;
41+
drop(file);
42+
return Ok(());
43+
}
3944

4045
if shallow_commits.is_empty() {
4146
if let Err(err) = std::fs::remove_file(file.resource_path()) {

gix/tests/clone/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ mod blocking_io {
7272
!repo.is_shallow(),
7373
"both methods agree - if there are no shallow commits, it shouldn't think the repo is shallow"
7474
);
75+
assert!(
76+
!repo.shallow_file().exists(),
77+
"when the repo is not shallow anymore, there is no need for a shallow file"
78+
);
7579
assert!(
7680
repo.head_id()?.ancestors().all()?.count() > shallow_commit_count,
7781
"there are more commits now as the history is complete"

0 commit comments

Comments
 (0)