Skip to content

Commit

Permalink
Minor improvements to JGitLightweightTagTest
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MarkEWaite committed Jan 4, 2025
1 parent 3a61ef9 commit 70ec3d7
Showing 1 changed file with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.io.FileMatchers.anExistingDirectory;

import hudson.EnvVars;
import hudson.model.TaskListener;
import hudson.plugins.git.GitObject;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.charset.StandardCharsets;
import java.util.List;
Expand Down Expand Up @@ -81,10 +81,9 @@ private void createFile(final String path, final String content) throws Exceptio
}
}

private void packRefs() throws IOException {
private void packRefs() throws Exception {
try (FileRepository repo = new FileRepository(repoRootGitDir)) {
org.eclipse.jgit.internal.storage.file.GC gc;
gc = new org.eclipse.jgit.internal.storage.file.GC(repo);
org.eclipse.jgit.internal.storage.file.GC gc = new org.eclipse.jgit.internal.storage.file.GC(repo);
gc.packRefs();
}
}
Expand All @@ -93,7 +92,6 @@ private void packRefs() throws IOException {
// But sometimes we want a lightweight a.k.a. non-annotated tag.
private void lightweightTag(String tagName) throws Exception {
try (FileRepository repo = new FileRepository(repoRootGitDir)) {
// Collides with implicit org.jenkinsci.plugins.gitclient.Git.
org.eclipse.jgit.api.Git jgitAPI = org.eclipse.jgit.api.Git.wrap(repo);
jgitAPI.tag().setName(tagName).setAnnotated(false).call();
}
Expand All @@ -112,6 +110,7 @@ public void testGetTags_packedRefs() throws Exception {
String annotatedTagName = "annotated_tag";
gitClient.tag(annotatedTagName, "Tag annotation");

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

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

0 comments on commit 70ec3d7

Please sign in to comment.