Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>6.2138.v03274d462c13</version>
<version>6.2152.ve00a_731c3ce9</version>
<relativePath />
</parent>

Expand Down Expand Up @@ -47,6 +47,7 @@
<spotbugs.threshold>Low</spotbugs.threshold>
<spotless.check.skip>false</spotless.check.skip>
<ban-junit4-imports.skip>false</ban-junit4-imports.skip>
<ban-deprecated-stapler.skip>true</ban-deprecated-stapler.skip>
</properties>

<dependencyManagement>
Expand Down
20 changes: 12 additions & 8 deletions src/test/java/hudson/plugins/git/GitExceptionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,12 @@ void initCliImplThrowsGitException() throws Exception {
.using("git")
.getClient();
assertNotNull(defaultClient);
assertThrows(GitException.class, () -> defaultClient
.init_()
.workspace(badDirectory.getAbsolutePath())
.execute());
assertThrows(
GitException.class,
() -> defaultClient
.init_()
.workspace(badDirectory.getAbsolutePath())
.execute());
}

@Test
Expand All @@ -81,10 +83,12 @@ void initJGitImplThrowsGitException() throws Exception {
.using("jgit")
.getClient();
assertNotNull(defaultClient);
JGitInternalException e = assertThrows(JGitInternalException.class, () -> defaultClient
.init_()
.workspace(badDirectory.getAbsolutePath())
.execute());
JGitInternalException e = assertThrows(
JGitInternalException.class,
() -> defaultClient
.init_()
.workspace(badDirectory.getAbsolutePath())
.execute());
assertThat(e.getCause(), isA(IOException.class));
}

