Skip to content

Commit

Permalink
added testcase for force push [JENKINS-24082]
Browse files Browse the repository at this point in the history
  • Loading branch information
wannessels committed Sep 16, 2014
1 parent 79819f5 commit b14f6f4
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/java/hudson/plugins/git/GitPublisherTest.java
Expand Up @@ -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;
Expand Down Expand Up @@ -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.<SubmoduleConfig>emptyList(),
null, null,
Collections.<GitSCMExtension>emptyList());
project.setScm(scm);

project.getPublishersList().add(new GitPublisher(
Collections.<TagToPush>emptyList(),
Collections.singletonList(new BranchToPush("origin", "otherbranch")),
Collections.<NoteToPush>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
Expand Down

0 comments on commit b14f6f4

Please sign in to comment.