Commit Diff


commit - 8ccaacf7a3bb2401fa09ec42bf513ed344c38e04
commit + d13d45484f4b12c1d19d0b2745abc08f3d92207d
blob - a79d7dd7434b10a9409ff691c9007f3e6df37b8b
blob + df5ab1f2e223cb83b7f61050e87c5b03755494ef
--- dulwich/client.py
+++ dulwich/client.py
@@ -2609,9 +2609,11 @@ class AbstractHttpGitClient(GitClient):
         )
         (
             negotiated_capabilities,
-            symrefs,
+            capa_symrefs,
             agent,
         ) = self._negotiate_upload_pack_capabilities(server_capabilities)
+        if not symrefs and capa_symrefs:
+            symrefs = capa_symrefs
         if depth is not None:
             wants = determine_wants(refs, depth=depth)
         else:
blob - 40cea9035ac05c79588d1d69091e0250bcde1db6
blob + 8c54a1ae7a8e69e18e2e8c04f9362ff99208800c
--- tests/compat/test_client.py
+++ tests/compat/test_client.py
@@ -226,10 +226,29 @@ class DulwichClientTestBase:
         c = self._client()
         with repo.Repo(os.path.join(self.gitroot, "dest")) as dest:
             result = c.fetch(self._build_path("/server_new.export"), dest)
+            self.assertEqual(
+                {b"HEAD": b"refs/heads/master"},
+                result.symrefs,
+            )
             for r in result.refs.items():
                 dest.refs.set_if_equals(r[0], None, r[1])
             self.assertDestEqualsSrc()
 
+    def test_fetch_pack_with_nondefault_symref(self):
+        c = self._client()
+        src = repo.Repo(os.path.join(self.gitroot, "server_new.export"))
+        src.refs.add_if_new(b"refs/heads/main", src.refs[b"refs/heads/master"])
+        src.refs.set_symbolic_ref(b"HEAD", b"refs/heads/main")
+        with repo.Repo(os.path.join(self.gitroot, "dest")) as dest:
+            result = c.fetch(self._build_path("/server_new.export"), dest)
+            self.assertEqual(
+                {b"HEAD": b"refs/heads/main"},
+                result.symrefs,
+            )
+            for r in result.refs.items():
+                dest.refs.set_if_equals(r[0], None, r[1])
+            self.assertDestEqualsSrc()
+
     def test_fetch_pack_depth(self):
         c = self._client()
         with repo.Repo(os.path.join(self.gitroot, "dest")) as dest: