Skip to content

fix: RemoveRef removes empty parent directories - #2342

Open
VedantMadane wants to merge 3 commits into
go-git:mainfrom
VedantMadane:fix/issue-1822
Open

VedantMadane wants to merge 3 commits into
go-git:mainfrom
VedantMadane:fix/issue-1822

Conversation

@VedantMadane

Copy link
Copy Markdown

Summary

RemoveRef removes empty parent directories

Changes

  • RemoveRef cleans up empty parent directories under refs/

Fixes #1822

- RemoveRef cleans up empty parent directories under refs/

Fixes go-git#1822

Signed-off-by: Vedant Madane <[email protected]>

@pjbgf pjbgf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VedantMadane thanks for looking into this. Please note that this fix also removes refs/heads. Please fix that and add a test to confirm that is no longer the case - so that it aligns with upstream Git.

…rents

Upstream Git's try_remove_empty_parents spares refs/ and its immediate subdirectories (such as refs/heads, refs/tags, refs/remotes). Update removeEmptyRefParents to break when the parent directory is refs/ (or root), avoiding accidental removal of refs/heads when the last loose branch is deleted.

Add test coverage ensuring refs/heads is preserved when deleting the sole branch, nested empty parents are cleaned up, sibling branches keep parent dirs intact, and creating a conflicting ref succeeds after cleanup (fixes go-git#1822).

Signed-off-by: Vedant Madane <[email protected]>
@VedantMadane

Copy link
Copy Markdown
Author

@pjbgf Thanks for the review and catching that! I've updated
emoveEmptyRefParents to align with upstream Git's ry_remove_empty_parents behavior (sparing
efs/ and its immediate subdirectories such as
efs/heads,
efs/tags, and
efs/remotes).

Added test coverage in storage/filesystem/dotgit/dotgit_test.go covering:

  • Preservation of
    efs/heads and
    efs/ when deleting nested references (TestRemoveRefCleansEmptyParentDirs).
  • Preservation of
    efs/heads even when the deleted branch is the sole loose branch (TestRemoveRefPreservesRefsHeadsWhenOnlyRef).
  • Parent directory preservation when sibling references exist (TestRemoveRefPreservesNonEmptyParentDirs).
  • Resolution of the conflict from RemoveReference should clean up empty directories #1822 (TestRemoveRefAllowsCreatingConflictingRef).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

RemoveReference should clean up empty directories

2 participants