summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.test
diff options
context:
space:
mode:
authorSaša Živkov <sasa.zivkov@sap.com>2021-10-15 10:13:53 +0200
committerMatthias Sohn <matthias.sohn@sap.com>2021-10-15 22:29:28 +0200
commitd160e8a9354c1acdb6f60d743581e99cee520077 (patch)
tree24a5165cecf09853f5831fa97552c2aea582f75e /org.eclipse.jgit.test
parent5a7a5d5ae92ba23a8c3aabaf5f875ed2f6421ae6 (diff)
downloadjgit-d160e8a9354c1acdb6f60d743581e99cee520077.tar.gz
jgit-d160e8a9354c1acdb6f60d743581e99cee520077.zip
Fix missing peel-part in lsRefsV2 for loose annotated tags
We observed the following issue: $ git tag -a v1.0 -m v1.0 $ git push origin tag v1.0 $ git ls-remote origin v1.0^{} ... empty result ... On the server (Gerrit) side run git-gc to pack the refs: $ git gc Repeat the ls-remote from the client and the result is correct: $ git ls-remote origin v1.0^{} 7ad85c810de3ae922903d4bdd17c53cd627260ba refs/tags/v1.0^{} Unfortunately, the existing UploadPackTest didn't reveal this issue although it provided the test case needed to do so: testV2LsRefsPeel. This is because The UploadPackTest uses InMemoryRepository which internally uses Dfs* implementations. The issue is only reproducible when using the FileRepository. It is a non-trivial task to refactor the UploadPackTest to work against both InMemoryRepository and FileRepository and this change is not trying to do that. This change creates a new test: UploadPackLsRefsFileRepositoryTest and copies the necesssary code from the UploadPackTest. Change-Id: Icfc7d0ca63f1524bafe24c9626ce12ea72aa3718 Signed-off-by: Saša Živkov <sasa.zivkov@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r--org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackLsRefsFileRepositoryTest.java123
1 files changed, 123 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackLsRefsFileRepositoryTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackLsRefsFileRepositoryTest.java
new file mode 100644
index 0000000000..7d5fc61017
--- /dev/null
+++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackLsRefsFileRepositoryTest.java
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2021, Saša Živkov <sasa.zivkov@sap.com> 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.transport;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.util.Objects;
+import java.util.function.Consumer;
+
+import org.eclipse.jgit.internal.storage.file.FileRepository;
+import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
+import org.eclipse.jgit.junit.TestRepository;
+import org.eclipse.jgit.lib.Sets;
+import org.eclipse.jgit.revwalk.RevCommit;
+import org.eclipse.jgit.revwalk.RevTag;
+import org.junit.Before;
+import org.junit.Test;
+
+// TODO: refactor UploadPackTest to run against both DfsRepository and FileRepository
+public class UploadPackLsRefsFileRepositoryTest
+ extends LocalDiskRepositoryTestCase {
+
+ private FileRepository server;
+
+ private TestRepository<FileRepository> remote;
+
+ @Before
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ server = createWorkRepository();
+ remote = new TestRepository<>(server);
+ }
+
+ @Test
+ public void testV2LsRefsPeel() throws Exception {
+ RevCommit tip = remote.commit().message("message").create();
+ remote.update("master", tip);
+ server.updateRef("HEAD").link("refs/heads/master");
+ RevTag tag = remote.tag("tag", tip);
+ remote.update("refs/tags/tag", tag);
+
+ ByteArrayInputStream recvStream = uploadPackV2("command=ls-refs\n",
+ PacketLineIn.delimiter(), "peel", PacketLineIn.end());
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ assertThat(pckIn.readString(),
+ is(tip.toObjectId().getName() + " HEAD"));
+ assertThat(pckIn.readString(),
+ is(tip.toObjectId().getName() + " refs/heads/master"));
+ assertThat(pckIn.readString(), is(tag.toObjectId().getName()
+ + " refs/tags/tag peeled:" + tip.toObjectId().getName()));
+ assertTrue(PacketLineIn.isEnd(pckIn.readString()));
+ }
+
+ private ByteArrayInputStream uploadPackV2(String... inputLines)
+ throws Exception {
+ return uploadPackV2(null, inputLines);
+ }
+
+ private ByteArrayInputStream uploadPackV2(
+ Consumer<UploadPack> postConstructionSetup, String... inputLines)
+ throws Exception {
+ ByteArrayInputStream recvStream = uploadPackV2Setup(
+ postConstructionSetup, inputLines);
+ PacketLineIn pckIn = new PacketLineIn(recvStream);
+
+ // drain capabilities
+ while (!PacketLineIn.isEnd(pckIn.readString())) {
+ // do nothing
+ }
+ return recvStream;
+ }
+
+ private ByteArrayInputStream uploadPackV2Setup(
+ Consumer<UploadPack> postConstructionSetup, String... inputLines)
+ throws Exception {
+
+ ByteArrayInputStream send = linesAsInputStream(inputLines);
+
+ server.getConfig().setString("protocol", null, "version", "2");
+ UploadPack up = new UploadPack(server);
+ if (postConstructionSetup != null) {
+ postConstructionSetup.accept(up);
+ }
+ up.setExtraParameters(Sets.of("version=2"));
+
+ ByteArrayOutputStream recv = new ByteArrayOutputStream();
+ up.upload(send, recv, null);
+
+ return new ByteArrayInputStream(recv.toByteArray());
+ }
+
+ private static ByteArrayInputStream linesAsInputStream(String... inputLines)
+ throws IOException {
+ try (ByteArrayOutputStream send = new ByteArrayOutputStream()) {
+ PacketLineOut pckOut = new PacketLineOut(send);
+ for (String line : inputLines) {
+ Objects.requireNonNull(line);
+ if (PacketLineIn.isEnd(line)) {
+ pckOut.end();
+ } else if (PacketLineIn.isDelimiter(line)) {
+ pckOut.writeDelim();
+ } else {
+ pckOut.writeString(line);
+ }
+ }
+ return new ByteArrayInputStream(send.toByteArray());
+ }
+ }
+}