Skip to content

Commit

Permalink
Prevent removal of refs directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
jelmer committed Apr 1, 2021
1 parent df949eb commit 3720808
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
7 changes: 5 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
%(version)s %(date)s
0.20.22 UNRELEASED

%(version)s %(date)s
* Prevent removal of refs directory when the last ref is
deleted. (Jelmer Vernooij)

0.20.21 2021-03-20

* Add basic support for a GcsObjectStore that stores
pack files in gcs. (Jelmer Vernooij)
Expand Down
2 changes: 2 additions & 0 deletions dulwich/refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,8 @@ def remove_if_equals(
except ValueError:
break

if parent == b'refs':
break
parent_filename = self.refpath(parent)
try:
os.rmdir(parent_filename)
Expand Down
7 changes: 7 additions & 0 deletions dulwich/tests/test_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ def test_setitem(self):
b"42d06bd4b77fed026b154d16493e5deab78f02ec",
)

def test_delete_refs_container(self):
# We shouldn't delete the refs directory
self._refs[b'refs/heads/blah'] = b"42d06bd4b77fed026b154d16493e5deab78f02ec"
for ref in self._refs.allkeys():
del self._refs[ref]
self.assertTrue(os.path.exists(os.path.join(self._refs.path, b'refs')))

def test_setitem_packed(self):
with open(os.path.join(self._refs.path, b"packed-refs"), "w") as f:
f.write("# pack-refs with: peeled fully-peeled sorted \n")
Expand Down

0 comments on commit 3720808

Please sign in to comment.