From 064691e90c4cbf1c550cb65b41b91e6fa07c7c81 Mon Sep 17 00:00:00 2001 From: Kaushik Lingarkar Date: Tue, 4 Apr 2023 18:05:53 -0700 Subject: UploadPack: Fix NPE when traversing a tag chain Always parse RevTags including their body before getting their object to ensure that non-cached objects are handled correctly when traversing a tag chain. An NPE in UploadPack#addTagChain will occur on a depth=1 fetch of a branch containing a tag chain and the ref to one of the middle tags in the chain is deleted. Change-Id: Ifd8fe868869070b365df926fec5dcd8e64d4f521 Signed-off-by: Kaushik Lingarkar --- .../org/eclipse/jgit/transport/UploadPackTest.java | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 7131905850..2b05decb45 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -2538,6 +2538,75 @@ public class UploadPackTest { } } + @Test + public void testSingleBranchShallowCloneTagChainWithReflessTag() throws Exception { + RevCommit one = remote.commit().message("1").create(); + remote.update("master", one); + RevTag tag1 = remote.tag("t1", one); + remote.lightweightTag("t1", tag1); + RevTag tag2 = remote.tag("t2", tag1); + RevTag tag3 = remote.tag("t3", tag2); + remote.lightweightTag("t3", tag3); + + UploadPack uploadPack = new UploadPack(remote.getRepository()); + + ByteArrayOutputStream cli = new ByteArrayOutputStream(); + PacketLineOut clientWant = new PacketLineOut(cli); + clientWant.writeString("want " + one.name() + " include-tag"); + clientWant.writeString("deepen 1\n"); + clientWant.end(); + clientWant.writeString("done\n"); + + try (ByteArrayOutputStream serverResponse = new ByteArrayOutputStream()) { + + uploadPack.setPreUploadHook(new PreUploadHook() { + @Override + public void onBeginNegotiateRound(UploadPack up, + Collection wants, int cntOffered) + throws ServiceMayNotContinueException { + // Do nothing. + } + + @Override + public void onEndNegotiateRound(UploadPack up, + Collection wants, int cntCommon, + int cntNotFound, boolean ready) + throws ServiceMayNotContinueException { + // Do nothing. + } + + @Override + public void onSendPack(UploadPack up, + Collection wants, + Collection haves) + throws ServiceMayNotContinueException { + // collect pack data + serverResponse.reset(); + } + }); + uploadPack.upload(new ByteArrayInputStream(cli.toByteArray()), + serverResponse, System.err); + ByteArrayInputStream packReceived = new ByteArrayInputStream( + serverResponse.toByteArray()); + PackLock lock = null; + try (ObjectInserter ins = client.newObjectInserter()) { + PackParser parser = ins.newPackParser(packReceived); + parser.setAllowThin(true); + parser.setLockMessage("receive-tag-chain"); + ProgressMonitor mlc = NullProgressMonitor.INSTANCE; + lock = parser.parse(mlc, mlc); + ins.flush(); + } finally { + if (lock != null) { + lock.unlock(); + } + } + InMemoryRepository.MemObjDatabase objDb = client + .getObjectDatabase(); + assertTrue(objDb.has(one.toObjectId())); + } + } + @Test public void testSafeToClearRefsInFetchV0() throws Exception { server = -- cgit v1.2.3 From 61d4e31349719778bce67fc9ec707cbb0a98def6 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Wed, 12 Jan 2022 23:45:34 +0100 Subject: [bazel] Skip ConfigTest#testCommitTemplatePathInHomeDirecory Move this test to another class and skip it when running tests with bazel since the bazel test runner does not allow to create files in the home directory. FS#userHome retrieves the home directory on the first call and caches it for subsequent calls to avoid overhead in case path translation is required (currently on cygwin). This prevents that the test can mock the home directory using MockSystemReader like SshTestHarness does. Change-Id: I6a22f37f4a19eb4b4935509eae508a23e56db7aa --- org.eclipse.jgit.test/BUILD | 1 + .../eclipse/jgit/lib/CommitTemplateConfigTest.java | 60 ++++++++++++++++++++++ .../tst/org/eclipse/jgit/lib/ConfigTest.java | 25 +-------- 3 files changed, 62 insertions(+), 24 deletions(-) create mode 100644 org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java (limited to 'org.eclipse.jgit.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.test/BUILD b/org.eclipse.jgit.test/BUILD index c9b5d37265..9e787fee71 100644 --- a/org.eclipse.jgit.test/BUILD +++ b/org.eclipse.jgit.test/BUILD @@ -42,6 +42,7 @@ DATA = [ EXCLUDED = [ PKG + "api/SecurityManagerTest.java", PKG + "api/SecurityManagerMissingPermissionsTest.java", + PKG + "lib/CommitTemplateConfigTest.java", ] tests(tests = glob( diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java new file mode 100644 index 0000000000..6dbe30af2d --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2021 SAP SE and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +package org.eclipse.jgit.lib; + +import static org.junit.Assert.assertEquals; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.jgit.errors.ConfigInvalidException; +import org.eclipse.jgit.junit.JGitTestUtil; +import org.eclipse.jgit.storage.file.FileRepositoryBuilder; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; + +/* + * This test was moved from ConfigTest to allow skipping it when running the + * test using bazel which doesn't allow tests to create files in the home + * directory + */ +public class CommitTemplateConfigTest { + + @Rule + public TemporaryFolder tmp = new TemporaryFolder(); + + @Test + public void testCommitTemplatePathInHomeDirecory() + throws ConfigInvalidException, IOException { + Config config = new Config(null); + File tempFile = tmp.newFile("testCommitTemplate-"); + File workTree = tmp.newFolder("dummy-worktree"); + Repository repo = FileRepositoryBuilder.create(workTree); + String templateContent = "content of the template"; + JGitTestUtil.write(tempFile, templateContent); + // proper evaluation of the ~/ directory + String homeDir = System.getProperty("user.home"); + File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder", + ".tmp", new File(homeDir)); + tempFileInHomeDirectory.deleteOnExit(); + JGitTestUtil.write(tempFileInHomeDirectory, templateContent); + String expectedTemplatePath = tempFileInHomeDirectory.getPath() + .replace(homeDir, "~"); + config = ConfigTest + .parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); + String templatePath = config.get(CommitConfig.KEY) + .getCommitTemplatePath(); + assertEquals(expectedTemplatePath, templatePath); + assertEquals(templateContent, + config.get(CommitConfig.KEY).getCommitTemplateContent(repo)); + } +} diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java index fe3c1db502..1b03fb76cb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ConfigTest.java @@ -1176,7 +1176,7 @@ public class ConfigTest { assertEquals(exp, c.getLong("s", null, "a", 0L)); } - private static Config parse(String content) + static Config parse(String content) throws ConfigInvalidException { return parse(content, null); } @@ -1515,29 +1515,6 @@ public class ConfigTest { "utf-8", commitEncoding); } - @Test - public void testCommitTemplatePathInHomeDirecory() - throws ConfigInvalidException, IOException { - Config config = new Config(null); - File tempFile = tmp.newFile("testCommitTemplate-"); - String templateContent = "content of the template"; - JGitTestUtil.write(tempFile, templateContent); - // proper evaluation of the ~/ directory - String homeDir = System.getProperty("user.home"); - File tempFileInHomeDirectory = File.createTempFile("fileInHomeFolder", - ".tmp", new File(homeDir)); - tempFileInHomeDirectory.deleteOnExit(); - JGitTestUtil.write(tempFileInHomeDirectory, templateContent); - String expectedTemplatePath = tempFileInHomeDirectory.getPath() - .replace(homeDir, "~"); - config = parse("[commit]\n\ttemplate = " + expectedTemplatePath + "\n"); - String templatePath = config.get(CommitConfig.KEY) - .getCommitTemplatePath(); - assertEquals(expectedTemplatePath, templatePath); - assertEquals(templateContent, - config.get(CommitConfig.KEY).getCommitTemplateContent()); - } - @Test(expected = ConfigInvalidException.class) public void testCommitTemplateWithInvalidEncoding() throws ConfigInvalidException, IOException { -- cgit v1.2.3 From 2aaa5611366edb9f48ebaa15860dce03bcfe4c93 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 27 Apr 2023 01:00:44 +0200 Subject: Fix CommitTemplateConfigTest The cherry-picked 61d4e313 doesn't match 5.13 APIs which changed in newer versions. Change-Id: I61ed0242472ed822028d86d3038f956f6bd5735c --- .../tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'org.eclipse.jgit.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java index 6dbe30af2d..eaebd57e43 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/CommitTemplateConfigTest.java @@ -17,7 +17,6 @@ import java.io.IOException; import org.eclipse.jgit.errors.ConfigInvalidException; import org.eclipse.jgit.junit.JGitTestUtil; -import org.eclipse.jgit.storage.file.FileRepositoryBuilder; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -37,8 +36,6 @@ public class CommitTemplateConfigTest { throws ConfigInvalidException, IOException { Config config = new Config(null); File tempFile = tmp.newFile("testCommitTemplate-"); - File workTree = tmp.newFolder("dummy-worktree"); - Repository repo = FileRepositoryBuilder.create(workTree); String templateContent = "content of the template"; JGitTestUtil.write(tempFile, templateContent); // proper evaluation of the ~/ directory @@ -55,6 +52,6 @@ public class CommitTemplateConfigTest { .getCommitTemplatePath(); assertEquals(expectedTemplatePath, templatePath); assertEquals(templateContent, - config.get(CommitConfig.KEY).getCommitTemplateContent(repo)); + config.get(CommitConfig.KEY).getCommitTemplateContent()); } } -- cgit v1.2.3 From 2fd050c5674a08f1a5ccbe6b6cfc922ce6144c4a Mon Sep 17 00:00:00 2001 From: Jonathan Tan Date: Wed, 5 Apr 2023 13:44:59 -0700 Subject: GcConcurrentTest: @Ignore flaky testInterruptGc During my development of Id7721cc5b7ea650e77c2db47042715487983cae6, I have found this test to be flaky when run by CI. As a speculative fix, mark this test as @Ignore so it won't be run. Signed-off-by: Jonathan Tan Change-Id: Idfe04d7f1fb72a772d4c8d249ca86a9c2eec0b1a --- .../tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java | 2 ++ 1 file changed, 2 insertions(+) (limited to 'org.eclipse.jgit.test/tst/org/eclipse') diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java index d53d5eb4b8..da9c0df089 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcConcurrentTest.java @@ -43,6 +43,7 @@ import org.eclipse.jgit.revwalk.RevBlob; import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase; +import org.junit.Ignore; import org.junit.Test; public class GcConcurrentTest extends GcTestCase { @@ -197,6 +198,7 @@ public class GcConcurrentTest extends GcTestCase { assertNotNull(getSinglePack(repository).getBitmapIndex()); } + @Ignore @Test public void testInterruptGc() throws Exception { FileBasedConfig c = repo.getConfig(); -- cgit v1.2.3