forked from Praqma/pretested-integration-plugin
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JENKINS-30603] Squash strategy now respects single commit messages.
- Loading branch information
Thierry Lacour
committed
Sep 24, 2015
1 parent
e93ad80
commit 9b6d14d
Showing
8 changed files
with
288 additions
and
38 deletions.
There are no files selected for viewing
40 changes: 40 additions & 0 deletions
40
.../org/jenkinsci/plugins/pretestedintegration/scm/git/GetCommitCountFromBranchCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,40 @@ | |||
package org.jenkinsci.plugins.pretestedintegration.scm.git; | |||
|
|||
import hudson.model.TaskListener; | |||
import hudson.remoting.VirtualChannel; | |||
import java.io.IOException; | |||
import org.eclipse.jgit.lib.ObjectId; | |||
import org.eclipse.jgit.lib.Repository; | |||
import org.eclipse.jgit.revwalk.RevCommit; | |||
import org.eclipse.jgit.revwalk.RevWalk; | |||
|
|||
public class GetCommitCountFromBranchCallback extends RepositoryListenerAwareCallback<Integer> { | |||
|
|||
public final ObjectId startObjectId; | |||
public final String targetBranchName; | |||
|
|||
public GetCommitCountFromBranchCallback(TaskListener listener, final ObjectId startObjectId, final String targetBranchName) { | |||
super(listener); | |||
this.startObjectId = startObjectId; | |||
this.targetBranchName = targetBranchName; | |||
} | |||
|
|||
@Override | |||
public Integer invoke(Repository repository, VirtualChannel channel) throws IOException, InterruptedException { | |||
RevWalk walker = new RevWalk(repository); | |||
RevCommit originCommit = walker.parseCommit(startObjectId); | |||
ObjectId targetId = repository.resolve(targetBranchName); | |||
RevCommit targetCommit = walker.parseCommit(targetId); | |||
|
|||
walker.markStart(originCommit); | |||
walker.markUninteresting(targetCommit); | |||
|
|||
int commitCount = 0; | |||
for (RevCommit rev : walker) { | |||
commitCount++; | |||
} | |||
walker.dispose(); | |||
|
|||
return commitCount; | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
.../plugins/pretestedintegration/integration/scm/git/GetCommitCountFromBranchCallbackIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
package org.jenkinsci.plugins.pretestedintegration.integration.scm.git; | |||
|
|||
import hudson.model.TaskListener; | |||
import java.io.File; | |||
import static junit.framework.TestCase.assertEquals; | |||
import org.apache.commons.io.FileUtils; | |||
import org.eclipse.jgit.api.Git; | |||
import org.eclipse.jgit.lib.ObjectId; | |||
import org.jenkinsci.plugins.pretestedintegration.scm.git.GetCommitCountFromBranchCallback; | |||
import org.junit.After; | |||
import org.junit.Test; | |||
|
|||
public class GetCommitCountFromBranchCallbackIT { | |||
|
|||
private final String FOLDER_PREFIX = "CommitCount_"; | |||
private File dir; | |||
|
|||
@After | |||
public void tearDown() throws Exception { | |||
TestUtilsFactory.destroyDirectory(dir); | |||
} | |||
|
|||
@Test | |||
public void counts_two_commits() throws Exception { | |||
dir = new File(FOLDER_PREFIX + "count2"); | |||
Git git = Git.init().setDirectory(dir).call(); | |||
File testFile = new File(dir + "/file"); | |||
|
|||
// First commit to master | |||
FileUtils.writeStringToFile(testFile, "master commit 1"); | |||
git.add().addFilepattern("file").call(); | |||
git.commit().setMessage("master commit 1").call(); | |||
|
|||
// Create a branch | |||
git.checkout().setCreateBranch(true).setName("branch").call(); | |||
// First commit to branch | |||
FileUtils.writeStringToFile(testFile, "branch commit 1", true); | |||
git.add().addFilepattern("file").call(); | |||
git.commit().setMessage("branch commit 1").call(); | |||
// Second commit to branch | |||
FileUtils.writeStringToFile(testFile, "branch commit 2", true); | |||
git.add().addFilepattern("file").call(); | |||
ObjectId startCommit = git.commit().setMessage("branch commit 2").call(); | |||
|
|||
// Counts two commits | |||
GetCommitCountFromBranchCallback callback = new GetCommitCountFromBranchCallback(TaskListener.NULL, startCommit, "master"); | |||
assertEquals("Commit count did not match expectations.", new Integer(2), callback.invoke(git.getRepository(), null)); | |||
|
|||
// Second commit to master | |||
FileUtils.writeStringToFile(testFile, "master commit 2"); | |||
git.add().addFilepattern("file").call(); | |||
git.commit().setMessage("master commit 2").call(); | |||
|
|||
// STILL counts two commits | |||
callback = new GetCommitCountFromBranchCallback(TaskListener.NULL, startCommit, "master"); | |||
assertEquals("Commit count did not match expectations.", new Integer(2), callback.invoke(git.getRepository(), null)); | |||
} | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.