/// <summary>Write the given ref update to the ref's log</summary> /// <param name="update"></param> /// <param name="msg"></param> /// <param name="deref"></param> /// <returns>this writer</returns> /// <exception cref="System.IO.IOException">System.IO.IOException</exception> public virtual NGit.Storage.File.ReflogWriter Log(RefUpdate update, string msg, bool deref) { ObjectId oldId = update.GetOldObjectId(); ObjectId newId = update.GetNewObjectId(); Ref @ref = update.GetRef(); PersonIdent ident = update.GetRefLogIdent(); if (ident == null) { ident = new PersonIdent(parent); } else { ident = new PersonIdent(ident); } byte[] rec = Encode(oldId, newId, ident, msg); if (deref && @ref.IsSymbolic()) { Log(@ref.GetName(), rec); Log(@ref.GetLeaf().GetName(), rec); } else { Log(@ref.GetName(), rec); } return(this); }
/// <summary>Construct remote ref update request by providing an update specification. /// </summary> /// <remarks> /// Construct remote ref update request by providing an update specification. /// Object is created with default /// <see cref="Status.NOT_ATTEMPTED">Status.NOT_ATTEMPTED</see> /// status and no /// message. /// </remarks> /// <param name="localDb">local repository to push from.</param> /// <param name="srcRef"> /// source revision to label srcId with. If null srcId.name() will /// be used instead. /// </param> /// <param name="srcId"> /// The new object that the caller wants remote ref to be after /// update. Use null or /// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see> /// for delete /// request. /// </param> /// <param name="remoteName"> /// full name of a remote ref to update, e.g. "refs/heads/master" /// (no wildcard, no short name). /// </param> /// <param name="forceUpdate"> /// true when caller want remote ref to be updated regardless /// whether it is fast-forward update (old object is ancestor of /// new object). /// </param> /// <param name="localName"> /// optional full name of a local stored tracking branch, to /// update after push, e.g. "refs/remotes/zawir/dirty" (no /// wildcard, no short name); null if no local tracking branch /// should be updated. /// </param> /// <param name="expectedOldObjectId"> /// optional object id that caller is expecting, requiring to be /// advertised by remote side before update; update will take /// place ONLY if remote side advertise exactly this expected id; /// null if caller doesn't care what object id remote side /// advertise. Use /// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see> /// when expecting no /// remote ref with this name. /// </param> /// <exception cref="System.IO.IOException"> /// when I/O error occurred during creating /// <see cref="TrackingRefUpdate">TrackingRefUpdate</see> /// for local tracking branch or srcRef /// can't be resolved to any object. /// </exception> /// <exception cref="System.ArgumentException">if some required parameter was null</exception> public RemoteRefUpdate(Repository localDb, string srcRef, ObjectId srcId, string remoteName, bool forceUpdate, string localName, ObjectId expectedOldObjectId) { if (remoteName == null) { throw new ArgumentException(JGitText.Get().remoteNameCantBeNull); } if (srcId == null && srcRef != null) { throw new IOException(MessageFormat.Format(JGitText.Get().sourceRefDoesntResolveToAnyObject , srcRef)); } if (srcRef != null) { this.srcRef = srcRef; } else { if (srcId != null && !srcId.Equals(ObjectId.ZeroId)) { this.srcRef = srcId.Name; } else { this.srcRef = null; } } if (srcId != null) { this.newObjectId = srcId; } else { this.newObjectId = ObjectId.ZeroId; } this.remoteName = remoteName; this.forceUpdate = forceUpdate; if (localName != null && localDb != null) { localUpdate = localDb.UpdateRef(localName); localUpdate.SetForceUpdate(true); localUpdate.SetRefLogMessage("push", true); localUpdate.SetNewObjectId(newObjectId); trackingRefUpdate = new TrackingRefUpdate(true, remoteName, localName, localUpdate .GetOldObjectId() != null ? localUpdate.GetOldObjectId() : ObjectId.ZeroId, newObjectId ); } else { trackingRefUpdate = null; } this.localDb = localDb; this.expectedOldObjectId = expectedOldObjectId; this.status = RemoteRefUpdate.Status.NOT_ATTEMPTED; }
// TODO not implemented yet // TODO not implemented yet /// <summary> /// Executes the /// <code>Reset</code> /// command. Each instance of this class should /// only be used for one invocation of the command. Don't call this method /// twice on an instance. /// </summary> /// <returns>the Ref after reset</returns> /// <exception cref="NGit.Api.Errors.GitAPIException">NGit.Api.Errors.GitAPIException /// </exception> /// <exception cref="NGit.Api.Errors.CheckoutConflictException"></exception> public override Ref Call() { CheckCallable(); Ref r; RevCommit commit; try { RepositoryState state = repo.GetRepositoryState(); bool merging = state.Equals(RepositoryState.MERGING) || state.Equals(RepositoryState .MERGING_RESOLVED); bool cherryPicking = state.Equals(RepositoryState.CHERRY_PICKING) || state.Equals (RepositoryState.CHERRY_PICKING_RESOLVED); // resolve the ref to a commit ObjectId commitId; try { commitId = repo.Resolve(@ref + "^{commit}"); if (commitId == null) { // @TODO throw an InvalidRefNameException. We can't do that // now because this would break the API throw new JGitInternalException("Invalid ref " + @ref + " specified"); } } catch (IOException e) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().cannotRead, @ref ), e); } RevWalk rw = new RevWalk(repo); try { commit = rw.ParseCommit(commitId); } catch (IOException e) { throw new JGitInternalException(MessageFormat.Format(JGitText.Get().cannotReadCommit , commitId.ToString()), e); } finally { rw.Release(); } if (!filepaths.IsEmpty()) { // reset [commit] -- paths ResetIndexForPaths(commit); SetCallable(false); return(repo.GetRef(Constants.HEAD)); } // write the ref RefUpdate ru = repo.UpdateRef(Constants.HEAD); ru.SetNewObjectId(commitId); string refName = Repository.ShortenRefName(@ref); 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); } switch (mode) { case ResetCommand.ResetType.HARD: { CheckoutIndex(commit); break; } case ResetCommand.ResetType.MIXED: { ResetIndex(commit); break; } case ResetCommand.ResetType.SOFT: { // do nothing, only the ref was changed break; } case ResetCommand.ResetType.KEEP: case ResetCommand.ResetType.MERGE: { // TODO // TODO throw new NotSupportedException(); } } if (mode != ResetCommand.ResetType.SOFT) { if (merging) { ResetMerge(); } else { if (cherryPicking) { ResetCherryPick(); } else { if (repo.ReadSquashCommitMsg() != null) { repo.WriteSquashCommitMsg(null); } } } } SetCallable(false); r = ru.GetRef(); } catch (IOException e) { throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfResetCommand , e); } return(r); }
/// <summary>The old value of the ref, prior to the update being attempted.</summary> /// <remarks> /// The old value of the ref, prior to the update being attempted. /// <p> /// This value may differ before and after the update method. Initially it is /// populated with the value of the ref before the lock is taken, but the old /// value may change if someone else modified the ref between the time we /// last read it and when the ref was locked for update. /// </remarks> /// <returns> /// the value of the ref prior to the update being attempted; null if /// the updated has not been attempted yet. /// </returns> public virtual ObjectId GetOldObjectId() { return(update.GetOldObjectId()); }