Enhance branch object with default flag

This commit is contained in:
René Pfeuffer
2019-03-25 11:28:29 +01:00
parent 5aab95b651
commit 4ec7006108
9 changed files with 26 additions and 10 deletions

View File

@@ -66,7 +66,7 @@ public final class Branch implements Serializable
* This constructor should only be called from JAXB.
*
*/
public Branch() {}
Branch() {}
/**
* Constructs a new branch.
@@ -75,10 +75,19 @@ public final class Branch implements Serializable
* @param name name of the branch
* @param revision latest revision of the branch
*/
public Branch(String name, String revision)
Branch(String name, String revision, boolean defaultBranch)
{
this.name = name;
this.revision = revision;
this.defaultBranch = defaultBranch;
}
public static Branch normalBranch(String name, String revision) {
return new Branch(name, revision, false);
}
public static Branch defaultBranch(String name, String revision) {
return new Branch(name, revision, true);
}
//~--- methods --------------------------------------------------------------
@@ -162,6 +171,10 @@ public final class Branch implements Serializable
return revision;
}
public boolean isDefaultBranch() {
return defaultBranch;
}
//~--- fields ---------------------------------------------------------------
/** name of the branch */
@@ -169,4 +182,6 @@ public final class Branch implements Serializable
/** Field description */
private String revision;
private boolean defaultBranch;
}

View File

@@ -92,7 +92,7 @@ public class GitBranchesCommand extends AbstractGitCommand
if (branchName != null)
{
branch = new Branch(branchName, GitUtil.getId(ref.getObjectId()));
branch = Branch.normalBranch(branchName, GitUtil.getId(ref.getObjectId()));
}
return branch;

View File

@@ -72,7 +72,7 @@ public class GitBranchCommand implements BranchCommand
try
{
Ref ref = git.branchCreate().setName(name).call();
return new Branch(name, GitUtil.getId(ref.getObjectId()));
return Branch.normalBranch(name, GitUtil.getId(ref.getObjectId()));
}
catch (GitAPIException ex)
{

View File

@@ -88,7 +88,7 @@ public class HgBranchesCommand extends AbstractCommand
node = changeset.getNode();
}
return new Branch(hgBranch.getName(), node);
return Branch.normalBranch(hgBranch.getName(), node);
}
});

View File

@@ -53,7 +53,7 @@ public class HgBranchCommand implements BranchCommand
public Branch branch(String name) throws IOException
{
com.aragost.javahg.commands.BranchCommand.on(repository).set(name);
return new Branch(name, repository.tip().getNode());
return Branch.normalBranch(name, repository.tip().getNode());
}
}

View File

@@ -12,6 +12,7 @@ public class BranchDto extends HalRepresentation {
private String name;
private String revision;
private boolean defaultBranch;
BranchDto(Links links, Embedded embedded) {
super(links, embedded);

View File

@@ -60,7 +60,7 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
}
if (repositoryService.isSupported(Command.BRANCHES)) {
embeddedBuilder.with("branches", branchCollectionToDtoMapper.getBranchDtoList(namespace, name,
getListOfObjects(source.getBranches(), branchName -> new Branch(branchName, source.getId()))));
getListOfObjects(source.getBranches(), branchName -> Branch.normalBranch(branchName, source.getId()))));
}
}
embeddedBuilder.with("parents", getListOfObjects(source.getParents(), parent -> changesetToParentDtoMapper.map(new Changeset(parent, 0L, null), repository)));

View File

@@ -125,7 +125,7 @@ public class BranchRootResourceTest extends RepositoryTestBase {
@Test
public void shouldFindExistingBranch() throws Exception {
when(branchesCommandBuilder.getBranches()).thenReturn(new Branches(new Branch("master", "revision")));
when(branchesCommandBuilder.getBranches()).thenReturn(new Branches(Branch.normalBranch("master", "revision")));
MockHttpRequest request = MockHttpRequest.get(BRANCH_URL);
MockHttpResponse response = new MockHttpResponse();
@@ -153,7 +153,7 @@ public class BranchRootResourceTest extends RepositoryTestBase {
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
Branches branches = mock(Branches.class);
List<Branch> branchList = Lists.newArrayList(new Branch("master",id));
List<Branch> branchList = Lists.newArrayList(Branch.normalBranch("master",id));
when(branches.getBranches()).thenReturn(branchList);
when(branchesCommandBuilder.getBranches()).thenReturn(branches);
MockHttpRequest request = MockHttpRequest.get(BRANCH_URL + "/changesets/");

View File

@@ -33,7 +33,7 @@ class BranchToBranchDtoMapperTest {
});
mapper.setRegistry(registry);
Branch branch = new Branch("master", "42");
Branch branch = Branch.normalBranch("master", "42");
BranchDto dto = mapper.map(branch, new NamespaceAndName("hitchhiker", "heart-of-gold"));
assertThat(dto.getLinks().getLinkBy("ka").get().getHref()).isEqualTo("http://hitchhiker/heart-of-gold/master");