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

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

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

Repository.getRef介绍

[英]Get a ref by name.
[中]通过名字获得参考。

代码示例

代码示例来源:origin: google/git-appraise-eclipse

/**
 * Returns whether or not a specific named branch exists in the repo.
 */
private boolean isBranchExists(String ref) throws IOException {
 return (repo.getRef(ref) != null);
}

代码示例来源:origin: Verigreen/verigreen

public Ref getRef(String ref) {
  
  Ref ans = null;
  try {
    ans = _repo.getRef(ref);
  } catch (Throwable e) {
    throw new RuntimeException(String.format("Failed retrieving ref of [%s]", ref), e);
  }
  
  return ans;
}

代码示例来源:origin: org.jenkins-ci.plugins/git

@Override
  public ObjectId invoke(Repository repository) throws IOException, InterruptedException {
    return repository.getRef(head).getObjectId();
  }
}) : ObjectId.fromString(rev.getHash());

代码示例来源:origin: com.beijunyi.parallelgit/parallelgit-utils

@Nullable
public static Ref getBranchRef(@Nonnull String name, @Nonnull Repository repo) throws IOException {
 return repo.getRef(ensureBranchRefName(name));
}

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

private static boolean hasHead(Repository repo) {
  try {
    Ref headRef = repo.getRef(Constants.HEAD);
    return headRef != null && headRef.getObjectId() != null;
  } catch (IOException e) {
    return false;
  }
}

代码示例来源:origin: com.beijunyi.parallelgit/parallelgit-utils

public static boolean tagExists(@Nonnull String name, @Nonnull Repository repo) throws IOException {
 Ref tagRef = repo.getRef(RefUtils.ensureTagRefName(name));
 return tagRef != null;
}

代码示例来源:origin: com.beijunyi.parallelgit/parallelgit-utils

@Nullable
public static RevTag getTag(@Nonnull String tagName, @Nonnull Repository repo) throws IOException {
 Ref tagRef = repo.getRef(RefUtils.ensureTagRefName(tagName));
 return tagRef != null ? getTag(tagRef, repo) : null;
}

代码示例来源:origin: stackoverflow.com

Repository repo = ...

RevWalk walk = new RevWalk(repo);
NoteMap map = NoteMap.newEmptyMap();
Ref ref = repo.getRef("refs/notes/commits");

if (ref != null) {
 RevCommit notesCommit = walk.parseCommit(ref.getObjectId());
 map = NoteMap.read(walk.getObjectReader(), notesCommit);
 map.getNote(notesCommit.getId());
}

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

@Override
  public boolean isEnabled() {
    try {
      Repository repository = getRepository();
      return repository != null
          && repository.getRef(Constants.HEAD).getObjectId() != null;
    } catch (IOException e) {
      Activator.handleError(e.getMessage(), e, false);
      return false;
    }
  }
}

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

private void addNoteMap(String notesRef) throws IOException {
  Ref notes = db.getRef(notesRef);
  if (notes == null)
    return;
  RevCommit notesCommit = argWalk.parseCommit(notes.getObjectId());
  noteMaps.put(notesRef,
      NoteMap.read(argWalk.getObjectReader(), notesCommit));
}

代码示例来源:origin: com.beijunyi.parallelgit/parallelgit-utils

public static void setRepositoryHead(@Nonnull Repository repo, @Nonnull String name) throws IOException {
 Ref ref = repo.getRef(name);
 if(ref != null) {
  if(!ref.getName().startsWith(Constants.R_HEADS))
   detachRepositoryHead(repo, repo.resolve(name));
  else
   attachRepositoryHead(repo, ref);
 } else
  attachRepositoryHead(repo, RefUtils.ensureBranchRefName(name));
}

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

private String getRealBranchName(Repository repo) {
  Ref ref;
  try {
    ref = repo.getRef(HEAD);
  } catch (IOException e) {
    ref = null;
  }
  if (ref != null && ref.isSymbolic())
    return ref.getTarget().getName();
  else
    return HEAD;
}

