本文整理汇总了Java中org.eclipse.jgit.api.ListBranchCommand类的典型用法代码示例。如果您正苦于以下问题:Java ListBranchCommand类的具体用法?Java ListBranchCommand怎么用?Java ListBranchCommand使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListBranchCommand类属于org.eclipse.jgit.api包,在下文中一共展示了ListBranchCommand类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBranches
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
public static ArrayList<String> getBranches(final File repo) {
try {
final List<Ref> refs = Git.open(repo)
.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
final ArrayList<String> result = new ArrayList<>();
for (Ref ref : refs)
result.add(ref.getName());
return result;
} catch (GitAPIException | IOException e) {
e.printStackTrace();
}
return new ArrayList<>();
}
示例2: gitClone
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
/**
* Clone GIT repository from sourceforge.
*
* @param gitDirectory The directory of Git.
*/
private void gitClone(File gitDirectory) {
try {
git = Git.cloneRepository()
.setDirectory(gitDirectory)
.setURI("http://git.code.sf.net/p/neembuuuploader/gitcode")
.setProgressMonitor(new TextProgressMonitor()).call();
for (Ref f : git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call()) {
git.checkout().setName(f.getName()).call();
System.out.println("checked out branch " + f.getName()
+ ". HEAD: " + git.getRepository().getRef("HEAD"));
}
// try to checkout branches by specifying abbreviated names
git.checkout().setName("master").call();
} catch (GitAPIException | IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例3: gitClone
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
/**
* Clone GIT repository from sourceforge.
*
* @param gitDirectory The directory of Git.
*/
private void gitClone(File gitDirectory) {
try {
git = Git.cloneRepository()
.setDirectory(gitDirectory)
.setURI(env.gitURI())
//.setURI("http://git.code.sf.net/p/neembuuuploader/gitcode")
.setProgressMonitor(new TextProgressMonitor()).call();
for (Ref f : git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call()) {
git.checkout().setName(f.getName()).call();
System.out.println("checked out branch " + f.getName()
+ ". HEAD: " + git.getRepository().getRef("HEAD"));
}
// try to checkout branches by specifying abbreviated names
git.checkout().setName("master").call();
} catch (GitAPIException | IOException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
示例4: findBranches
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
List<GitBranch> findBranches() throws IOException {
Repository repository = getRepository();
List<GitBranch> result = new LinkedList<>();
try (Git git = new Git(repository)) {
List<Ref> branches = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
for (Ref branchRef : branches) {
GitBranch newBranch = new GitBranch (branchRef.getName(), ObjectId.toString(branchRef.getObjectId()));
result.add (newBranch);
}
} catch (GitAPIException e) {
throw new IllegalStateException("Could not read branches from Git repository '" + path + "'", e);
} finally {
repository.close();
}
return result;
}
示例5: setListMode
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
/**
* Sets the listing mode
*
* @antdoc.notrequired
* @param listMode - optional: corresponds to the -r/-a options; by default, only local branches will be listed
*/
public void setListMode(String listMode) {
if (!GitTaskUtils.isNullOrBlankString(listMode)) {
try {
this.listMode = ListBranchCommand.ListMode.valueOf(listMode);
}
catch (IllegalArgumentException e) {
ListBranchCommand.ListMode[] listModes = ListBranchCommand.ListMode.values();
List<String> listModeValidValues = new ArrayList<String>(listModes.length);
for (ListBranchCommand.ListMode aListMode : listModes) {
listModeValidValues.add(aListMode.name());
}
String validModes = listModeValidValues.toString();
throw new BuildException(String.format("Valid listMode options are: %s.", validModes));
}
}
}
示例6: containsBranch
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
private boolean containsBranch(Git git, String label, ListBranchCommand.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;
}
示例7: checkoutAllBranches
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
private void checkoutAllBranches(Repository repository) throws GitAPIException {
final Git git = Git.wrap(repository);
for (final Ref ref : git.branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call()) {
final String refName = ref.getName();
final String branchName = refName.substring(refName.lastIndexOf('/') + 1);
try {
git.checkout().setCreateBranch(true).setName(branchName).setStartPoint("origin/" + branchName).call();
} catch (RefAlreadyExistsException e) {
LOGGER.warning("Already exists, so ignoring " + e.getMessage());
}
}
}
示例8: doListBranches
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
protected List<String> doListBranches(Git git) throws Exception {
SortedSet<String> names = new TreeSet<String>();
List<Ref> call = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
for (Ref ref : call) {
String name = ref.getName();
int idx = name.lastIndexOf('/');
if (idx >= 0) {
name = name.substring(idx + 1);
}
if (name.length() > 0) {
names.add(name);
}
}
return new ArrayList<String>(names);
}
示例9: setBranchType
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
/**
* Determines whether to return local, remote, or all branches for {@code getBranches*()} related methods.
* @param branchList the branch list command
* @param branchType the type of branches to include
*/
private static void setBranchType(ListBranchCommand branchList, BranchType branchType) {
if (branchType.equals(BranchType.LOCAL)) {
// to get local branches, don't set list mode
return;
}
if (branchType.equals(BranchType.REMOTE)) {
branchList.setListMode(ListBranchCommand.ListMode.REMOTE);
} else {
branchList.setListMode(ListBranchCommand.ListMode.ALL);
}
}
示例10: containsBranch
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的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; //导入依赖的package包/类
/**
* getBranches.
*
* @return a {@link java.util.Set} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
*/
public Set<Branch> getBranches() throws GitException {
try (Repository repo = getRepository()) {
List<Ref> refs = git(repo).branchList().setListMode(ListBranchCommand.ListMode.ALL).call();
Set<Branch> branches = new HashSet<>(refs.size());
for (Ref ref : refs) {
branches.add(new Branch(ref));
}
return branches;
} catch (GitAPIException e) {
throw new GitException(e);
}
}
示例12: getRemoteBranches
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
/**
* getRemoteBranches.
*
* @return a {@link java.util.Set} object.
* @throws hudson.plugins.git.GitException if underlying git operation fails.
*/
public Set<Branch> getRemoteBranches() throws GitException {
try (Repository repo = getRepository()) {
List<Ref> refs = git(repo).branchList().setListMode(ListBranchCommand.ListMode.REMOTE).call();
Set<Branch> branches = new HashSet<>(refs.size());
for (Ref ref : refs) {
branches.add(new Branch(ref));
}
return branches;
} catch (GitAPIException e) {
throw new GitException(e);
}
}
示例13: isBranch
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
private boolean isBranch(Git git, String label) throws GitAPIException {
return containsBranch(git, label, ListBranchCommand.ListMode.ALL);
}
示例14: getBranches
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的package包/类
public static List<Ref> getBranches(Git git, BranchType branchType) throws GitAPIException {
ListBranchCommand branchList = git.branchList();
setBranchType(branchList, branchType);
return branchList.call();
}
示例15: branchList
import org.eclipse.jgit.api.ListBranchCommand; //导入依赖的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;
}