Expand Down
54 changes: 31 additions & 23 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -603,12 +603,14 @@ void testPushTags() throws Exception {
assertEquals(commit2, testGitClient.revParse("tag1"), "tag1 points to wrong commit");
if (testGitClient instanceof CliGitAPIImpl) {
// Modern CLI git should throw exception pushing a change to existing tag
Exception exception = assertThrows(GitException.class, () -> testGitClient
.push()
.ref(defaultBranchName)
.to(new URIish(bare.getGitFileDir().getAbsolutePath()))
.tags(true)
.execute());
Exception exception = assertThrows(
GitException.class,
() -> testGitClient
.push()
.ref(defaultBranchName)
.to(new URIish(bare.getGitFileDir().getAbsolutePath()))
.tags(true)
.execute());
assertThat(exception.getMessage(), containsString("already exists"));
} else {
testGitClient
Expand All @@ -621,13 +623,15 @@ void testPushTags() throws Exception {

if (testGitClient instanceof CliGitAPIImpl) {
/* CliGit throws exception updating existing tag */
Exception exception = assertThrows(GitException.class, () -> testGitClient
.push()
.ref(defaultBranchName)
.to(new URIish(bare.getGitFileDir().getAbsolutePath()))
.tags(true)
.force(false)
.execute());
Exception exception = assertThrows(
GitException.class,
() -> testGitClient
.push()
.ref(defaultBranchName)
.to(new URIish(bare.getGitFileDir().getAbsolutePath()))
.tags(true)
.force(false)
.execute());
assertThat(exception.getMessage(), containsString("already exists"));
} else {
/* JGit does not throw exception updating existing tag - ugh */
Expand Down Expand Up @@ -1062,11 +1066,13 @@ void testMergeStrategyCorrectFail() throws Exception {
testGitClient.add("file");
testGitClient.commit("commit2");

assertThrows(GitException.class, () -> testGitClient
.merge()
.setStrategy(MergeCommand.Strategy.RESOLVE)
.setRevisionToMerge(testGitClient.getHeadRev(testGitDir.getAbsolutePath(), "branch1"))
.execute());
assertThrows(
GitException.class,
() -> testGitClient
.merge()
.setStrategy(MergeCommand.Strategy.RESOLVE)
.setRevisionToMerge(testGitClient.getHeadRev(testGitDir.getAbsolutePath(), "branch1"))
.execute());
}

@Issue("JENKINS-12402")
Expand Down Expand Up @@ -1153,11 +1159,13 @@ void testMergeFastForwardModeFFOnly() throws Exception {

// The second merge calls for fast-forward only (FF_ONLY), but a merge commit is required, hence it is expected
// to fail
assertThrows(GitException.class, () -> testGitClient
.merge()
.setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.FF_ONLY)
.setRevisionToMerge(testGitClient.getHeadRev(testGitDir.getAbsolutePath(), "branch2"))
.execute());
assertThrows(
GitException.class,
() -> testGitClient
.merge()
.setGitPluginFastForwardMode(MergeCommand.GitPluginFastForwardMode.FF_ONLY)
.setRevisionToMerge(testGitClient.getHeadRev(testGitDir.getAbsolutePath(), "branch2"))
.execute());
assertEquals(
workspace.head(),
branch1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,11 @@ void test_checkout_interrupted() throws Exception {
/* Configure next checkout to fail with an exception */
CliGitAPIImpl cli = workspace.cgit();
cli.interruptNextCheckoutWithMessage(exceptionMsg);
Exception exception = assertThrows(InterruptedException.class, () -> cli.checkout()
.ref("6b7bbcb8f0e51668ddba349b683fb06b4bd9d0ea")
.execute());
Exception exception = assertThrows(
InterruptedException.class,
() -> cli.checkout()
.ref("6b7bbcb8f0e51668ddba349b683fb06b4bd9d0ea")
.execute());
assertThat(exception.getMessage(), is(exceptionMsg)); // Except exact exception message returned
assertThat("Lock file removed by checkout", lockFile, is(not(aReadableFile())));
}
Expand All @@ -139,9 +141,11 @@ void test_checkout_interrupted_with_existing_lock() throws Exception {
/* Configure next checkout to fail with an exception */
CliGitAPIImpl cli = workspace.cgit();
cli.interruptNextCheckoutWithMessage(exceptionMsg);
Exception exception = assertThrows(InterruptedException.class, () -> cli.checkout()
.ref("6b7bbcb8f0e51668ddba349b683fb06b4bd9d0ea")
.execute());
Exception exception = assertThrows(
InterruptedException.class,
() -> cli.checkout()
.ref("6b7bbcb8f0e51668ddba349b683fb06b4bd9d0ea")
.execute());
assertThat(exception.getMessage(), containsString(exceptionMsg));
assertThat("Lock file removed by checkout", lockFile, is(aReadableFile()));
}
Expand Down
62 changes: 36 additions & 26 deletions src/test/java/org/jenkinsci/plugins/gitclient/GitClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -624,11 +624,13 @@ void testInitFailureWindows() throws Exception {
.getClient();
Class<? extends Exception> expectedExceptionClass =
gitImplName.equals("git") ? GitException.class : JGitInternalException.class;
assertThrows(expectedExceptionClass, () -> badGitClient
.init_()
.bare(random.nextBoolean())
.workspace(badDirName)
.execute());
assertThrows(
expectedExceptionClass,
() -> badGitClient
.init_()
.bare(random.nextBoolean())
.workspace(badDirName)
.execute());
}

@Test
Expand All @@ -644,11 +646,13 @@ void testInitFailureNotWindowsNotSuperUser() throws Exception {
.getClient();
Class<? extends Exception> expectedExceptionClass =
gitImplName.equals("git") ? GitException.class : JGitInternalException.class;
assertThrows(expectedExceptionClass, () -> badGitClient
.init_()
.bare(random.nextBoolean())
.workspace(badDirName)
.execute());
assertThrows(
expectedExceptionClass,
() -> badGitClient
.init_()
.bare(random.nextBoolean())
.workspace(badDirName)
.execute());
}

@Test
Expand Down Expand Up @@ -1734,12 +1738,14 @@ void testCheckoutWithJGitLFS() throws Exception {
"Skipping testCheckoutWithJGitLFS for CLI git exception");
String branch = "tests/largeFileSupport";
String remote = fetchLFSTestRepo(branch);
assertThrows(org.eclipse.jgit.api.errors.JGitInternalException.class, () -> gitClient
.checkout()
.branch(branch)
.ref(remote + "/" + branch)
.lfsRemote(remote)
.execute());
assertThrows(
org.eclipse.jgit.api.errors.JGitInternalException.class,
() -> gitClient
.checkout()
.branch(branch)
.ref(remote + "/" + branch)
.lfsRemote(remote)
.execute());
}

// If LFS installed and not enabled, throw an exception
Expand All @@ -1750,11 +1756,13 @@ void testCLICheckoutWithoutLFSWhenLFSAvailable() throws Exception {
assumeFalse(!gitImplName.equals("git") || !CLI_GIT_HAS_GIT_LFS, "Test requires CLI git with LFS enabled");
String branch = "tests/largeFileSupport";
String remote = fetchLFSTestRepo(branch);
assertThrows(GitException.class, () -> gitClient
.checkout()
.branch(branch)
.ref(remote + "/" + branch)
.execute());
assertThrows(
GitException.class,
() -> gitClient
.checkout()
.branch(branch)
.ref(remote + "/" + branch)
.execute());
}

// If LFS installed and not enabled, throw an exception if branch includes LFS reference
Expand All @@ -1765,11 +1773,13 @@ void testJGitCheckoutWithoutLFSWhenLFSAvailable() throws Exception {
assumeFalse(!gitImplName.startsWith("jgit") || !CLI_GIT_HAS_GIT_LFS, "Test requires CLI git with LFS enabled");
String branch = "tests/largeFileSupport";
String remote = fetchLFSTestRepo(branch);
assertThrows(org.eclipse.jgit.api.errors.JGitInternalException.class, () -> gitClient
.checkout()
.branch(branch)
.ref(remote + "/" + branch)
.execute());
assertThrows(
org.eclipse.jgit.api.errors.JGitInternalException.class,
() -> gitClient
.checkout()
.branch(branch)
.ref(remote + "/" + branch)
.execute());
}

// If LFS not installed and not enabled, checkout content without download
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,9 @@ void testConflictOnMerge() throws Exception {
git.revList(defaultBranchName).contains(commit2Branch),
"branch commit 2 not on default branch after merge");
assertTrue(readmeOne.exists(), "README 1 missing in working directory");
GitException e = assertThrows(GitException.class, () -> mergeCmd.setRevisionToMerge(commitConflict)
.execute());
GitException e = assertThrows(
GitException.class,
() -> mergeCmd.setRevisionToMerge(commitConflict).execute());
assertThat(e.getMessage(), containsString(commitConflict.getName()));
}

Expand All @@ -424,8 +425,9 @@ void testConflictNoCommitOnMerge() throws Exception {
git.revList(defaultBranchName).contains(commit2Branch),
"branch commit 2 on default branch after merge without commit");
assertTrue(readmeOne.exists(), "README 1 missing in working directory");
GitException e = assertThrows(GitException.class, () -> mergeCmd.setRevisionToMerge(commitConflict)
.execute());
GitException e = assertThrows(
GitException.class,
() -> mergeCmd.setRevisionToMerge(commitConflict).execute());
assertThat(e.getMessage(), containsString(commitConflict.getName()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@ class PushSimpleTest extends PushTest {
@Test
void pushNonFastForwardThrows() throws Exception {
checkoutOldBranchAndCommitFile(); // Old branch can't be pushed without force()
assertThrows(GitException.class, () -> workingGitClient
.push()
.to(bareURI)
.ref(refSpec)
.timeout(1)
.execute());
assertThrows(
GitException.class,
() -> workingGitClient
.push()
.to(bareURI)
.ref(refSpec)
.timeout(1)
.execute());
}

@Test
Expand Down
14 changes: 8 additions & 6 deletions src/test/java/org/jenkinsci/plugins/gitclient/PushTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,14 @@ void pushNonFastForwardForce() throws Exception {
checkoutOldBranchAndCommitFile();

if (expectedException != null) {
assertThrows(expectedException, () -> workingGitClient
.push()
.to(bareURI)
.ref(refSpec)
.force(true)
.execute());
assertThrows(
expectedException,
() -> workingGitClient
.push()
.to(bareURI)
.ref(refSpec)
.force(true)
.execute());
} else {
workingGitClient.push().to(bareURI).ref(refSpec).force(true).execute();
}
Expand Down
Loading