Checkout target branch while cloning repository

This will prevent the checkout of a wrong initial branch and therefore
safe some unnecessary io
This commit is contained in:
René Pfeuffer
2019-10-06 16:29:50 +02:00
parent d83bc4ea86
commit 3dea971e10
14 changed files with 188 additions and 73 deletions

View File

@@ -2,7 +2,7 @@ package sonia.scm.repository.spi;
import com.aragost.javahg.commands.PullCommand;
import com.google.inject.util.Providers;
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
import sonia.scm.repository.Branch;
import sonia.scm.repository.HgTestUtil;
@@ -10,30 +10,48 @@ import sonia.scm.repository.api.BranchRequest;
import sonia.scm.repository.util.WorkdirProvider;
import sonia.scm.web.HgRepositoryEnvironmentBuilder;
import java.io.IOException;
import java.util.List;
public class HgBranchCommandTest extends AbstractHgCommandTestBase {
@Test
public void shouldCreateBranch() throws IOException {
Assertions.assertThat(readBranches()).filteredOn(b -> b.getName().equals("new_branch")).isEmpty();
import static org.assertj.core.api.Assertions.assertThat;
public class HgBranchCommandTest extends AbstractHgCommandTestBase {
private SimpleHgWorkdirFactory workdirFactory;
@Before
public void initWorkdirFactory() {
HgRepositoryEnvironmentBuilder hgRepositoryEnvironmentBuilder =
new HgRepositoryEnvironmentBuilder(handler, HgTestUtil.createHookManager());
SimpleHgWorkdirFactory workdirFactory = new SimpleHgWorkdirFactory(Providers.of(hgRepositoryEnvironmentBuilder), new WorkdirProvider()) {
workdirFactory = new SimpleHgWorkdirFactory(Providers.of(hgRepositoryEnvironmentBuilder), new WorkdirProvider()) {
@Override
public void configure(PullCommand pullCommand) {
// we do not want to configure http hooks in this unit test
}
};
}
@Test
public void shouldCreateBranch() {
BranchRequest branchRequest = new BranchRequest();
branchRequest.setNewBranch("new_branch");
new HgBranchCommand(cmdContext, repository, workdirFactory).branch(branchRequest);
Branch newBranch = new HgBranchCommand(cmdContext, repository, workdirFactory).branch(branchRequest);
Assertions.assertThat(readBranches()).filteredOn(b -> b.getName().equals("new_branch")).isNotEmpty();
assertThat(readBranches()).filteredOn(b -> b.getName().equals("new_branch")).isNotEmpty();
assertThat(cmdContext.open().changeset(newBranch.getRevision()).getParent1().getBranch()).isEqualTo("default");
}
@Test
public void shouldCreateBranchOnSpecificParent() {
BranchRequest branchRequest = new BranchRequest();
branchRequest.setParentBranch("test-branch");
branchRequest.setNewBranch("new_branch");
Branch newBranch = new HgBranchCommand(cmdContext, repository, workdirFactory).branch(branchRequest);
assertThat(readBranches()).filteredOn(b -> b.getName().equals("new_branch")).isNotEmpty();
assertThat(cmdContext.open().changeset(newBranch.getRevision()).getParent1().getBranch()).isEqualTo("test-branch");
}
private List<Branch> readBranches() {