代码示例来源:origin: com.beijunyi.parallelgit/parallelgit-utils

@Nonnull
public static Ref createTag(@Nonnull AnyObjectId tagId, @Nonnull String name, @Nonnull Repository repo) throws IOException {
 String refName = RefUtils.ensureTagRefName(name);
 if(tagExists(name, repo))
  throw new TagAlreadyExistsException(refName);
 RefUpdate update = repo.updateRef(refName);
 update.setNewObjectId(tagId);
 update.setRefLogMessage("tagged " + name, false);
 RefUpdateValidator.validate(update.update());
 return repo.getRef(refName);
}

代码示例来源:origin: google/git-appraise-eclipse

private AbstractTreeIterator prepareTreeParser(String ref)
  throws IOException, MissingObjectException, IncorrectObjectTypeException {
 // from the commit we can build the tree which allows us to construct the TreeParser
 Ref head = repo.getRef(ref);
 try (RevWalk walk = new RevWalk(repo)) {
  RevCommit commit = walk.parseCommit(head.getObjectId());
  return prepareTreeParserHelper(walk, commit);
 }
}

代码示例来源:origin: airlift/airship

public Bundle getActiveBundle()
    throws IOException
{
  String currentBranch = git.getRepository().getRef(Constants.HEAD).getTarget().getName();
  if (currentBranch != null) {
    return getBundle(Repository.shortenRefName(currentBranch));
  }
  // TODO: ensure branch is not "template" or "master"
  return null;
}

代码示例来源:origin: airlift/airship

public Bundle createBundle(String name)
    throws IOException, InvalidRefNameException, RefNotFoundException, RefAlreadyExistsException
{
  Ref templateBranch = git.getRepository().getRef(TEMPLATE_BRANCH);
  Preconditions.checkNotNull(templateBranch, "'%s' branch not found", TEMPLATE_BRANCH);
  RevCommit templateCommit = GitUtils.getCommit(git.getRepository(), templateBranch);
  git.branchCreate()
      .setName(name)
      .setStartPoint(templateCommit)
      .call();
  return getBundle(name);
}

代码示例来源:origin: robinst/git-merge-repos

private void resetToBranch() throws IOException, GitAPIException {
  Ref master = repository.getRef(Constants.R_HEADS + "master");
  if (master != null) {
    Git git = new Git(repository);
    git.reset().setMode(ResetType.HARD).setRef(master.getName()).call();
  }
}

代码示例来源:origin: indeedeng/proctor

@Override
public String getLatestVersion() throws StoreException {
  try {
    final Ref branch = git.getRepository().getRef(getGitCore().getRefName());
    return branch.getObjectId().name();
  } catch (IOException e) {
    throw new StoreException(e);
  }
}

代码示例来源:origin: danielflower/multi-module-maven-release-plugin

public boolean hasChangedSince(String modulePath, java.util.List<String> childModules, Collection<AnnotatedTag> tags) throws IOException {
  RevWalk walk = new RevWalk(repo);
  try {
    walk.setRetainBody(false);
    walk.markStart(walk.parseCommit(repo.getRef("HEAD").getObjectId()));
    filterOutOtherModulesChanges(modulePath, childModules, walk);
    stopWalkingWhenTheTagsAreHit(tags, walk);
    return walk.iterator().hasNext();
  } finally {
    walk.dispose();
  }
}

代码示例来源:origin: google/git-appraise-eclipse

private void loadBase() throws IOException {
 Ref notesBranch = repo.getRef(ref);
 if (notesBranch != null) {
  baseCommit = revWalk.parseCommit(notesBranch.getObjectId());
  base = NoteMap.read(revWalk.getObjectReader(), baseCommit);
 }
 if (baseCommit != null) {
  ours = NoteMap.read(repo.newObjectReader(), baseCommit);
 } else {
  ours = NoteMap.newEmptyMap();
 }
}

相关文章

Repository类方法