Throw exception when no changes were made

This commit is contained in:
Rene Pfeuffer
2019-08-29 17:57:29 +02:00
parent bdc2622df8
commit 8a7b50a079
5 changed files with 58 additions and 4 deletions

View File

@@ -14,6 +14,7 @@ import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import sonia.scm.AlreadyExistsException;
import sonia.scm.BadRequestException;
import sonia.scm.repository.Person;
import sonia.scm.repository.util.WorkdirProvider;
@@ -108,6 +109,21 @@ public class GitModifyCommandTest extends AbstractGitCommandTestBase {
assertInTree(assertions);
}
@Test(expected = BadRequestException.class)
public void shouldFailIfNoChangesMade() throws IOException, GitAPIException {
File newFile = Files.write(temporaryFolder.newFile().toPath(), "b\n".getBytes()).toFile();
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setBranch("master");
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.CreateFileRequest("b.txt", newFile, true));
request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det"));
command.execute(request);
}
private void assertInTree(TreeAssertions assertions) throws IOException, GitAPIException {
try (Git git = new Git(createContext().open())) {
RevCommit lastCommit = getLastCommit(git);