implement deleteBranchCommand for git

This commit is contained in:
Eduard Heimbuch
2019-11-11 11:15:56 +01:00
parent 73cdab4ddc
commit 7cd2cb4ccb
4 changed files with 40 additions and 0 deletions

View File

@@ -4,12 +4,15 @@ import org.assertj.core.api.Assertions;
import org.junit.Rule;
import org.junit.Test;
import sonia.scm.repository.Branch;
import sonia.scm.repository.InternalRepositoryException;
import sonia.scm.repository.api.BranchRequest;
import sonia.scm.repository.util.WorkdirProvider;
import java.io.IOException;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class GitBranchCommandTest extends AbstractGitCommandTestBase {
@@ -51,6 +54,21 @@ public class GitBranchCommandTest extends AbstractGitCommandTestBase {
Assertions.assertThat(readBranches(context)).filteredOn(b -> b.getName().equals("new_branch")).isNotEmpty();
}
@Test
public void shouldDeleteBranch() throws IOException {
GitContext context = createContext();
String branchToBeDeleted = "squash";
new GitBranchCommand(context, repository, new SimpleGitWorkdirFactory(new WorkdirProvider())).delete(branchToBeDeleted);
Assertions.assertThat(readBranches(context)).filteredOn(b -> b.getName().equals(branchToBeDeleted)).isEmpty();
}
@Test
public void shouldThrowInternalRepositoryException() {
GitContext context = createContext();
String branchToBeDeleted = "master";
assertThrows(InternalRepositoryException.class, () -> new GitBranchCommand(context, repository, new SimpleGitWorkdirFactory(new WorkdirProvider())).delete(branchToBeDeleted));
}
private List<Branch> readBranches(GitContext context) throws IOException {
return new GitBranchesCommand(context, repository).getBranches();
}