/// <exception cref="System.IO.IOException"></exception> private void Delete(RefUpdate @ref, RefUpdate.Result expected, bool exists, bool removed) { NUnit.Framework.Assert.AreEqual(exists, db.GetAllRefs().ContainsKey(@ref.GetName())); NUnit.Framework.Assert.AreEqual(expected, @ref.Delete()); NUnit.Framework.Assert.AreEqual(!removed, db.GetAllRefs().ContainsKey(@ref.GetName())); }
private bool RenameLog(RefUpdate src, RefUpdate dst) { FilePath srcLog = refdb.GetLogWriter().LogFor(src.GetName()); FilePath dstLog = refdb.GetLogWriter().LogFor(dst.GetName()); if (!srcLog.Exists()) { return(true); } if (!Rename(srcLog, dstLog)) { return(false); } try { int levels = RefDirectory.LevelsIn(src.GetName()) - 2; RefDirectory.Delete(srcLog, levels); return(true); } catch (IOException) { Rename(dstLog, srcLog); return(false); } }
private bool LinkHEAD(RefUpdate target) { try { RefUpdate u = ((RefDirectoryUpdate)refdb.NewUpdate(Constants.HEAD, false)); u.DisableRefLog(); switch (u.Link(target.GetName())) { case RefUpdate.Result.NEW: case RefUpdate.Result.FORCED: case RefUpdate.Result.NO_CHANGE: { return(true); } default: { return(false); break; } } } catch (IOException) { return(false); } }
// 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); }
/// <summary>Get the name of the local tracking ref.</summary> /// <remarks> /// Get the name of the local tracking ref. /// <p> /// Usually this is of the form "refs/remotes/origin/master". /// </remarks> /// <returns>the name used within this local repository.</returns> public virtual string GetLocalName() { return(update.GetName()); }