Skip to content

Commit

Permalink
fix: When removing all shallow commits from shallow file, delete it.
Browse files Browse the repository at this point in the history
Previously it would leave an empty file, which will be ignored by the implementation
but might be confusing to users.
  • Loading branch information
Byron committed Apr 26, 2023
1 parent f37a930 commit 2cd5054
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gix/src/shallow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ pub mod write {
ShallowUpdate::Unshallow(id) => shallow_commits.retain(|oid| oid != id),
}
}
if shallow_commits.is_empty() {
std::fs::remove_file(file.resource_path())?;
drop(file);
return Ok(());
}

if shallow_commits.is_empty() {
if let Err(err) = std::fs::remove_file(file.resource_path()) {
Expand Down
4 changes: 4 additions & 0 deletions gix/tests/clone/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ mod blocking_io {
!repo.is_shallow(),
"both methods agree - if there are no shallow commits, it shouldn't think the repo is shallow"
);
assert!(
!repo.shallow_file().exists(),
"when the repo is not shallow anymore, there is no need for a shallow file"
);
assert!(
repo.head_id()?.ancestors().all()?.count() > shallow_commit_count,
"there are more commits now as the history is complete"
Expand Down

0 comments on commit 2cd5054

Please sign in to comment.