Skip to content

Commit

Permalink
JENKINS-25960: Fixed tests due testutils change
Browse files Browse the repository at this point in the history
  • Loading branch information
Bue Petersen committed Dec 11, 2014
1 parent 6e27a1e commit 64208a4
Showing 1 changed file with 32 additions and 7 deletions.
Expand Up @@ -7,8 +7,10 @@

import hudson.model.AbstractBuild;
import hudson.model.Result;
import java.io.File;
import java.util.Iterator;
import static junit.framework.TestCase.assertTrue;
import org.apache.commons.io.FileUtils;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.Repository;
Expand Down Expand Up @@ -95,17 +97,27 @@ private void validateResult() throws ValidationException {
}
}

private boolean validateHeadCommitMessage() throws ValidationException,Exception {
Git git = new Git(repo);
private boolean validateHeadCommitMessage() throws ValidationException, Exception {

File workDirForRepo = new File("work-" + repo.getDirectory().getPath().replace(".git",""));
Git.cloneRepository().setURI("file:///"+repo.getDirectory().getAbsolutePath()).setDirectory(workDirForRepo)
.setBare(false)
.setCloneAllBranches(true)
.setNoCheckout(false)
.call().close();

Git git = Git.open(workDirForRepo);

git.checkout().setName("master").call();
RevWalk walk = new RevWalk(repo);

Iterable<RevCommit> logs = git.log().call();
Iterator<RevCommit> i = logs.iterator();

ObjectId head = repo.resolve("HEAD");


Boolean validated = false;
String errorMessage = "No head commit found";
RevCommit commit = null;
while(i.hasNext()) {
commit = walk.parseCommit(i.next());
Expand All @@ -119,14 +131,27 @@ private boolean validateHeadCommitMessage() throws ValidationException,Exception
}

if(!(matched && match)) {
throw new ValidationException("The head commit did not match any of the strings specified");
validated = false;
errorMessage = "The head commit did not match any of the strings specified";
break;
//throw new ValidationException("The head commit did not match any of the strings specified");
} else {
return true;
//return true;
validated = true;

}

}
}
throw new ValidationException("No head commit found");
//throw new ValidationException("No head commit found");
git.close();
FileUtils.deleteDirectory(workDirForRepo);
if (!validated) {
throw new ValidationException(errorMessage);
}
else {
return validated;
}
}

@Override
Expand Down

0 comments on commit 64208a4

Please sign in to comment.