String originalBranch = repo.getFullBranch();
boolean empty = repo.resolve(Constants.HEAD) == null;
if (!empty) {
- if (repo.getRef(branch) == null)
+ if (repo.findRef(branch) == null)
git.branchCreate().setName(branch).call();
git.checkout().setName(branch).call();
}
*/
public CommitBuilder amendRef(String ref) throws Exception {
String name = normalizeRef(ref);
- Ref r = db.getRef(name);
+ Ref r = db.exactRef(name);
if (r == null)
throw new IOException("Not a ref: " + ref);
return amend(pool.parseCommit(r.getObjectId()), branch(name).commit());
RevCommit parent = commit.getParent(0);
pool.parseHeaders(parent);
- Ref headRef = db.getRef(Constants.HEAD);
+ Ref headRef = db.exactRef(Constants.HEAD);
if (headRef == null)
throw new IOException("Missing HEAD");
RevCommit head = pool.parseCommit(headRef.getObjectId());
CommitBuilder(BranchBuilder b) throws Exception {
branch = b;
- Ref ref = db.getRef(branch.ref);
+ Ref ref = db.exactRef(branch.ref);
if (ref != null && ref.getObjectId() != null)
parent(pool.parseCommit(ref.getObjectId()));
}
if (rename) {
String src, dst;
if (otherBranch == null) {
- final Ref head = db.getRef(Constants.HEAD);
+ final Ref head = db.exactRef(Constants.HEAD);
if (head != null && head.isSymbolic()) {
src = head.getLeaf().getName();
} else {
dst = branch;
} else {
src = branch;
- final Ref old = db.getRef(src);
+ final Ref old = db.findRef(src);
if (old == null)
throw die(MessageFormat.format(CLIText.get().doesNotExist, src));
if (!old.getName().startsWith(Constants.R_HEADS))
} else {
startBranch = Constants.HEAD;
}
- Ref startRef = db.getRef(startBranch);
+ Ref startRef = db.findRef(startBranch);
ObjectId startAt = db.resolve(startBranch + "^0"); //$NON-NLS-1$
if (startRef != null) {
startBranch = startRef.getName();
}
private void list() throws Exception {
- Ref head = db.getRef(Constants.HEAD);
+ Ref head = db.exactRef(Constants.HEAD);
// This can happen if HEAD is stillborn
if (head != null) {
String current = head.getLeaf().getName();
commitCmd.setOnly(p);
commitCmd.setAmend(amend);
commitCmd.setAll(all);
- Ref head = db.getRef(Constants.HEAD);
+ Ref head = db.exactRef(Constants.HEAD);
if (head == null) {
throw die(CLIText.get().onBranchToBeBorn);
}
}
private void addNoteMap(String notesRef) throws IOException {
- Ref notes = db.getRef(notesRef);
+ Ref notes = db.exactRef(notesRef);
if (notes == null)
return;
RevCommit notesCommit = argWalk.parseCommit(notes.getObjectId());
}
// determine the other revision we want to merge with HEAD
- final Ref srcRef = db.getRef(ref);
+ final Ref srcRef = db.findRef(ref);
final ObjectId src = db.resolve(ref + "^{commit}"); //$NON-NLS-1$
if (src == null)
throw die(MessageFormat.format(
}
private Ref getOldHead() throws IOException {
- Ref oldHead = db.getRef(Constants.HEAD);
+ Ref oldHead = db.exactRef(Constants.HEAD);
if (oldHead == null) {
throw die(CLIText.get().onBranchToBeBorn);
}
private void printLongStatus(org.eclipse.jgit.api.Status status)
throws IOException {
// Print current branch name
- final Ref head = db.getRef(Constants.HEAD);
+ final Ref head = db.exactRef(Constants.HEAD);
if (head != null && head.isSymbolic()) {
String branch = Repository.shortenRefName(head.getLeaf().getName());
outw.println(CLIText.formatLine(MessageFormat.format(
* @throws IOException
*/
private void assertSameAsHead(Ref ref) throws IOException {
- Ref headRef = db.getRef(Constants.HEAD);
+ Ref headRef = db.exactRef(Constants.HEAD);
assertEquals(headRef.getName(), ref.getName());
assertEquals(headRef.getObjectId(), ref.getObjectId());
}
RevCommit notesCommit = null;
try (RevWalk walk = new RevWalk(repo);
ObjectInserter inserter = repo.newObjectInserter()) {
- Ref ref = repo.getRef(notesRef);
+ Ref ref = repo.findRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
notesCommit = walk.parseCommit(ref.getObjectId());
}
}
- Ref headRef = repo.getRef(Constants.HEAD);
+ Ref headRef = repo.exactRef(Constants.HEAD);
if (headRef == null) {
// TODO Git CLI supports checkout from unborn branch, we should
// also allow this
JGitText.get().checkoutUnexpectedResult,
r.name()));
this.status = CheckoutResult.NOT_TRIED_RESULT;
- return repo.getRef(Constants.HEAD);
+ return repo.exactRef(Constants.HEAD);
}
branch = getStartPointObjectId();
} else {
} finally {
dc.unlock();
}
- Ref ref = repo.getRef(name);
+ Ref ref = repo.findRef(name);
if (ref != null && !ref.getName().startsWith(Constants.R_HEADS))
ref = null;
String toName = Repository.shortenRefName(name);
updateResult = refUpdate.link(ref.getName());
else if (orphan) {
updateResult = refUpdate.link(getBranchName());
- ref = repo.getRef(Constants.HEAD);
+ ref = repo.exactRef(Constants.HEAD);
} else {
refUpdate.setNewObjectId(newCommit);
updateResult = refUpdate.forceUpdate();
.get().branchNameInvalid, name == null ? "<null>" : name)); //$NON-NLS-1$
if (orphan) {
- Ref refToCheck = repo.getRef(getBranchName());
+ Ref refToCheck = repo.exactRef(getBranchName());
if (refToCheck != null)
throw new RefAlreadyExistsException(MessageFormat.format(
JGitText.get().refAlreadyExists, name));
try (RevWalk revWalk = new RevWalk(repo)) {
// get the head commit
- Ref headRef = repo.getRef(Constants.HEAD);
+ Ref headRef = repo.exactRef(Constants.HEAD);
if (headRef == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
}
}
- Ref head = repo.getRef(Constants.HEAD);
+ Ref head = repo.exactRef(Constants.HEAD);
if (head == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
checkCallable();
processOptions();
try (RevWalk revWalk = new RevWalk(repo)) {
- Ref refToCheck = repo.getRef(name);
+ Ref refToCheck = repo.findRef(name);
boolean exists = refToCheck != null
&& refToCheck.getName().startsWith(Constants.R_HEADS);
if (!force && exists)
ObjectId startAt = getStartPointObjectId();
String startPointFullName = null;
if (startPoint != null) {
- Ref baseRef = repo.getRef(startPoint);
+ Ref baseRef = repo.findRef(startPoint);
if (baseRef != null)
startPointFullName = baseRef.getName();
}
.get().createBranchUnexpectedResult, updateResult
.name()));
- Ref result = repo.getRef(name);
+ Ref result = repo.findRef(name);
if (result == null)
throw new JGitInternalException(
JGitText.get().createBranchFailedUnknownReason);
for (String branchName : branchNames) {
if (branchName == null)
continue;
- Ref currentRef = repo.getRef(branchName);
+ Ref currentRef = repo.findRef(branchName);
if (currentRef == null)
continue;
for (String branchName : branchNames) {
if (branchName == null)
continue;
- Ref currentRef = repo.getRef(branchName);
+ Ref currentRef = repo.findRef(branchName);
if (currentRef == null)
continue;
String fullName = currentRef.getName();
for (String tagName : tags) {
if (tagName == null)
continue;
- Ref currentRef = repo.getRef(tagName);
+ Ref currentRef = repo.findRef(tagName);
if (currentRef == null)
continue;
String fullName = currentRef.getName();
Collection<Ref> refs = new ArrayList<Ref>();
// Also return HEAD if it's detached
- Ref head = repo.getRef(Constants.HEAD);
+ Ref head = repo.exactRef(Constants.HEAD);
if (head != null && head.getLeaf().getName().equals(Constants.HEAD))
refs.add(head);
List<Note> notes = new ArrayList<Note>();
NoteMap map = NoteMap.newEmptyMap();
try (RevWalk walk = new RevWalk(repo)) {
- Ref ref = repo.getRef(notesRef);
+ Ref ref = repo.findRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
RevCommit notesCommit = walk.parseCommit(ref.getObjectId());
RevWalk revWalk = null;
DirCacheCheckout dco = null;
try {
- Ref head = repo.getRef(Constants.HEAD);
+ Ref head = repo.exactRef(Constants.HEAD);
if (head == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
refSpecs.addAll(config.getPushRefSpecs());
}
if (refSpecs.isEmpty()) {
- Ref head = repo.getRef(Constants.HEAD);
+ Ref head = repo.exactRef(Constants.HEAD);
if (head != null && head.isSymbolic())
refSpecs.add(new RefSpec(head.getLeaf().getName()));
}
} else {
Ref src;
try {
- src = repo.getRef(nameOrSpec);
+ src = repo.findRef(nameOrSpec);
} catch (IOException e) {
throw new JGitInternalException(
JGitText.get().exceptionCaughtDuringExecutionOfPushCommand,
private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent,
String refLogMessage) throws IOException {
- Ref currentRef = repo.getRef(Constants.R_STASH);
+ Ref currentRef = repo.exactRef(Constants.R_STASH);
RefUpdate refUpdate = repo.updateRef(Constants.R_STASH);
refUpdate.setNewObjectId(commitId);
refUpdate.setRefLogIdent(refLogIdent);
private void resetSoftToParent() throws IOException,
GitAPIException, CheckoutConflictException {
- Ref ref = repo.getRef(Constants.ORIG_HEAD);
+ Ref ref = repo.exactRef(Constants.ORIG_HEAD);
ObjectId orig_head = ref == null ? null : ref.getObjectId();
try {
// we have already commited the cherry-picked commit.
}
private Ref getHead() throws IOException, RefNotFoundException {
- Ref head = repo.getRef(Constants.HEAD);
+ Ref head = repo.exactRef(Constants.HEAD);
if (head == null || head.getObjectId() == null)
throw new RefNotFoundException(MessageFormat.format(
JGitText.get().refNotResolved, Constants.HEAD));
ObjectInserter inserter = repo.newObjectInserter()) {
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
- Ref ref = repo.getRef(notesRef);
+ Ref ref = repo.exactRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
notesCommit = walk.parseCommit(ref.getObjectId());
try {
String fullOldName;
String fullNewName;
- if (repo.getRef(newName) != null)
+ if (repo.findRef(newName) != null)
throw new RefAlreadyExistsException(MessageFormat.format(
JGitText.get().refAlreadyExists1, newName));
if (oldName != null) {
- Ref ref = repo.getRef(oldName);
+ Ref ref = repo.findRef(oldName);
if (ref == null)
throw new RefNotFoundException(MessageFormat.format(
JGitText.get().refNotResolved, oldName));
repoConfig.save();
}
- Ref resultRef = repo.getRef(newName);
+ Ref resultRef = repo.findRef(newName);
if (resultRef == null)
throw new JGitInternalException(
JGitText.get().renameBranchFailedUnknownReason);
// reset [commit] -- paths
resetIndexForPaths(commitTree);
setCallable(false);
- return repo.getRef(Constants.HEAD);
+ return repo.exactRef(Constants.HEAD);
}
final Ref result;
try (RevWalk revWalk = new RevWalk(repo)) {
// get the head commit
- Ref headRef = repo.getRef(Constants.HEAD);
+ Ref headRef = repo.exactRef(Constants.HEAD);
if (headRef == null)
throw new NoHeadException(
JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
NoteMap map = NoteMap.newEmptyMap();
RevCommit notesCommit = null;
try (RevWalk walk = new RevWalk(repo)) {
- Ref ref = repo.getRef(notesRef);
+ Ref ref = repo.exactRef(notesRef);
// if we have a notes ref, use it
if (ref != null) {
notesCommit = walk.parseCommit(ref.getObjectId());
String refLogMessage) throws IOException {
if (ref == null)
return;
- Ref currentRef = repo.getRef(ref);
+ Ref currentRef = repo.findRef(ref);
RefUpdate refUpdate = repo.updateRef(ref);
refUpdate.setNewObjectId(commitId);
refUpdate.setRefLogIdent(refLogIdent);
private Ref getHead() throws GitAPIException {
try {
- Ref head = repo.getRef(Constants.HEAD);
+ Ref head = repo.exactRef(Constants.HEAD);
if (head == null || head.getObjectId() == null)
throw new NoHeadException(JGitText.get().headRequiredToStash);
return head;
private Ref getRef() throws GitAPIException {
try {
- return repo.getRef(R_STASH);
+ return repo.exactRef(R_STASH);
} catch (IOException e) {
throw new InvalidRefNameException(MessageFormat.format(
JGitText.get().cannotRead, R_STASH), e);
updateRef(stashRef, entryId);
try {
- Ref newStashRef = repo.getRef(R_STASH);
+ Ref newStashRef = repo.exactRef(R_STASH);
return newStashRef != null ? newStashRef.getObjectId() : null;
} catch (IOException e) {
throw new InvalidRefNameException(MessageFormat.format(
checkCallable();
try {
- if (repo.getRef(Constants.R_STASH) == null)
+ if (repo.exactRef(Constants.R_STASH) == null)
return Collections.emptyList();
} catch (IOException e) {
throw new InvalidRefNameException(MessageFormat.format(
* @throws IOException
*/
protected String getHeadBranch(final Repository subRepo) throws IOException {
- Ref head = subRepo.getRef(Constants.HEAD);
+ Ref head = subRepo.exactRef(Constants.HEAD);
if (head != null && head.isSymbolic())
return Repository.shortenRefName(head.getLeaf().getName());
else
switch (updateResult) {
case NEW:
case FORCED:
- return repo.getRef(refName);
+ return repo.exactRef(refName);
case LOCK_FAILURE:
throw new ConcurrentRefUpdateException(
JGitText.get().couldNotLockHEAD, tagRef.getRef(),
* @throws IOException the ref could not be accessed.
*/
public ReflogReader getReflogReader(String refName) throws IOException {
- Ref ref = getRef(refName);
+ Ref ref = findRef(refName);
if (ref != null)
return new ReflogReaderImpl(this, ref.getName());
return null;
if (trackingBranch == null)
return null;
- Ref tracking = repository.getRef(trackingBranch);
+ Ref tracking = repository.exactRef(trackingBranch);
if (tracking == null)
return null;
- Ref local = repository.getRef(fullBranchName);
+ Ref local = repository.exactRef(fullBranchName);
if (local == null)
return null;
* This is essentially the same as doing:
*
* <pre>
- * return getRef(Constants.HEAD).getTarget().getName()
+ * return exactRef(Constants.HEAD).getTarget().getName()
* </pre>
*
* Except when HEAD is detached, in which case this method returns the
*/
@Nullable
public String getFullBranch() throws IOException {
- Ref head = getRef(Constants.HEAD);
+ Ref head = exactRef(Constants.HEAD);
if (head == null) {
return null;
}
String remoteName = null;
// Look up remote URL associated wit HEAD ref
- Ref ref = parent.getRef(Constants.HEAD);
+ Ref ref = parent.exactRef(Constants.HEAD);
if (ref != null) {
if (ref.isSymbolic())
ref = ref.getLeaf();
if (subRepo == null)
return null;
try {
- Ref head = subRepo.getRef(Constants.HEAD);
+ Ref head = subRepo.exactRef(Constants.HEAD);
return head != null ? head.getLeaf().getName() : null;
} finally {
subRepo.close();
for (final RefSpec spec : procRefs) {
String srcSpec = spec.getSource();
- final Ref srcRef = db.getRef(srcSpec);
+ final Ref srcRef = db.findRef(srcSpec);
if (srcRef != null)
srcSpec = srcRef.getName();