/** * Returns whether or not a specific named branch exists in the repo. */ private boolean isBranchExists(String ref) throws IOException { return (repo.getRef(ref) != null); }
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; }
@Override public ObjectId invoke(Repository repository) throws IOException, InterruptedException { return repository.getRef(head).getObjectId(); } }) : ObjectId.fromString(rev.getHash());
@Nullable public static Ref getBranchRef(@Nonnull String name, @Nonnull Repository repo) throws IOException { return repo.getRef(ensureBranchRefName(name)); }
private static boolean hasHead(Repository repo) { try { Ref headRef = repo.getRef(Constants.HEAD); return headRef != null && headRef.getObjectId() != null; } catch (IOException e) { return false; } }
public static boolean tagExists(@Nonnull String name, @Nonnull Repository repo) throws IOException { Ref tagRef = repo.getRef(RefUtils.ensureTagRefName(name)); return tagRef != null; }
@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; }
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()); }
@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; } } }
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)); }
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)); }
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; }
@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); }
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); } }
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; }
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); }
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(); } }
@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); } }
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(); } }
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(); } }