diff --git a/src/test/java/hudson/plugins/git/GitPublisherTest.java b/src/test/java/hudson/plugins/git/GitPublisherTest.java index 6c164d73fd..451c5d4088 100644 --- a/src/test/java/hudson/plugins/git/GitPublisherTest.java +++ b/src/test/java/hudson/plugins/git/GitPublisherTest.java @@ -39,7 +39,9 @@ import hudson.scm.NullSCM; import hudson.tasks.BuildStepDescriptor; import org.eclipse.jgit.lib.Constants; +import org.eclipse.jgit.lib.ObjectId; import org.jvnet.hudson.test.Bug; +import org.jvnet.hudson.test.Issue; import java.io.IOException; import java.util.ArrayList; @@ -132,6 +134,40 @@ public void testMergeAndPush() throws Exception { assertEquals(sha1, testRepo.git.revParse(Constants.HEAD).name()); } + + @Issue("JENKINS-24082") + public void testForcePush() throws Exception { + FreeStyleProject project = setupSimpleProject("master"); + + GitSCM scm = new GitSCM( + createRemoteRepositories(), + Collections.singletonList(new BranchSpec("*")), + false, Collections.emptyList(), + null, null, + Collections.emptyList()); + project.setScm(scm); + + project.getPublishersList().add(new GitPublisher( + Collections.emptyList(), + Collections.singletonList(new BranchToPush("origin", "otherbranch")), + Collections.emptyList(), + true, true, true)); + + commit("commitFile", johnDoe, "Initial Commit"); + + testRepo.git.branch("otherbranch"); + testRepo.git.checkout("otherbranch"); + commit("otherCommitFile", johnDoe, "commit lost on force push"); + + testRepo.git.checkout("master"); + commit("commitFile2", johnDoe, "commit to be pushed"); + + ObjectId expectedCommit = testRepo.git.revParse("master"); + + build(project, Result.SUCCESS, "commitFile"); + + assertEquals(expectedCommit, testRepo.git.revParse("otherbranch")); + } /** * Fix push to remote when skipTag is enabled