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); } }
rup.setNewObjectId(aNewHead); rup.setRefLogMessage("rebase finished: " + headName + " onto " //$NON-NLS-1$ //$NON-NLS-2$ + onto.getName(), false); Result res = rup.forceUpdate(); switch (res) { case FAST_FORWARD: rup.setRefLogMessage("rebase finished: returning to " + headName, //$NON-NLS-1$ false); res = rup.link(headName); switch (res) { case FAST_FORWARD:
if (source.getRef().isSymbolic()) return Result.IO_FAILURE; // not supported objId = source.getOldObjectId(); updateHEAD = needToUpdateHEAD(); tmp = refdb.newTemporaryUpdate(); dst.setRefLogIdent(destination.getRefLogIdent()); dst.setRefLogMessage(destination.getRefLogMessage(), false); source.setExpectedOldObjectId(objId); source.setForceUpdate(true); source.disableRefLog(); if (source.delete(rw) != Result.FORCED) { renameLog(tmp, source); if (updateHEAD) linkHEAD(source); return source.getResult(); source.setExpectedOldObjectId(ObjectId.zeroId()); source.setNewObjectId(objId); source.update(rw); if (updateHEAD) linkHEAD(source); dst.setExpectedOldObjectId(ObjectId.zeroId()); dst.setNewObjectId(objId); if (dst.update(rw) != Result.NEW) {
/** {@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 boolean linkHEAD(RefUpdate target) { try { RefUpdate u = refdb.newUpdate(Constants.HEAD, false); u.disableRefLog(); switch (u.link(target.getName())) { case NEW: case FORCED: case NO_CHANGE: return true; default: return false; } } catch (IOException e) { return false; } } }
private void updateStashRef(ObjectId commitId, PersonIdent refLogIdent, String refLogMessage) throws IOException { Ref currentRef = repo.exactRef(Constants.R_STASH); RefUpdate refUpdate = repo.updateRef(Constants.R_STASH); refUpdate.setNewObjectId(commitId); refUpdate.setRefLogIdent(refLogIdent); refUpdate.setRefLogMessage(refLogMessage, false); refUpdate.setForceRefLog(true); if (currentRef != null) refUpdate.setExpectedOldObjectId(currentRef.getObjectId()); else refUpdate.setExpectedOldObjectId(ObjectId.zeroId()); refUpdate.forceUpdate(); }
RefUpdate ru = rp.getRepository().updateRef(getRefName(), detach); if (expTarget != null) { if (!ru.getRef().isSymbolic() || !ru.getRef().getTarget() .getName().equals(expTarget)) { setResult(Result.LOCK_FAILURE); ru.setRefLogIdent(rp.getRefLogIdent()); ru.setRefLogMessage(refLogMessage, refLogIncludeResult); switch (getType()) { case DELETE: ru.setExpectedOldObjectId(getOldId()); ru.setForceUpdate(true); setResult(ru.delete(rp.getRevWalk())); break; case UPDATE: case UPDATE_NONFASTFORWARD: ru.setForceUpdate(rp.isAllowNonFastForwards()); ru.setExpectedOldObjectId(getOldId()); ru.setRefLogMessage("push", true); //$NON-NLS-1$ if (getNewSymref() != null) { setResult(ru.link(getNewSymref())); } else { ru.setNewObjectId(getNewId()); setResult(ru.update(rp.getRevWalk()));
newHead.disableRefLog(); newHead.link(head.getName()); addMergeConfig(clonedRepo, head); u.setNewObjectId(commit.getId()); u.forceUpdate();
branchName)); RefUpdate update = repo.updateRef(fullName); update.setRefLogMessage("branch deleted", false); //$NON-NLS-1$ update.setForceUpdate(true); Result deleteResult = update.delete();
RefUpdate refUpdate = submoduleRepo.updateRef( Constants.HEAD, true); refUpdate.setNewObjectId(commit); refUpdate.forceUpdate(); if (callback != null) { callback.checkingOut(commit,
RefUpdate ru = refdb.newUpdate(cmd.getRefName(), false); if (isRefLogDisabled(cmd)) { ru.disableRefLog(); } else { ru.setRefLogIdent(refLogIdent); ru.setRefLogMessage(getRefLogMessage(cmd), isRefLogIncludingResult(cmd)); ru.setForceRefLog(isForceRefLog(cmd)); ru.setPushCertificate(pushCert); switch (cmd.getType()) { case DELETE: if (!ObjectId.zeroId().equals(cmd.getOldId())) ru.setExpectedOldObjectId(cmd.getOldId()); ru.setForceUpdate(true); return ru; case UPDATE_NONFASTFORWARD: default: ru.setForceUpdate(isAllowNonFastForwards()); ru.setExpectedOldObjectId(cmd.getOldId()); ru.setNewObjectId(cmd.getNewId()); return ru;
@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); }
updateRef.setNewObjectId(startAt); updateRef.setRefLogMessage(refLogMessage, false); Result updateResult; if (exists && force) updateResult = updateRef.forceUpdate(); else updateResult = updateRef.update();
ru.setNewObjectId(commitId); ru.disableRefLog(); } else { String message = refName + ": updating " + Constants.HEAD; //$NON-NLS-1$ ru.setRefLogMessage(message, false); if (ru.forceUpdate() == RefUpdate.Result.LOCK_FAILURE) throw new JGitInternalException(MessageFormat.format( JGitText.get().cannotLock, ru.getName())); ObjectId origHead = ru.getOldObjectId(); if (origHead != null) repo.writeOrigHead(origHead);
if (localName != null && localDb != null) { localUpdate = localDb.updateRef(localName); localUpdate.setForceUpdate(true); localUpdate.setRefLogMessage("push", true); //$NON-NLS-1$ localUpdate.setNewObjectId(newObjectId); trackingRefUpdate = new TrackingRefUpdate( true, remoteName, localName, localUpdate.getOldObjectId() != null ? localUpdate.getOldObjectId() : ObjectId.zeroId(), newObjectId);
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); }
/** * 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 createRefUpdate(Ref stashRef) throws IOException { RefUpdate update = repo.updateRef(R_STASH); update.disableRefLog(); update.setExpectedOldObjectId(stashRef.getObjectId()); update.setForceUpdate(true); return update; }
protected void checkoutBranch(String branchName) throws IllegalStateException, IOException { try (RevWalk walk = new RevWalk(db)) { RevCommit head = walk.parseCommit(db.resolve(Constants.HEAD)); RevCommit branch = walk.parseCommit(db.resolve(branchName)); DirCacheCheckout dco = new DirCacheCheckout(db, head.getTree().getId(), db.lockDirCache(), branch.getTree().getId()); dco.setFailOnConflict(true); dco.checkout(); } // update the HEAD RefUpdate refUpdate = db.updateRef(Constants.HEAD); refUpdate.setRefLogMessage("checkout: moving to " + branchName, false); refUpdate.link(branchName); }
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); } }