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 0a0d85c8a..358e19ef6 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 @@ -58,6 +58,25 @@ public void testWriteEmptyRepo() throws Exception { assertFalse(graphFile.exists()); } + @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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java index c9ecebe80..273d658a1 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/GC.java @@ -913,6 +913,9 @@ void writeCommitGraph(@NonNull Set wants) if (!repo.getConfig().get(CoreConfig.KEY).enableCommitGraph()) { return; } + if (repo.getObjectDatabase().getShallowCommits().size() > 0) { + return; + } checkCancelled(); if (wants.isEmpty()) { return;