Skip to content

Commit

Permalink
Merge pull request magnayn#1 from wannessels/forceOption
Browse files Browse the repository at this point in the history
added testcase for force push [JENKINS-24082]
  • Loading branch information
guilhem committed Sep 16, 2014
2 parents 79819f5 + b14f6f4 commit ef6bc18
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/test/java/hudson/plugins/git/GitPublisherTest.java
Original file line number Diff line number Diff line change
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 ef6bc18

Please sign in to comment.