/** {@inheritDoc} */ @Override public Result update(RevWalk walk) throws IOException { try { rw = walk; return super.update(walk); } finally { rw = null; } }
/** * Force the ref to take the new value. * <p> * This is just a convenient helper for setting the force flag, and as such * the merge test is performed. * * @return the result status of the update. * @throws java.io.IOException * an unexpected IO error occurred while writing changes. */ public Result forceUpdate() throws IOException { force = true; return update(); }
/** * Gracefully update the ref to the new value. * <p> * Merge test will be performed according to {@link #isForceUpdate()}. * <p> * This is the same as: * * <pre> * return update(new RevWalk(getRepository())); * </pre> * * @return the result status of the update. * @throws java.io.IOException * an unexpected IO error occurred while writing changes. */ public Result update() throws IOException { try (RevWalk rw = new RevWalk(getRepository())) { return update(rw); } }
/** * Update locally stored tracking branch with the new object. * * @param walk * walker used for checking update properties. * @throws java.io.IOException * when I/O error occurred during update */ protected void updateTrackingRef(RevWalk walk) throws IOException { if (isDelete()) trackingRefUpdate.setResult(localUpdate.delete(walk)); else trackingRefUpdate.setResult(localUpdate.update(walk)); }
private RefUpdate.Result updateRef(ObjectId newId) throws IOException { RefUpdate ru = db.updateRef(REF_NAME); ru.setExpectedOldObjectId(commit != null ? commit : ObjectId.zeroId()); ru.setNewObjectId(newId); ru.setRefLogIdent(pending.get(pending.size() - 1).ident); ru.setRefLogMessage(JGitText.get().storePushCertReflog, false); try (RevWalk rw = new RevWalk(reader)) { return ru.update(rw); } }
private void updateRef(Ref stashRef, ObjectId newId) { try { RefUpdate update = createRefUpdate(stashRef); update.setNewObjectId(newId); Result result = update.update(); switch (result) { case FORCED: case NEW: case NO_CHANGE: return; default: throw new JGitInternalException(MessageFormat.format( JGitText.get().updatingRefFailed, R_STASH, newId, result)); } } catch (IOException e) { throw new JGitInternalException(JGitText.get().stashDropFailed, e); } }
private void updateHead(StringBuilder refLogMessage, ObjectId newHeadId, ObjectId oldHeadID) throws IOException, ConcurrentRefUpdateException { RefUpdate refUpdate = repo.updateRef(Constants.HEAD); refUpdate.setNewObjectId(newHeadId); refUpdate.setRefLogMessage(refLogMessage.toString(), false); refUpdate.setExpectedOldObjectId(oldHeadID); Result rc = refUpdate.update(); switch (rc) { case NEW: case FAST_FORWARD: return; case REJECTED: case LOCK_FAILURE: throw new ConcurrentRefUpdateException( JGitText.get().couldNotLockHEAD, refUpdate.getRef(), rc); default: throw new JGitInternalException(MessageFormat.format( JGitText.get().updatingRefFailed, Constants.HEAD, newHeadId.toString(), rc)); } }
/** {@inheritDoc} */ @Override protected Result doRename() throws IOException { // TODO Correctly handle renaming foo/bar to foo. // TODO Batch these together into one log update. destination.setExpectedOldObjectId(ObjectId.zeroId()); destination.setNewObjectId(source.getRef().getObjectId()); switch (destination.update()) { case NEW: source.delete(); return Result.RENAMED; default: return destination.getResult(); } } }
private Ref updateTagRef(ObjectId tagId, RevWalk revWalk, String tagName, String newTagToString) throws IOException, ConcurrentRefUpdateException, RefAlreadyExistsException { String refName = Constants.R_TAGS + tagName; RefUpdate tagRef = repo.updateRef(refName); tagRef.setNewObjectId(tagId); tagRef.setForceUpdate(forceUpdate); tagRef.setRefLogMessage("tagged " + name, false); //$NON-NLS-1$ Result updateResult = tagRef.update(revWalk); switch (updateResult) { case NEW: case FORCED: return repo.exactRef(refName); case LOCK_FAILURE: throw new ConcurrentRefUpdateException( JGitText.get().couldNotLockHEAD, tagRef.getRef(), updateResult); case REJECTED: throw new RefAlreadyExistsException(MessageFormat.format( JGitText.get().tagAlreadyExists, newTagToString)); default: throw new JGitInternalException(MessageFormat.format( JGitText.get().updatingRefFailed, refName, newTagToString, updateResult)); } }
updateResult = updateRef.forceUpdate(); else updateResult = updateRef.update();
rup.setRefLogMessage("Fast-forward from " + oldCommit.name() //$NON-NLS-1$ + " to " + newCommit.name(), false); //$NON-NLS-1$ Result res = rup.update(walk); switch (res) { case FAST_FORWARD:
static void commitNoteMap(Repository r, String ref, RevWalk walk, NoteMap map, RevCommit notesCommit, ObjectInserter inserter, String msg) throws IOException { // commit the note CommitBuilder builder = new CommitBuilder(); builder.setTreeId(map.writeTree(inserter)); builder.setAuthor(new PersonIdent(r)); builder.setCommitter(builder.getAuthor()); builder.setMessage(msg); if (notesCommit != null) builder.setParentIds(notesCommit); ObjectId commit = inserter.insert(builder); inserter.flush(); RefUpdate refUpdate = r.updateRef(ref); if (notesCommit != null) refUpdate.setExpectedOldObjectId(notesCommit); else refUpdate.setExpectedOldObjectId(ObjectId.zeroId()); refUpdate.setNewObjectId(commit); refUpdate.update(walk); }
ru.setNewObjectId(commitId); ru.setExpectedOldObjectId(headId != null ? headId : ObjectId.zeroId()); Result rc = ru.update(rw);
protected void createBranch(ObjectId objectId, String branchName) throws IOException { RefUpdate updateRef = db.updateRef(branchName); updateRef.setNewObjectId(objectId); updateRef.update(); }
protected void createBranch(ObjectId objectId, String branchName) throws IOException { RefUpdate updateRef = db.updateRef(branchName); updateRef.setNewObjectId(objectId); updateRef.update(); }
source.setExpectedOldObjectId(ObjectId.zeroId()); source.setNewObjectId(objId); source.update(rw); if (updateHEAD) linkHEAD(source); if (dst.update(rw) != Result.NEW) { source.setExpectedOldObjectId(ObjectId.zeroId()); source.setNewObjectId(objId); source.update(rw); if (updateHEAD) linkHEAD(source);
refUpdate.setExpectedOldObjectId(null); refUpdate.setRefLogMessage("initial pull", false); //$NON-NLS-1$ if (refUpdate.update() != Result.NEW) throw new NoHeadException( JGitText.get().commitOnRepoWithoutHEADCurrentlyNotSupported);
} else { ru.setNewObjectId(getNewId()); setResult(ru.update(rp.getRevWalk()));
@Nonnull private static Ref linkTag(String name, AnyObjectId tag, Repository repo) throws IOException { String refName = RefUtils.fullTagRef(name); if(tagExists(name, repo)) throw new TagAlreadyExistsException(refName); RefUpdate update = repo.updateRef(refName); update.setNewObjectId(tag); update.setRefLogMessage("tagged " + name, false); RefUpdateValidator.validate(update.update()); return repo.exactRef(refName); }