Skip to content

Commit f02b158

Browse files
authored
Minor improvements to JGitLightweightTagTest (jenkinsci#1236)
Prepare for JGit 7.2.0 where the `packRefs()` method will be publicly available instead of requiring a JGit internal API. Document that the packRefs() call is required in order to confirm that the previous bug in JGitAPIImpl is still fixed. I reverted the fix and confirmed that without the call to `packRefs()` the bug is not shown by the test. Assert that the set of tags has the correct size.
1 parent 3a61ef9 commit f02b158

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/test/java/org/jenkinsci/plugins/gitclient/JGitLightweightTagTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@
77
import static org.hamcrest.Matchers.greaterThan;
88
import static org.hamcrest.Matchers.hasItem;
99
import static org.hamcrest.Matchers.hasProperty;
10+
import static org.hamcrest.Matchers.hasSize;
1011
import static org.hamcrest.Matchers.is;
1112
import static org.hamcrest.io.FileMatchers.anExistingDirectory;
1213

1314
import hudson.EnvVars;
1415
import hudson.model.TaskListener;
1516
import hudson.plugins.git.GitObject;
1617
import java.io.File;
17-
import java.io.IOException;
1818
import java.io.PrintWriter;
1919
import java.nio.charset.StandardCharsets;
2020
import java.util.List;
@@ -81,10 +81,9 @@ private void createFile(final String path, final String content) throws Exceptio
8181
}
8282
}
8383

84-
private void packRefs() throws IOException {
84+
private void packRefs() throws Exception {
8585
try (FileRepository repo = new FileRepository(repoRootGitDir)) {
86-
org.eclipse.jgit.internal.storage.file.GC gc;
87-
gc = new org.eclipse.jgit.internal.storage.file.GC(repo);
86+
org.eclipse.jgit.internal.storage.file.GC gc = new org.eclipse.jgit.internal.storage.file.GC(repo);
8887
gc.packRefs();
8988
}
9089
}
@@ -93,7 +92,6 @@ private void packRefs() throws IOException {
9392
// But sometimes we want a lightweight a.k.a. non-annotated tag.
9493
private void lightweightTag(String tagName) throws Exception {
9594
try (FileRepository repo = new FileRepository(repoRootGitDir)) {
96-
// Collides with implicit org.jenkinsci.plugins.gitclient.Git.
9795
org.eclipse.jgit.api.Git jgitAPI = org.eclipse.jgit.api.Git.wrap(repo);
9896
jgitAPI.tag().setName(tagName).setAnnotated(false).call();
9997
}
@@ -112,6 +110,7 @@ public void testGetTags_packedRefs() throws Exception {
112110
String annotatedTagName = "annotated_tag";
113111
gitClient.tag(annotatedTagName, "Tag annotation");
114112

113+
// Must pack the tags and other refs in order to show the JGitAPIImpl bug
115114
packRefs();
116115

117116
Set<GitObject> tags = gitClient.getTags();
@@ -124,5 +123,6 @@ public void testGetTags_packedRefs() throws Exception {
124123
tags,
125124
hasItem(allOf(
126125
hasProperty("name", equalTo(annotatedTagName)), hasProperty("SHA1", equalTo(secondCommit)))));
126+
assertThat(tags, hasSize(2));
127127
}
128128
}

0 commit comments

Comments
 (0)