From 2a69ff09d5654de31361365e3faf9f8495f03ed7 Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Thu, 17 Mar 2022 11:24:47 -0700 Subject: shallow: reset commit grafts when shallow is reset When reset_repository_shallow() is called, Git clears its cache of shallow information, so that if shallow information is re-requested, Git will read fresh data from disk instead of reusing its stale cached data. However, the cache of commit grafts is not likewise cleared, even though there are commit grafts created from shallow information. This means that if on-disk shallow information were to be updated and then a commit-graft-using codepath were run (for example, a revision walk), Git would be using stale commit graft information. This can be seen from the test in this patch, in which Git performs a revision walk (to check for changed submodules) after a fetch with --update-shallow. Therefore, clear the cache of commit grafts whenever reset_repository_shallow() is called. Signed-off-by: Jonathan Tan Signed-off-by: Junio C Hamano --- t/t5537-fetch-shallow.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't') diff --git a/t/t5537-fetch-shallow.sh b/t/t5537-fetch-shallow.sh index 11d5ea54a9..92948de7a0 100755 --- a/t/t5537-fetch-shallow.sh +++ b/t/t5537-fetch-shallow.sh @@ -161,6 +161,15 @@ test_expect_success 'fetch --update-shallow' ' ) ' +test_expect_success 'fetch --update-shallow into a repo with submodules' ' + git init a-submodule && + test_commit -C a-submodule foo && + git init repo-with-sub && + git -C repo-with-sub submodule add ../a-submodule a-submodule && + git -C repo-with-sub commit -m "added submodule" && + git -C repo-with-sub fetch --update-shallow ../shallow/.git refs/heads/*:refs/remotes/shallow/* +' + test_expect_success 'fetch --update-shallow (with fetch.writeCommitGraph)' ' ( cd shallow && -- cgit v1.2.3