// 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="System.IO.IOException"></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); } 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())); } 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(); } } } SetCallable(false); r = ru.GetRef(); } catch (IOException e) { throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfResetCommand , e); } return(r); }