当前位置: 首页>>代码示例>>Java>>正文


Java GitRepository.getCurrentBranch方法代码示例

本文整理汇总了Java中git4idea.repo.GitRepository.getCurrentBranch方法的典型用法代码示例。如果您正苦于以下问题:Java GitRepository.getCurrentBranch方法的具体用法?Java GitRepository.getCurrentBranch怎么用?Java GitRepository.getCurrentBranch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git4idea.repo.GitRepository的用法示例。


在下文中一共展示了GitRepository.getCurrentBranch方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getCurrentBranch

import git4idea.repo.GitRepository; //导入方法依赖的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;
}
 
开发者ID:crowdin,项目名称:android-studio-plugin,代码行数:17,代码来源:Utils.java

示例2: pushCurrentBranch

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
private static boolean pushCurrentBranch(@NotNull Project project,
                                         @NotNull GitRepository repository,
                                         @NotNull String remoteName,
                                         @NotNull String remoteUrl,
                                         @NotNull String name,
                                         @NotNull String url) {
  Git git = ServiceManager.getService(Git.class);

  GitLocalBranch currentBranch = repository.getCurrentBranch();
  if (currentBranch == null) {
    GithubNotifications.showErrorURL(project, "Can't finish GitHub sharing process", "Successfully created project ", "'" + name + "'",
                                     " on GitHub, but initial push failed: no current branch", url);
    return false;
  }
  GitCommandResult result = git.push(repository, remoteName, remoteUrl, currentBranch.getName(), true);
  if (!result.success()) {
    GithubNotifications.showErrorURL(project, "Can't finish GitHub sharing process", "Successfully created project ", "'" + name + "'",
                                     " on GitHub, but initial push failed:<br/>" + result.getErrorOutputAsHtmlString(), url);
    return false;
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:GithubShareAction.java

示例3: isEnabled

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
@Override
public boolean isEnabled(@NotNull VcsLog log, @NotNull List<VcsFullCommitDetails> details) {
  if (details.isEmpty()) {
    return false;
  }
  for (VcsFullCommitDetails commit : details) {
    GitRepository repository = myPlatformFacade.getRepositoryManager(myProject).getRepositoryForRoot(commit.getRoot());
    if (repository == null) {
      return false;
    }
    GitLocalBranch currentBranch = repository.getCurrentBranch();
    Collection<String> containingBranches = log.getContainingBranches(commit.getId());
    if (currentBranch != null && containingBranches != null && containingBranches.contains(currentBranch.getName())) {
      // already is contained in the current branch
      return false;
    }
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:GitCherryPicker.java

示例4: getLocationFor

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
public RepositoryLocation getLocationFor(@NotNull FilePath root) {
  VirtualFile gitRoot = GitUtil.getGitRootOrNull(root);
  if (gitRoot == null) {
    return null;
  }
  GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(gitRoot);
  if (repository == null) {
    LOG.info("No GitRepository for " + gitRoot);
    return null;
  }
  GitLocalBranch currentBranch = repository.getCurrentBranch();
  if (currentBranch == null) {
    return null;
  }
  GitRemoteBranch trackedBranch = currentBranch.findTrackedBranch(repository);
  if (trackedBranch == null) {
    return null;
  }
  File rootFile = new File(gitRoot.getPath());
  return new GitRepositoryLocation(trackedBranch.getRemote().getFirstUrl(), rootFile);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:GitCommittedChangeListProvider.java

示例5: loadRefs

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
/**
 * Load tags and branches
 */
protected void loadRefs() {
  try {
    myLocalBranches.clear();
    myRemoteBranches.clear();
    myTags.clear();
    final VirtualFile root = gitRoot();
    GitRepository repository = GitUtil.getRepositoryManager(myProject).getRepositoryForRoot(root);
    if (repository != null) {
      myLocalBranches.addAll(repository.getBranches().getLocalBranches());
      myRemoteBranches.addAll(repository.getBranches().getRemoteBranches());
      myCurrentBranch = repository.getCurrentBranch();
    }
    else {
      LOG.error("Repository is null for root " + root);
    }
    GitTag.list(myProject, root, myTags);
  }
  catch (VcsException e) {
    GitUIUtil.showOperationError(myProject, e, "git branch -a");
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:GitRebaseDialog.java

示例6: getGitBranch

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
public static String getGitBranch(Project project) {
    GitRepositoryManager repositoryManager = ServiceManager.getService(project, GitRepositoryManager.class);

    if (repositoryManager.getRepositories().size() > 0) {
        GitRepository gitRepository = repositoryManager.getRepositories().get(0);
        GitLocalBranch branch = gitRepository.getCurrentBranch();
        if (branch != null) {
            return branch.getName();
        }
    }

    return StringUtils.EMPTY;
}
 
开发者ID:WesleyElliott,项目名称:IntelliJ-TimeTracker,代码行数:14,代码来源:RepoHelper.java

示例7: getDefaultTarget

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
@Nullable
@Override
public GitPushTarget getDefaultTarget(@NotNull GitRepository repository) {
  if (repository.isFresh()) {
    return null;
  }
  GitLocalBranch currentBranch = repository.getCurrentBranch();
  if (currentBranch == null) {
    return null;
  }

  GitPushTarget persistedTarget = getPersistedTarget(repository, currentBranch);
  if (persistedTarget != null) {
    return persistedTarget;
  }

  GitPushTarget pushSpecTarget = GitPushTarget.getFromPushSpec(repository, currentBranch);
  if (pushSpecTarget != null) {
    return pushSpecTarget;
  }

  GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, currentBranch);
  if (trackInfo != null) {
    return new GitPushTarget(trackInfo.getRemoteBranch(), false);
  }
  return proposeTargetForNewBranch(repository, currentBranch);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:28,代码来源:GitPushSupport.java

示例8: getSource

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
@NotNull
@Override
public GitPushSource getSource(@NotNull GitRepository repository) {
  GitLocalBranch currentBranch = repository.getCurrentBranch();
  return currentBranch != null
         ? GitPushSource.create(currentBranch)
         : GitPushSource.create(ObjectUtils.assertNotNull(repository.getCurrentRevision())); // fresh repository is on branch
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:GitPushSupport.java

示例9: checkTrackedBranchesConfigured

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
/**
 * For each root check that the repository is on branch, and this branch is tracking a remote branch,
 * and the remote branch exists.
 * If it is not true for at least one of roots, notify and return false.
 * If branch configuration is OK for all roots, return true.
 */
private boolean checkTrackedBranchesConfigured() {
  LOG.info("checking tracked branch configuration...");
  for (GitRepository repository : myRepositories) {
    VirtualFile root = repository.getRoot();
    final GitLocalBranch branch = repository.getCurrentBranch();
    if (branch == null) {
      LOG.info("checkTrackedBranchesConfigured: current branch is null in " + repository);
      notifyImportantError(myProject, "Can't update: no current branch",
                           "You are in 'detached HEAD' state, which means that you're not on any branch" +
                           rootStringIfNeeded(root) +
                           "Checkout a branch to make update possible.");
      return false;
    }
    GitBranchTrackInfo trackInfo = GitBranchUtil.getTrackInfoForBranch(repository, branch);
    if (trackInfo == null) {
      final String branchName = branch.getName();
      LOG.info(String.format("checkTrackedBranchesConfigured: no track info for current branch %s in %s", branch, repository));
      notifyImportantError(myProject, "Can't update: no tracked branch",
                           "No tracked branch configured for branch " + code(branchName) +
                           rootStringIfNeeded(root) +
                           "To make your branch track a remote branch call, for example,<br/>" +
                           "<code>git branch --set-upstream " + branchName + " origin/" + branchName + "</code>");
      return false;
    }
    myTrackedBranches.put(root, new GitBranchPair(branch, trackInfo.getRemoteBranch()));
  }
  return true;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:35,代码来源:GitUpdateProcess.java

示例10: getTrackInfoForCurrentBranch

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
/**
 * Returns the tracking information (remote and the name of the remote branch), or null if we are not on a branch.
 */
@Nullable
public static GitBranchTrackInfo getTrackInfoForCurrentBranch(@NotNull GitRepository repository) {
  GitLocalBranch currentBranch = repository.getCurrentBranch();
  if (currentBranch == null) {
    return null;
  }
  return GitBranchUtil.getTrackInfoForBranch(repository, currentBranch);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:GitUtil.java

示例11: getRepositories

import git4idea.repo.GitRepository; //导入方法依赖的package包/类
@NotNull
private Map<GitRepository, GitBranch> getRepositories(@NotNull Map<VirtualFile, VcsLogProvider> providers,
                                                      @NotNull String branchToCompare) {
  Map<GitRepository, GitBranch> repos = ContainerUtil.newHashMap();
  for (VirtualFile root : providers.keySet()) {
    GitRepository repository = myRepositoryManager.getRepositoryForRoot(root);
    if (repository == null || repository.getCurrentBranch() == null ||
        repository.getBranches().findBranchByName(branchToCompare) == null) {
      continue;
    }
    repos.put(repository, repository.getCurrentBranch());
  }
  return repos;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:15,代码来源:DeepComparator.java


注:本文中的git4idea.repo.GitRepository.getCurrentBranch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。