Ensured we don't do empty commits
This commit is contained in:
@@ -27,6 +27,7 @@ import org.eclipse.jgit.api.CloneCommand;
|
||||
import org.eclipse.jgit.api.CreateBranchCommand;
|
||||
import org.eclipse.jgit.api.Git;
|
||||
import org.eclipse.jgit.api.ListBranchCommand;
|
||||
import org.eclipse.jgit.api.errors.EmtpyCommitException;
|
||||
import org.eclipse.jgit.api.errors.GitAPIException;
|
||||
import org.eclipse.jgit.lib.Ref;
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
@@ -105,7 +106,9 @@ class GitRepo {
|
||||
void commit(File project, String message) {
|
||||
try(Git git = this.gitFactory.open(file(project))) {
|
||||
git.add().addFilepattern(".").call();
|
||||
git.commit().setMessage(message).call();
|
||||
git.commit().setAllowEmpty(false).setMessage(message).call();
|
||||
} catch (EmtpyCommitException e) {
|
||||
log.info("There were no changes detected. Will not commit an empty commit");
|
||||
} catch (Exception e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
|
||||
@@ -110,6 +110,20 @@ public class GitRepoTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_not_commit_empty_changes() throws Exception {
|
||||
File project = this.gitRepo.cloneProject(this.springCloudReleaseProject.toURI());
|
||||
createNewFile(project);
|
||||
this.gitRepo.commit(project, "some message");
|
||||
|
||||
this.gitRepo.commit(project, "empty commit");
|
||||
|
||||
try(Git git = openGitProject(project)) {
|
||||
RevCommit revCommit = git.log().call().iterator().next();
|
||||
then(revCommit.getShortMessage()).isNotEqualTo("empty commit");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void should_create_a_tag() throws Exception {
|
||||
File project = this.gitRepo.cloneProject(this.springCloudReleaseProject.toURI());
|
||||
|
||||
Reference in New Issue
Block a user