public interface

RepositoryMetadataService

com.atlassian.stash.repository.RepositoryMetadataService

Class Overview

A service for interacting with metadata about a given Repository, such as branches and tags.

Summary

Public Methods
@Nonnull Page<Branch> getBranches(RepositoryBranchesRequest request, PageRequest pageRequest)
Retrieves a paged list of branches for the specified repository, optionally filtered by the provided starting text.
@Nonnull @Deprecated Page<? extends Branch> getBranches(Repository repository, PageRequest pageRequest, String filterText, RefOrder order)
This method is deprecated. in 2.8 for removal in 3.0, replaced by getBranches(RepositoryBranchesRequest, PageRequest)
@Nonnull Branch getDefaultBranch(Repository repository)
Retrieves the default branch for the specified repository.
@Nonnull Map<RefMetadataMap> getMetadataByRefs(RefMetadataRequest request)
Retrieves the associated metadata based on a given collection of refs in a repository.
@Nonnull Page<? extends Tag> getTags(Repository repository, PageRequest pageRequest, String filterText, RefOrder order)
Retrieves a paged list of Tags for the specified repository, optionally filtered by the provided starting text.
boolean isEmpty(Repository repository)
Retrieves a flag indicating whether the specified repository is empty or not.
@Nullable Ref resolveRef(Repository repository, String objectId)
Attempts to resolve a Ref from the provided objectId.
void setDefaultBranch(Repository repository, String branchName)
Sets the default branch for the specified repository.

Public Methods

@Nonnull public Page<Branch> getBranches (RepositoryBranchesRequest request, PageRequest pageRequest)

Retrieves a paged list of branches for the specified repository, optionally filtered by the provided starting text.

Parameters
request request parameters for this query, including repository, filter text and ordering
pageRequest the page request defining the page start and limit
Returns
  • a page containing 0 or more branches

@Nonnull @Deprecated public Page<? extends Branch> getBranches (Repository repository, PageRequest pageRequest, String filterText, RefOrder order)

This method is deprecated.
in 2.8 for removal in 3.0, replaced by getBranches(RepositoryBranchesRequest, PageRequest)

Retrieves a paged list of Branches for the specified repository, optionally filtered by the provided starting text.

Parameters
repository the repository to retrieve branches from
pageRequest the page request defining the page start and limit
filterText optional text for filtering returned branches
order the ordering to apply when listing branches
Returns
  • a page containing 0 or more branches

@Nonnull public Branch getDefaultBranch (Repository repository)

Retrieves the default branch for the specified repository.

If the repository is newly created and no commits have been pushed to it, it will have no default branch. As a result, for new repositories, this method can return null.

Parameters
repository the repository to retrieve the default branch for
Returns
  • the default branch, if any, or null if the repository is empty
Throws
NoDefaultBranchException when no default branch is configured for the repository

@Nonnull public Map<RefMetadataMap> getMetadataByRefs (RefMetadataRequest request)

Retrieves the associated metadata based on a given collection of refs in a repository.

Parameters
request request parameters for this query, including repository and refs to find metadata for
Returns
  • a containing the associated metadata keyed by Ref

@Nonnull public Page<? extends Tag> getTags (Repository repository, PageRequest pageRequest, String filterText, RefOrder order)

Retrieves a paged list of Tags for the specified repository, optionally filtered by the provided starting text.

Parameters
repository the repository to retrieve tags from
pageRequest the page request defining the page start and limit
filterText optional text for filtering returned tags
order the ordering to apply when listing tags
Returns
  • a page containing 0 or more tags

public boolean isEmpty (Repository repository)

Retrieves a flag indicating whether the specified repository is empty or not. While the definition of "empty" is SCM-specific, it generally distills to a repository which contains no branches or tags.

Parameters
repository the repository to check
Returns
  • true if the repository is empty; otherwise false

@Nullable public Ref resolveRef (Repository repository, String objectId)

Attempts to resolve a Ref from the provided objectId. Specifically, the object is resolved as either a Branch or Tag. If the provided objectId references something else, such as a commit hash, tree or blob, null is returned.

Parameters
repository the repository to resolve the objectId in
objectId the object within the repository to resolve
Returns
  • a Branch or a Tag or null to indicate "something else"

public void setDefaultBranch (Repository repository, String branchName)

Sets the default branch for the specified repository. Support for this operation is SCM-specific, and different SCMs may apply different rules to what values are supported.

Parameters
repository the repository to update the default branch for
branchName the branch to mark as the default within the repository