Implement delete for git

This commit is contained in:
Rene Pfeuffer
2019-09-04 10:31:01 +02:00
parent 379c58d3a9
commit c37ed20303
4 changed files with 67 additions and 8 deletions

View File

@@ -16,6 +16,7 @@ import org.junit.rules.TemporaryFolder;
import sonia.scm.AlreadyExistsException;
import sonia.scm.BadRequestException;
import sonia.scm.ConcurrentModificationException;
import sonia.scm.NotFoundException;
import sonia.scm.repository.Person;
import sonia.scm.repository.util.WorkdirProvider;
@@ -156,6 +157,47 @@ public class GitModifyCommandTest extends AbstractGitCommandTestBase {
command.execute(request);
}
@Test
public void shouldDeleteExistingFile() throws IOException, GitAPIException {
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.DeleteFileRequest("a.txt"));
request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det"));
command.execute(request);
TreeAssertions assertions = canonicalTreeParser -> assertThat(canonicalTreeParser.findFile("a.txt")).isFalse();
assertInTree(assertions);
}
@Test(expected = NotFoundException.class)
public void shouldThrowNotFoundExceptionWhenFileToDeleteDoesNotExist() {
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.DeleteFileRequest("no/such/file"));
request.setAuthor(new Person("Dirk Gently", "dirk@holistic.det"));
command.execute(request);
}
@Test(expected = NotFoundException.class)
public void shouldThrowNotFoundExceptionWhenBranchDoesNotExist() {
GitModifyCommand command = createCommand();
ModifyCommandRequest request = new ModifyCommandRequest();
request.setBranch("does-not-exist");
request.setCommitMessage("test commit");
request.addRequest(new ModifyCommandRequest.DeleteFileRequest("a.txt"));
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);