本文整理汇总了Java中org.eclipse.jgit.api.ListBranchCommand.ListMode类的典型用法代码示例。如果您正苦于以下问题:Java ListMode类的具体用法?Java ListMode怎么用?Java ListMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListMode类属于org.eclipse.jgit.api.ListBranchCommand包,在下文中一共展示了ListMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
public static void main(String[] args) throws IOException, GitAPIException {
Repository repo = Commands.getRepo(Consts.META_REPO_PATH);
Git git = new Git(repo);
// Create a new branch
git.branchCreate().setName("newBranch").call();
// Checkout the new branch
git.checkout().setName("newBranch").call();
// List the existing branches
List<Ref> listRefsBranches = git.branchList().setListMode(ListMode.ALL).call();
listRefsBranches.forEach((refBranch) -> {
System.out.println("Branch : " + refBranch.getName());
});
// Go back on "master" branch and remove the created one
git.checkout().setName("master");
git.branchDelete().setBranchNames("newBranch");
}
示例2: retreiveBranches
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
@Override
public List<String> retreiveBranches() {
List <String> receivedListAsString = new ArrayList<>();
List <Ref> receivedList;
try {
receivedList = _git.branchList().setListMode(ListMode.ALL).call();
for (Ref ref : receivedList) {
receivedListAsString.add(ref.getName());
}
} catch (GitAPIException e) {
VerigreenLogger.get().log(
getClass().getName(),
RuntimeUtils.getCurrentMethodName(), "Failed to receive branches list");
return null;
}
return receivedListAsString;
}
示例3: getBranches
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
/**
* Get a list of branches based on mode
* @param mode
* @return
*/
private List<String> getBranches( ListMode mode ) {
try {
return git.branchList().setListMode( mode ).call().stream()
.filter( ref -> !ref.getName().endsWith( Constants.HEAD ) )
.map( ref -> Repository.shortenRefName( ref.getName() ) )
.collect( Collectors.toList() );
} catch ( Exception e ) {
e.printStackTrace();
}
return null;
}
示例4: getBranch
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
public static Ref getBranch(String repositoryPath,ObjectId id) throws IOException, GitAPIException{
Git git = new Git(new FileRepository(repositoryPath+"/.git"));
ListBranchCommand list = git.branchList().setListMode(ListMode.ALL);
List<Ref> call = list.call();
Ref ref = null;
for(Ref r:call){
if(r.getObjectId().equals(id)){
ref = r;
}
}
return ref;
}
示例5: cloneAll
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
public void cloneAll(String host) throws InvalidRemoteException, TransportException, GitAPIException{
Git git = Git.cloneRepository().setURI(host).setNoCheckout(true).setCloneAllBranches(true).call();
List<Ref> branches = git.branchList().setListMode( ListMode.REMOTE ).call();
for(Ref r:branches){
System.out.println(r.getName());
}
}
示例6: doShowBranches
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
protected void doShowBranches(Exchange exchange, String operation) throws Exception {
List<Ref> result = null;
try {
result = git.branchList().setListMode(ListMode.ALL).call();
} catch (Exception e) {
LOG.error("There was an error in Git " + operation + " operation");
throw e;
}
exchange.getOut().setBody(result);
}
示例7: getRevision
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
private Revision getRevision(RevCommit commit, String filePath)
throws GitAPIException, IOException {
List<String> commitParentsList =
Stream.of(commit.getParents()).map(RevCommit::getName).collect(Collectors.toList());
return newDto(Revision.class)
.withId(commit.getId().getName())
.withMessage(commit.getFullMessage())
.withCommitTime((long) commit.getCommitTime() * 1000)
.withCommitter(getCommitCommitter(commit))
.withAuthor(getCommitAuthor(commit))
.withBranches(getBranchesOfCommit(commit, ListMode.ALL))
.withCommitParent(commitParentsList)
.withDiffCommitFile(getCommitDiffFiles(commit, filePath));
}
示例8: getBranchesOfCommit
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
private List<Branch> getBranchesOfCommit(RevCommit commit, ListMode mode) throws GitAPIException {
List<Ref> branches =
getGit().branchList().setListMode(mode).setContains(commit.getName()).call();
return branches
.stream()
.map(branch -> newDto(Branch.class).withName(branch.getName()))
.collect(toList());
}
示例9: getBranches
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
@Override
public void getBranches(final List<String> names, final List<String> commits) {
try {
for (final Ref ref : git.branchList().setListMode(ListMode.REMOTE).call()) {
names.add(ref.getName());
commits.add(ref.getObjectId().getName());
}
} catch (final GitAPIException e) {
if (debug)
System.err.println("Git Error reading branches: " + e.getMessage());
}
}
示例10: containsBranch
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
private boolean containsBranch(Git git, String label, ListMode listMode)
throws GitAPIException {
ListBranchCommand command = git.branchList();
if (listMode != null) {
command.setListMode(listMode);
}
List<Ref> branches = command.call();
for (Ref ref : branches) {
if (ref.getName().endsWith("/" + label)) {
return true;
}
}
return false;
}
示例11: getBranches
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
@Override
public Collection<BranchModel> getBranches() {
try {
return git.branchList()
.setListMode(ListMode.ALL)
.call().stream()
.map(this::transformToBranchModel)
.collect(Collectors.toList());
}
catch (GitAPIException e) {
throw new GitException(e.getMessage(), e);
}
}
示例12: getBranches
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
@Override
public Stream<VersionInfo> getBranches() throws IOException {
try {
return refToVersionInfo(repo.branchList().setListMode(ListMode.ALL).call().stream());
} catch (GitAPIException ex) {
throw new IOException(ex);
}
}
示例13: getDefaultBaseline
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
@Override
public Optional<VersionInfo> getDefaultBaseline() {
try {
return refToVersionInfo(
repo.branchList()
.setListMode(ListMode.ALL)
.setContains("HEAD")
.call()
.stream()).findAny();
} catch (GitAPIException ex) {
return Optional.empty();
}
}
示例14: branchList
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
@Override
public List<Branch> branchList(BranchListMode listMode) throws GitException {
ListBranchCommand listBranchCommand = getGit().branchList();
if (LIST_ALL == listMode || listMode == null) {
listBranchCommand.setListMode(ListMode.ALL);
} else if (LIST_REMOTE == listMode) {
listBranchCommand.setListMode(ListMode.REMOTE);
}
List<Ref> refs;
String currentRef;
try {
refs = listBranchCommand.call();
String headBranch = getRepository().getBranch();
Optional<Ref> currentTag =
getGit()
.tagList()
.call()
.stream()
.filter(tag -> tag.getObjectId().getName().equals(headBranch))
.findFirst();
if (currentTag.isPresent()) {
currentRef = currentTag.get().getName();
} else {
currentRef = "refs/heads/" + headBranch;
}
} catch (GitAPIException | IOException exception) {
throw new GitException(exception.getMessage(), exception);
}
List<Branch> branches = new ArrayList<>();
for (Ref ref : refs) {
String refName = ref.getName();
boolean isCommitOrTag = HEAD.equals(refName);
String branchName = isCommitOrTag ? currentRef : refName;
String branchDisplayName;
if (isCommitOrTag) {
branchDisplayName = "(detached from " + Repository.shortenRefName(currentRef) + ")";
} else {
branchDisplayName = Repository.shortenRefName(refName);
}
Branch branch =
newDto(Branch.class)
.withName(branchName)
.withActive(isCommitOrTag || refName.equals(currentRef))
.withDisplayName(branchDisplayName)
.withRemote(refName.startsWith("refs/remotes"));
branches.add(branch);
}
return branches;
}
示例15: push
import org.eclipse.jgit.api.ListBranchCommand.ListMode; //导入依赖的package包/类
@Override
public boolean push(String sourceBranch, String destinationBranch) {
PushCommand command = _git.push();
boolean ret = true;
RefSpec refSpec = new RefSpec().setSourceDestination(sourceBranch, destinationBranch);
command.setRefSpecs(refSpec);
try {
List<Ref> remoteBranches = _git.branchList().setListMode(ListMode.REMOTE).call();
Iterable<PushResult> results = command.call();
for (PushResult pushResult : results) {
Collection<RemoteRefUpdate> resultsCollection = pushResult.getRemoteUpdates();
Map<PushResult,RemoteRefUpdate> resultsMap = new HashMap<>();
for(RemoteRefUpdate remoteRefUpdate : resultsCollection)
{
resultsMap.put(pushResult, remoteRefUpdate);
}
RemoteRefUpdate remoteUpdate = pushResult.getRemoteUpdate(destinationBranch);
if (remoteUpdate != null) {
org.eclipse.jgit.transport.RemoteRefUpdate.Status status =
remoteUpdate.getStatus();
ret =
status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.OK)
|| status.equals(org.eclipse.jgit.transport.RemoteRefUpdate.Status.UP_TO_DATE);
}
if(remoteUpdate == null && !remoteBranches.toString().contains(destinationBranch))
{
for(RemoteRefUpdate resultValue : resultsMap.values())
{
if(resultValue.toString().contains("REJECTED_OTHER_REASON"))
{
ret = false;
}
}
}
}
} catch (Throwable e) {
throw new RuntimeException(String.format(
"Failed to push [%s] into [%s]",
sourceBranch,
destinationBranch), e);
}
return ret;
}