diff options
author | kylezhao <kylezhao@tencent.com> | 2023-01-06 15:24:14 +0800 |
---|---|---|
committer | Ivan Frade <ifrade@google.com> | 2023-01-06 13:13:13 -0500 |
commit | 05e5e9907c6f85f8662ab9b78e5df90a62919f90 (patch) | |
tree | bf1dbcd14d872f39e596e9838bd2b69686a18f14 /org.eclipse.jgit.test | |
parent | 8ef58089a8fe46d10fdf040d3af7cc56f5b36f14 (diff) | |
download | jgit-05e5e9907c6f85f8662ab9b78e5df90a62919f90.tar.gz jgit-05e5e9907c6f85f8662ab9b78e5df90a62919f90.zip |
GC: disable writing commit-graph for shallow repos
In shallow repos, GC writes to the commit-graph that shallow commits
do not have parents. This won't be true after a "git fetch --unshallow"
(and before another GC).
Do not write the commit-graph from shallow clones of a repo. The
commit-graph must have the real metadata of commits and that is not
available in a shallow view of the repo.
Change-Id: Ic9f2358ddaa607c74f4dbf289c9bf2a2f0af9ce0
Signed-off-by: kylezhao <kylezhao@tencent.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java index 0a0d85c8aa..358e19ef67 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcCommitGraphTest.java @@ -59,6 +59,25 @@ public class GcCommitGraphTest extends GcTestCase { } @Test + public void testWriteShallowRepo() throws Exception { + StoredConfig config = repo.getConfig(); + config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, + ConfigConstants.CONFIG_COMMIT_GRAPH, true); + config.setBoolean(ConfigConstants.CONFIG_GC_SECTION, null, + ConfigConstants.CONFIG_KEY_WRITE_COMMIT_GRAPH, true); + + RevCommit tip = commitChain(2); + TestRepository.BranchBuilder bb = tr.branch("refs/heads/master"); + bb.update(tip); + repo.getObjectDatabase().setShallowCommits(Collections.singleton(tip)); + + gc.writeCommitGraph(Collections.singleton(tip)); + File graphFile = new File(repo.getObjectsDirectory(), + Constants.INFO_COMMIT_GRAPH); + assertFalse(graphFile.exists()); + } + + @Test public void testWriteWhenGc() throws Exception { StoredConfig config = repo.getConfig(); config.setBoolean(ConfigConstants.CONFIG_CORE_SECTION, null, |