mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-10 07:25:44 +01:00
Enhance branch object with default flag
This commit is contained in:
@@ -66,7 +66,7 @@ public final class Branch implements Serializable
|
|||||||
* This constructor should only be called from JAXB.
|
* This constructor should only be called from JAXB.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public Branch() {}
|
Branch() {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new branch.
|
* Constructs a new branch.
|
||||||
@@ -75,10 +75,19 @@ public final class Branch implements Serializable
|
|||||||
* @param name name of the branch
|
* @param name name of the branch
|
||||||
* @param revision latest revision 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.name = name;
|
||||||
this.revision = revision;
|
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 --------------------------------------------------------------
|
//~--- methods --------------------------------------------------------------
|
||||||
@@ -162,6 +171,10 @@ public final class Branch implements Serializable
|
|||||||
return revision;
|
return revision;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isDefaultBranch() {
|
||||||
|
return defaultBranch;
|
||||||
|
}
|
||||||
|
|
||||||
//~--- fields ---------------------------------------------------------------
|
//~--- fields ---------------------------------------------------------------
|
||||||
|
|
||||||
/** name of the branch */
|
/** name of the branch */
|
||||||
@@ -169,4 +182,6 @@ public final class Branch implements Serializable
|
|||||||
|
|
||||||
/** Field description */
|
/** Field description */
|
||||||
private String revision;
|
private String revision;
|
||||||
|
|
||||||
|
private boolean defaultBranch;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ public class GitBranchesCommand extends AbstractGitCommand
|
|||||||
|
|
||||||
if (branchName != null)
|
if (branchName != null)
|
||||||
{
|
{
|
||||||
branch = new Branch(branchName, GitUtil.getId(ref.getObjectId()));
|
branch = Branch.normalBranch(branchName, GitUtil.getId(ref.getObjectId()));
|
||||||
}
|
}
|
||||||
|
|
||||||
return branch;
|
return branch;
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class GitBranchCommand implements BranchCommand
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
Ref ref = git.branchCreate().setName(name).call();
|
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)
|
catch (GitAPIException ex)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class HgBranchesCommand extends AbstractCommand
|
|||||||
node = changeset.getNode();
|
node = changeset.getNode();
|
||||||
}
|
}
|
||||||
|
|
||||||
return new Branch(hgBranch.getName(), node);
|
return Branch.normalBranch(hgBranch.getName(), node);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ public class HgBranchCommand implements BranchCommand
|
|||||||
public Branch branch(String name) throws IOException
|
public Branch branch(String name) throws IOException
|
||||||
{
|
{
|
||||||
com.aragost.javahg.commands.BranchCommand.on(repository).set(name);
|
com.aragost.javahg.commands.BranchCommand.on(repository).set(name);
|
||||||
return new Branch(name, repository.tip().getNode());
|
return Branch.normalBranch(name, repository.tip().getNode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public class BranchDto extends HalRepresentation {
|
|||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
private String revision;
|
private String revision;
|
||||||
|
private boolean defaultBranch;
|
||||||
|
|
||||||
BranchDto(Links links, Embedded embedded) {
|
BranchDto(Links links, Embedded embedded) {
|
||||||
super(links, embedded);
|
super(links, embedded);
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ public abstract class DefaultChangesetToChangesetDtoMapper extends HalAppenderMa
|
|||||||
}
|
}
|
||||||
if (repositoryService.isSupported(Command.BRANCHES)) {
|
if (repositoryService.isSupported(Command.BRANCHES)) {
|
||||||
embeddedBuilder.with("branches", branchCollectionToDtoMapper.getBranchDtoList(namespace, name,
|
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)));
|
embeddedBuilder.with("parents", getListOfObjects(source.getParents(), parent -> changesetToParentDtoMapper.map(new Changeset(parent, 0L, null), repository)));
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ public class BranchRootResourceTest extends RepositoryTestBase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindExistingBranch() throws Exception {
|
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);
|
MockHttpRequest request = MockHttpRequest.get(BRANCH_URL);
|
||||||
MockHttpResponse response = new MockHttpResponse();
|
MockHttpResponse response = new MockHttpResponse();
|
||||||
@@ -153,7 +153,7 @@ public class BranchRootResourceTest extends RepositoryTestBase {
|
|||||||
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
|
when(logCommandBuilder.setBranch(anyString())).thenReturn(logCommandBuilder);
|
||||||
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
|
when(logCommandBuilder.getChangesets()).thenReturn(changesetPagingResult);
|
||||||
Branches branches = mock(Branches.class);
|
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(branches.getBranches()).thenReturn(branchList);
|
||||||
when(branchesCommandBuilder.getBranches()).thenReturn(branches);
|
when(branchesCommandBuilder.getBranches()).thenReturn(branches);
|
||||||
MockHttpRequest request = MockHttpRequest.get(BRANCH_URL + "/changesets/");
|
MockHttpRequest request = MockHttpRequest.get(BRANCH_URL + "/changesets/");
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class BranchToBranchDtoMapperTest {
|
|||||||
});
|
});
|
||||||
mapper.setRegistry(registry);
|
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"));
|
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");
|
assertThat(dto.getLinks().getLinkBy("ka").get().getHref()).isEqualTo("http://hitchhiker/heart-of-gold/master");
|
||||||
|
|||||||
Reference in New Issue
Block a user