Skip to content

Commit

Permalink
Merge pull request #1044 from jelmer/follow-ref-fix
Browse files Browse the repository at this point in the history
Catch SymrefLoop in set_if_equals
  • Loading branch information
jelmer authored Sep 16, 2022
2 parents 9051030 + fcae731 commit 9bb4312
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
0.20.47 UNRELEASED

* Fix handling of SymrefLoop in RefsContainer.__setitem__.
(Dominic Davis-Foster, Jelmer Vernooij)

0.20.46 2022-09-06

* Apply insteadOf to rsync-style location strings
Expand Down
2 changes: 1 addition & 1 deletion dulwich/refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ def set_if_equals(
try:
realnames, _ = self.follow(name)
realname = realnames[-1]
except (KeyError, IndexError):
except (KeyError, IndexError, SymrefLoop):
realname = name
filename = self.refpath(realname)

Expand Down
8 changes: 8 additions & 0 deletions dulwich/tests/test_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,14 @@ def test_follow(self):
)
self.assertRaises(SymrefLoop, self._refs.follow, b"refs/heads/loop")

def test_set_overwrite_loop(self):
self.assertRaises(SymrefLoop, self._refs.follow, b"refs/heads/loop")
self._refs[b'refs/heads/loop'] = (
b"42d06bd4b77fed026b154d16493e5deab78f02ec")
self.assertEqual(
([b'refs/heads/loop'], b'42d06bd4b77fed026b154d16493e5deab78f02ec'),
self._refs.follow(b"refs/heads/loop"))

def test_delitem(self):
RefsContainerTests.test_delitem(self)
ref_file = os.path.join(self._refs.path, b"refs", b"heads", b"master")
Expand Down

0 comments on commit 9bb4312

Please sign in to comment.