本文整理汇总了Java中git4idea.branch.GitBranchUtil类的典型用法代码示例。如果您正苦于以下问题:Java GitBranchUtil类的具体用法?Java GitBranchUtil怎么用?Java GitBranchUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GitBranchUtil类属于git4idea.branch包,在下文中一共展示了GitBranchUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: extractBranchName
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
public static String extractBranchName(Project project) {
String branch = "";
ProjectLevelVcsManager instance = ProjectLevelVcsManagerImpl.getInstance(project);
if (instance.checkVcsIsActive("Git")) {
GitLocalBranch currentBranch = GitBranchUtil.getCurrentRepository(project).getCurrentBranch();
if (currentBranch != null) {
// Branch name matches Ticket Name
branch = currentBranch.getName().trim();
}
} else if (instance.checkVcsIsActive("Mercurial")) {
branch = HgUtil.getCurrentRepository(project).getCurrentBranch().trim();
}
return branch;
}
示例2: getCurrentBranch
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
public static String getCurrentBranch(@NotNull final Project project) {
GitRepository repository;
GitLocalBranch localBranch;
String branchName = "";
try {
repository = GitBranchUtil.getCurrentRepository(project);
localBranch = repository.getCurrentBranch();
branchName = localBranch.getName();
} catch (Exception e) {
e.getMessage();
}
if (branchName == null) {
branchName = "";
}
return branchName;
}
示例3: mergeCommit
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
public void mergeCommit(VirtualFile root) throws VcsException {
GitSimpleHandler handler = new GitSimpleHandler(myProject, root, GitCommand.COMMIT);
handler.setStdoutSuppressed(false);
File gitDir = new File(VfsUtilCore.virtualToIoFile(root), GitUtil.DOT_GIT);
File messageFile = new File(gitDir, GitRepositoryFiles.MERGE_MSG);
if (!messageFile.exists()) {
final GitBranch branch = GitBranchUtil.getCurrentBranch(myProject, root);
final String branchName = branch != null ? branch.getName() : "";
handler.addParameters("-m", "Merge branch '" + branchName + "' of " + root.getPresentableUrl() + " with conflicts.");
} else {
handler.addParameters("-F", messageFile.getAbsolutePath());
}
handler.endOptions();
handler.run();
}
示例4: refreshStashList
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
private void refreshStashList() {
final DefaultListModel listModel = (DefaultListModel)myStashList.getModel();
listModel.clear();
VirtualFile root = getGitRoot();
GitStashUtils.loadStashStack(myProject, root, new Consumer<StashInfo>() {
@Override
public void consume(StashInfo stashInfo) {
listModel.addElement(stashInfo);
}
});
myBranches.clear();
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
if (repository != null) {
myBranches.addAll(GitBranchUtil.convertBranchesToNames(repository.getBranches().getLocalBranches()));
}
else {
LOG.error("Repository is null for root " + root);
}
myStashList.setSelectedIndex(0);
}
示例5: setCurrentBranchInfo
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
@Override
protected void setCurrentBranchInfo() {
String currentBranchText = "Current branch";
if (myRepositoryManager.moreThanOneRoot()) {
if (myMultiRootBranchConfig.diverged()) {
currentBranchText += " in " + DvcsUtil.getShortRepositoryName(myCurrentRepository) + ": " +
GitBranchUtil.getDisplayableBranchText(myCurrentRepository);
}
else {
currentBranchText += ": " + myMultiRootBranchConfig.getCurrentBranch();
}
}
else {
currentBranchText += ": " + GitBranchUtil.getDisplayableBranchText(myCurrentRepository);
}
myPopup.setAdText(currentBranchText, SwingConstants.CENTER);
}
示例6: given
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
@NotNull
protected Collection<VcsRef> given(@NotNull String... refs) throws IOException {
Collection<VcsRef> result = ContainerUtil.newArrayList();
cd(myProjectRoot);
Hash hash = HashImpl.build(git("rev-parse HEAD"));
for (String refName : refs) {
if (isHead(refName)) {
result.add(ref(hash, "HEAD", GitRefManager.HEAD));
}
else if (isRemoteBranch(refName)) {
git("update-ref refs/remotes/" + refName + " " + hash.asString());
result.add(ref(hash, refName, GitRefManager.REMOTE_BRANCH));
}
else if (isTag(refName)) {
git("update-ref " + refName + " " + hash.asString());
result.add(ref(hash, GitBranchUtil.stripRefsPrefix(refName), GitRefManager.TAG));
}
else {
git("update-ref refs/heads/" + refName + " " + hash.asString());
result.add(ref(hash, refName, GitRefManager.LOCAL_BRANCH));
}
}
setUpTracking(result);
myRepo.update();
return result;
}
示例7: expect
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
@NotNull
protected List<VcsRef> expect(@NotNull String... refNames) {
final Set<VcsRef> refs = GitTestUtil.readAllRefs(myProjectRoot, ServiceManager.getService(myProject, VcsLogObjectsFactory.class));
return ContainerUtil.map2List(refNames, new Function<String, VcsRef>() {
@Override
public VcsRef fun(@NotNull final String refName) {
VcsRef item = ContainerUtil.find(refs, new Condition<VcsRef>() {
@Override
public boolean value(VcsRef ref) {
return ref.getName().equals(GitBranchUtil.stripRefsPrefix(refName));
}
});
assertNotNull("Ref " + refName + " not found among " + refs, item);
return item;
}
});
}
示例8: pushSpecsForCurrentOrEnteredBranches
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
private Map<GitRepository, GitPushSpec> pushSpecsForCurrentOrEnteredBranches() throws VcsException {
Map<GitRepository, GitPushSpec> defaultSpecs = new HashMap<GitRepository, GitPushSpec>();
for (GitRepository repository : myRepositories) {
GitLocalBranch currentBranch = repository.getCurrentBranch();
if (currentBranch == null) {
continue;
}
String remoteName = GitBranchUtil.getTrackedRemoteName(repository.getProject(), repository.getRoot(), currentBranch.getName());
String trackedBranchName = GitBranchUtil.getTrackedBranchName(repository.getProject(), repository.getRoot(), currentBranch.getName());
GitRemote remote = GitUtil.findRemoteByName(repository, remoteName);
GitRemoteBranch targetBranch;
if (remote != null && trackedBranchName != null) {
targetBranch = GitBranchUtil.findRemoteBranchByName(trackedBranchName, remote.getName(),
repository.getBranches().getRemoteBranches());
}
else {
Pair<GitRemote, GitRemoteBranch> remoteAndBranch = GitUtil.findMatchingRemoteBranch(repository, currentBranch);
if (remoteAndBranch == null) {
targetBranch = GitPusher.NO_TARGET_BRANCH;
} else {
targetBranch = remoteAndBranch.getSecond();
}
}
if (myRefspecPanel.turnedOn()) {
String manualBranchName = myRefspecPanel.getBranchToPush();
remote = myRefspecPanel.getSelectedRemote();
GitRemoteBranch manualBranch = GitBranchUtil.findRemoteBranchByName(manualBranchName, remote.getName(),
repository.getBranches().getRemoteBranches());
if (manualBranch == null) {
manualBranch = new GitStandardRemoteBranch(remote, manualBranchName, GitBranch.DUMMY_HASH);
}
targetBranch = manualBranch;
}
GitPushSpec pushSpec = new GitPushSpec(currentBranch, targetBranch == null ? GitPusher.NO_TARGET_BRANCH : targetBranch);
defaultSpecs.put(repository, pushSpec);
}
return defaultSpecs;
}
示例9: readUnpackedRemoteBranches
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
/**
* @return list of branches from refs/remotes.
* @param remotes
*/
@NotNull
private Set<GitRemoteBranch> readUnpackedRemoteBranches(@NotNull final Collection<GitRemote> remotes) {
final Set<GitRemoteBranch> branches = new HashSet<GitRemoteBranch>();
if (!myRefsRemotesDir.exists()) {
return branches;
}
FileUtil.processFilesRecursively(myRefsRemotesDir, new Processor<File>() {
@Override
public boolean process(File file) {
if (!file.isDirectory()) {
final String relativePath = FileUtil.getRelativePath(myGitDir, file);
if (relativePath != null) {
String branchName = FileUtil.toSystemIndependentName(relativePath);
String hash = loadHashFromBranchFile(file);
GitRemoteBranch remoteBranch = GitBranchUtil.parseRemoteBranch(branchName, createHash(hash), remotes);
if (remoteBranch != null) {
branches.add(remoteBranch);
}
}
}
return true;
}
});
return branches;
}
示例10: refreshStashList
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
/**
* Refresh stash list
*/
private void refreshStashList() {
final DefaultListModel listModel = (DefaultListModel)myStashList.getModel();
listModel.clear();
VirtualFile root = getGitRoot();
GitStashUtils.loadStashStack(myProject, root, new Consumer<StashInfo>() {
@Override
public void consume(StashInfo stashInfo) {
listModel.addElement(stashInfo);
}
});
myBranches.clear();
GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
if (repository != null) {
myBranches.addAll(GitBranchUtil.convertBranchesToNames(repository.getBranches().getLocalBranches()));
}
else {
LOG.error("Repository is null for root " + root);
}
myStashList.setSelectedIndex(0);
}
示例11: update
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
private void update() {
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
Project project = getProject();
if (project == null) {
emptyTextAndTooltip();
return;
}
GitRepository repo = GitBranchUtil.getCurrentRepository(project);
if (repo == null) { // the file is not under version control => display nothing
emptyTextAndTooltip();
return;
}
int maxLength = myMaxString.length() - 1; // -1, because there are arrows indicating that it is a popup
myText = StringUtil.shortenTextWithEllipsis(GitBranchUtil.getDisplayableBranchText(repo), maxLength, 5);
myTooltip = getDisplayableBranchTooltip(repo);
myStatusBar.updateWidget(ID());
mySettings.setRecentRoot(repo.getRoot().getPath());
}
});
}
示例12: setCurrentBranchInfo
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
private void setCurrentBranchInfo() {
String currentBranchText = "Current branch";
if (myRepositoryManager.moreThanOneRoot()) {
if (myMultiRootBranchConfig.diverged()) {
currentBranchText += " in " + DvcsUtil.getShortRepositoryName(myCurrentRepository) + ": " +
GitBranchUtil.getDisplayableBranchText(myCurrentRepository);
}
else {
currentBranchText += ": " + myMultiRootBranchConfig.getCurrentBranch();
}
}
else {
currentBranchText += ": " + GitBranchUtil.getDisplayableBranchText(myCurrentRepository);
}
myPopup.setAdText(currentBranchText, SwingConstants.CENTER);
}
示例13: getCommonBranches
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
@NotNull
private Collection<String> getCommonBranches(boolean local) {
Collection<String> commonBranches = null;
for (GitRepository repository : myRepositories) {
GitBranchesCollection branchesCollection = repository.getBranches();
Collection<String> names = local
? GitBranchUtil.convertBranchesToNames(branchesCollection.getLocalBranches())
: GitBranchUtil.getBranchNamesWithoutRemoteHead(branchesCollection.getRemoteBranches());
if (commonBranches == null) {
commonBranches = names;
}
else {
commonBranches.retainAll(names);
}
}
if (commonBranches != null) {
ArrayList<String> common = new ArrayList<String>(commonBranches);
Collections.sort(common);
return common;
}
else {
return Collections.emptyList();
}
}
示例14: actionPerformed
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
@Override
public void actionPerformed(AnActionEvent e) {
final int[] selectedRows = myJBTable.getSelectedRows();
if (selectedRows.length != 1) return;
final CommitI commitAt = myTableModel.getCommitAt(selectedRows[0]);
if (commitAt.holdsDecoration() || myTableModel.isStashed(commitAt)) return;
final GitRepository repository =
GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(commitAt.selectRepository(myRootsUnderVcs));
if (repository == null) return;
String reference = commitAt.getHash().getString();
final String name = GitBranchUtil
.getNewBranchNameFromUser(myProject, Collections.singleton(repository), "Checkout New Branch From " + reference);
if (name != null) {
GitBrancher brancher = ServiceManager.getService(myProject, GitBrancher.class);
brancher.checkoutNewBranchStartingFrom(name, reference, Collections.singletonList(repository), myRefresh);
}
}
示例15: formTagDescription
import git4idea.branch.GitBranchUtil; //导入依赖的package包/类
@Nullable
private static String formTagDescription(@NotNull List<String> pushedTags, @NotNull String remoteName) {
if (pushedTags.isEmpty()) {
return null;
}
if (pushedTags.size() == 1) {
return "tag " + GitBranchUtil.stripRefsPrefix(pushedTags.get(0)) + " to " + remoteName;
}
return pushedTags.size() + " tags to " + remoteName;
}