org.eclipse.jgit.lib.Repository.getBranch()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(7.7k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中org.eclipse.jgit.lib.Repository.getBranch方法的一些代码示例,展示了Repository.getBranch的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Repository.getBranch方法的具体详情如下:
包路径:org.eclipse.jgit.lib.Repository
类名称:Repository
方法名:getBranch

Repository.getBranch介绍

[英]Get the short name of the current branch that HEAD points to.

This is essentially the same as #getFullBranch(), except the leading prefix refs/heads/ is removed from the reference before it is returned to the caller.
[中]获取HEAD指向的当前分支的短名称。
这基本上与#getFullBranch()相同,只是在引用返回给调用方之前,前导前缀refs/heads/已从引用中移除。

代码示例

代码示例来源:origin: gocd/gocd

void cleanAndResetToMaster() throws IOException {
  try {
    git.reset().setMode(ResetCommand.ResetType.HARD).call();
    checkout("master");
    deleteBranch(BRANCH_AT_REVISION);
    deleteBranch(BRANCH_AT_HEAD);
  } catch (Exception e) {
    String currentBranch = git.getRepository().getBranch();
    LOGGER.error("Error while trying to clean up config repository, CurrentBranch: {} \n : \n Message: {} \n StackTrace: {}", currentBranch, e.getMessage(), e.getStackTrace(), e);
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: jphp-group/jphp

@Signature
public String getBranch() throws IOException {
  return getWrappedObject().getRepository().getBranch();
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldSwitchToMasterAndDeleteTempBranches() throws Exception, GitAPIException {
  configRepo.checkin(goConfigRevision("v1", "md5-1"));
  configRepo.createBranch(ConfigRepository.BRANCH_AT_HEAD, configRepo.getCurrentRevCommit());
  configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit());
  configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call();
  assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION));
  assertThat(configRepo.git().branchList().call().size(), is(3));
  configRepo.cleanAndResetToMaster();
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldCleanAndResetToMasterDuringInitialization() throws Exception {
  configRepo.checkin(goConfigRevision("v1", "md5-1"));
  configRepo.createBranch(ConfigRepository.BRANCH_AT_REVISION, configRepo.getCurrentRevCommit());
  configRepo.git().checkout().setName(ConfigRepository.BRANCH_AT_REVISION).call();
  assertThat(configRepo.git().getRepository().getBranch(), is(ConfigRepository.BRANCH_AT_REVISION));
  new ConfigRepository(systemEnvironment).initialize();
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

代码示例来源:origin: gocd/gocd

@Test
public void shouldCleanAndResetToMasterOnceMergeFlowIsComplete() throws Exception {
  String original = "first\nsecond\n";
  String changeOnBranch = "first\nsecond\nthird\n";
  String changeOnMaster = "1st\nsecond\n";
  String oldMd5 = "md5-1";
  configRepo.checkin(goConfigRevision(original, oldMd5));
  configRepo.checkin(goConfigRevision(changeOnMaster, "md5-2"));
  configRepo.getConfigMergedWithLatestRevision(goConfigRevision(changeOnBranch, "md5-3"), oldMd5);
  assertThat(configRepo.git().getRepository().getBranch(), is("master"));
  assertThat(configRepo.git().branchList().call().size(), is(1));
}

代码示例来源:origin: git-commit-id/maven-git-commit-id-plugin

@Override
public String getBranchName() throws GitCommitIdExecutionException {
 try {
  return git.getBranch();
 } catch (IOException e) {
  throw new GitCommitIdExecutionException(e);
 }
}

代码示例来源:origin: yacy/yacy_grid_mcp

public GitTool() {
  File gitWorkDir = new File(".");
  try {
    Git git = Git.open(gitWorkDir);
    Iterable<RevCommit> commits = git.log().all().call();
    Repository repo = git.getRepository();
    branch = repo.getBranch();
    RevCommit latestCommit = commits.iterator().next();
    name = latestCommit.getName();
    message = latestCommit.getFullMessage();
  } catch (Throwable e) {
    name = "";
    message = "";
    branch = "";
  }
}

代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit

/**
 * Get merge configuration for the current branch of the repository
 *
 * @param repo
 *            a {@link org.eclipse.jgit.lib.Repository} object.
 * @return merge configuration for the current branch of the repository
 */
public static MergeConfig getConfigForCurrentBranch(Repository repo) {
  try {
    String branch = repo.getBranch();
    if (branch != null)
      return repo.getConfig().get(getParser(branch));
  } catch (IOException e) {
    // ignore
  }
  // use defaults if branch can't be determined
  return new MergeConfig();
}

代码示例来源:origin: org.eclipse.egit/ui

private String getBranch() {
  try {
    return repository.getBranch();
  } catch (IOException e) {
    return null;
  }
}

代码示例来源:origin: io.fabric8.forge/fabric8-forge-core

public String currentBranch(Git git) {
  try {
    return git.getRepository().getBranch();
  } catch (IOException e) {
    LOG.warn("Failed to get the current branch due: " + e.getMessage() + ". This exception is ignored.", e);
    return null;
  }
}

代码示例来源:origin: org.eclipse.egit/ui

private String getCurrentBranch(Repository repository) throws ExecutionException {
    try {
      return repository.getBranch();
    } catch (IOException e) {
      throw new ExecutionException(UIText.RebaseCurrentRefCommand_ErrorGettingCurrentBranchMessage, e);
    }
  }
}

代码示例来源:origin: org.jboss.forge.addon/git-impl

@Override
public String getCurrentBranchName(final Git repo) throws IOException
{
 return repo.getRepository().getBranch();
}

代码示例来源:origin: org.apereo.cas/cas-mgmt-support-version-control

/**
 * Returns the name of the current branch in the repository.
 *
 * @return - the name of the branch.
 * @throws IOException - failed
 */
public String currentBranchName() throws IOException {
  return git.getRepository().getBranch();
}

代码示例来源:origin: org.eclipse.egit/ui

private void fillValues(final Repository repository) throws IOException {
  gitDir.setText(repository.getDirectory().getAbsolutePath());
  branch.setText(repository.getBranch());
  workDir.setText(repository.getWorkTree().getAbsolutePath());
  state.setText(repository.getRepositoryState().getDescription());
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-contract-stub-runner

private String currentBranch(File projectDir) {
  Git git = this.gitFactory.open(projectDir);
  try {
    return git.getRepository().getBranch();
  }
  catch (IOException e) {
    throw new IllegalStateException(e);
  }
  finally {
    git.close();
  }
}

代码示例来源:origin: gradle.plugin.ru.rambler.jiratasksupdater/jiraTaskUpdater

public void init(String jiraProjectId, Logger logger) throws IOException {
  // Open an existing repository
  existingRepo = new FileRepositoryBuilder()
      .setGitDir(new File(".git"))
      .build();
  logger.quiet("Current branch " + existingRepo.getBranch());
  this.logger = logger;
  this.smartCommitPattern = Pattern.compile(".*(" + jiraProjectId + "-\\d*).*");
}

代码示例来源:origin: beijunyi/ParallelGit

@Test
public void attachHeadToNewBranch_theRepositoryHeadShouldBecomeTheSpecifiedBranch() throws IOException {
 RepositoryUtils.attachRepositoryHead(repo, "refs/heads/new_branch");
 assertEquals("new_branch", repo.getBranch());
}

代码示例来源:origin: org.jboss.forge.addon/git-impl

@Override
public List<String> getLogForBranch(final Git repo, String branchName) throws GitAPIException,
    IOException
{
 String oldBranch = repo.getRepository().getBranch();
 repo.checkout().setName(branchName).call();
 List<String> results = getLogForCurrentBranch(repo);
 repo.checkout().setName(oldBranch).call();
 return results;
}

代码示例来源:origin: beijunyi/ParallelGit

@Test
public void deleteOrphanBranch_orphanBranchShouldNotBeAffected() throws IOException {
 RepositoryUtils.setRepositoryHead(repo, "orphan_branch");
 BranchUtils.deleteBranch("orphan_branch", repo);
 assertEquals("orphan_branch", repo.getBranch());
}

代码示例来源:origin: beijunyi/ParallelGit

@Test
public void setHeadToCommit_theRepositoryHeadShouldDetachToTheSpecifiedCommit() throws IOException {
 writeSomethingToCache();
 AnyObjectId commitId = commitToMaster();
 RepositoryUtils.setRepositoryHead(repo, commitId.getName());
 assertEquals(commitId.getName(), repo.getBranch());
}

相关文章

Repository类方法