From 4e7149282247730388a9625174262c1aeb50c573 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Thu, 28 Nov 2024 17:10:58 +0000 Subject: [PATCH 1/2] add a compat test case which verifies that shallow clones can be deepened This test shows that deepening shallow clones works across all Git protocol versions. The trick to make this work is to pass depth=DEPTH_INFINITE Related to issue #1399 --- tests/compat/test_client.py | 45 +++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/compat/test_client.py b/tests/compat/test_client.py index f8416df02..9dc7c0a5c 100644 --- a/tests/compat/test_client.py +++ b/tests/compat/test_client.py @@ -40,6 +40,8 @@ from dulwich import client, file, index, objects, protocol, repo from dulwich.porcelain import tag_create +from dulwich.refs import _import_remote_refs +from dulwich.protocol import DEPTH_INFINITE from .. import SkipTest, expectedFailure from .utils import ( @@ -155,6 +157,49 @@ def test_send_without_report_status(self) -> None: ) self.assertDestEqualsSrc() + def test_fetch_into_shallow_clone(self) -> None: + c = self._client() + server_new_path = os.path.join(self.gitroot, "server_new.export") + run_git_or_fail(["config", "http.uploadpack", "true"], cwd=server_new_path) + run_git_or_fail(["config", "http.receivepack", "true"], cwd=server_new_path) + remote_path = self._build_path("/server_new.export") + with repo.Repo(self.dest) as local: + result = c.fetch(remote_path, local, depth=1) + self.assertEqual( + local.get_shallow(), + { + b"35e0b59e187dd72a0af294aedffc213eaa4d03ff", + b"514dc6d3fbfe77361bcaef320c4d21b72bc10be9", + }, + ) + for r in result.refs.items(): + local.refs.set_if_equals(r[0], None, r[1]) + with repo.Repo(os.path.join(self.gitroot, "server_new.export")) as src: + tree_id = src[src.head()].tree + for filename, contents in [ + ("bar", "bar contents"), + ("zop", "zop contents"), + ]: + tree_id = self._add_file(src, tree_id, filename, contents) + commit_id = src.do_commit( + message=b"add " + filename.encode("utf-8"), + committer=b"Joe Example ", + tree=tree_id, + ) + with repo.Repo(self.dest) as local: + result = c.fetch(remote_path, local, depth=DEPTH_INFINITE) + _import_remote_refs( + local.refs, + "origin", + result.refs, + f"fetch: from {remote_path}".encode('ascii') + ) + self.assertEqual(local.get_shallow(), set()) + with repo.Repo(self.dest) as local: + tree = local[b"HEAD"].tree + tree = local[b"refs/remotes/origin/master"].tree + local.reset_index(tree=tree) + def make_dummy_commit(self, dest): b = objects.Blob.from_string(b"hi") dest.object_store.add_object(b) From 574f6a0f5d2e5e269d2897e18006b34c2e50de63 Mon Sep 17 00:00:00 2001 From: Stefan Sperling Date: Thu, 28 Nov 2024 17:10:58 +0000 Subject: [PATCH 2/2] appease ruff --- tests/compat/test_client.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/compat/test_client.py b/tests/compat/test_client.py index 9dc7c0a5c..30ce475c4 100644 --- a/tests/compat/test_client.py +++ b/tests/compat/test_client.py @@ -40,8 +40,8 @@ from dulwich import client, file, index, objects, protocol, repo from dulwich.porcelain import tag_create -from dulwich.refs import _import_remote_refs from dulwich.protocol import DEPTH_INFINITE +from dulwich.refs import _import_remote_refs from .. import SkipTest, expectedFailure from .utils import ( @@ -181,7 +181,7 @@ def test_fetch_into_shallow_clone(self) -> None: ("zop", "zop contents"), ]: tree_id = self._add_file(src, tree_id, filename, contents) - commit_id = src.do_commit( + src.do_commit( message=b"add " + filename.encode("utf-8"), committer=b"Joe Example ", tree=tree_id, @@ -192,7 +192,7 @@ def test_fetch_into_shallow_clone(self) -> None: local.refs, "origin", result.refs, - f"fetch: from {remote_path}".encode('ascii') + f"fetch: from {remote_path}".encode("ascii"), ) self.assertEqual(local.get_shallow(), set()) with repo.Repo(self.dest) as local: