private StashedState OnStashSaveCompleted(bool created) { if (created) { var stashTopData = Repository.Accessor.QueryStashTop.Invoke( new QueryStashTopParameters(true)); Revision revision; lock (Repository.Revisions.SyncRoot) { revision = ObjectFactories.CreateRevision(Repository, stashTopData); } var res = new StashedState(Repository, 0, revision); lock (SyncRoot) { _stash.Insert(0, res); for (int i = 1; i < _stash.Count; ++i) { ++_stash[i].Index; } InvokeStashedStateCreated(res); } Repository.OnCommitCreated(res.Revision); Repository.Status.Refresh(); return(res); } else { return(null); } }
public Revision Merge(IRevisionPointer branch, bool noCommit, bool noFastForward, bool squash, string message) { Verify.Argument.IsValidRevisionPointer(branch, Repository, nameof(branch)); Verify.State.IsFalse(IsEmpty, Resources.ExcCantDoOnEmptyRepository.UseAsFormat("merge")); var oldRev = branch.Dereference(); var currentBranch = CurrentBranch; using (Repository.Monitor.BlockNotifications( RepositoryNotifications.Checkout, RepositoryNotifications.IndexUpdated, RepositoryNotifications.WorktreeUpdated, RepositoryNotifications.BranchChanged)) { try { Repository.Accessor.Merge.Invoke( new MergeParameters(branch.FullName) { NoCommit = noCommit, NoFastForward = noFastForward, Squash = squash, Message = message, }); } catch (AutomaticMergeFailedException) { Repository.OnStateChanged(); Repository.Status.Refresh(); throw; } } if (currentBranch != null) { currentBranch.Refresh(); } else { Refresh(); } var headRev = Revision; if (noCommit) { Repository.OnStateChanged(); Repository.Status.Refresh(); } else { if (noFastForward || headRev != oldRev) //not fast-forwarded { Repository.OnCommitCreated(headRev); } } NotifyRelogRecordAdded(); return(headRev); }
public Revision Commit(string message, bool amend) { Verify.Argument.IsNotNull(message, "message"); var currentBranch = Repository.Head.Pointer as Branch; using (Repository.Monitor.BlockNotifications( RepositoryNotifications.IndexUpdated, RepositoryNotifications.BranchChanged, RepositoryNotifications.Checkout)) { var fileName = Path.Combine( Repository.GitDirectory, GitConstants.CommitMessageFileName); File.WriteAllText(fileName, message); bool commitSuccess = false; try { Repository.Accessor.Commit.Invoke( new CommitParameters() { MessageFileName = Path.Combine( Repository.GitDirectory, GitConstants.CommitMessageFileName), Amend = amend, }); commitSuccess = true; } finally { if (commitSuccess) { try { File.Delete(fileName); } catch (Exception exc) { if (exc.IsCritical()) { throw; } } } } } Revision commit = null; if (currentBranch != null) { var oldHeadRev = currentBranch.Revision; currentBranch.Refresh(); commit = currentBranch.Revision; if (commit != oldHeadRev) { Repository.OnCommitCreated(commit); } } else { var oldHeadRev = Repository.Head.Revision; Repository.Head.Refresh(); commit = Repository.Head.Revision; if (commit != oldHeadRev) { Repository.OnCommitCreated(commit); } } Repository.Head.NotifyRelogRecordAdded(); Repository.OnStateChanged(); Refresh(); return(commit); }
public Revision Merge(ICollection <IRevisionPointer> branches, bool noCommit, bool noFastForward, bool squash, string message) { Verify.Argument.IsValidRevisionPointerSequence(branches, Repository, nameof(branches)); Verify.Argument.IsTrue(branches.Count != 0, nameof(branches), Resources.ExcCollectionMustContainAtLeastOneObject.UseAsFormat("branch")); Verify.State.IsFalse(IsEmpty, Resources.ExcCantDoOnEmptyRepository.UseAsFormat("merge")); if (branches.Count == 1) { foreach (var branch in branches) { return(Merge(branch, noCommit, noFastForward, squash, message)); } } var oldRevs = new List <Revision>(branches.Count); var branchNames = new List <string>(branches.Count); foreach (var branch in branches) { oldRevs.Add(branch.Dereference()); branchNames.Add(branch.FullName); } var currentBranch = CurrentBranch; using (Repository.Monitor.BlockNotifications( RepositoryNotifications.Checkout, RepositoryNotifications.WorktreeUpdated, RepositoryNotifications.IndexUpdated, RepositoryNotifications.BranchChanged)) { try { Repository.Accessor.Merge.Invoke( new MergeParameters(branchNames) { NoCommit = noCommit, NoFastForward = noFastForward, Squash = squash, Message = message, }); } catch (AutomaticMergeFailedException) { Repository.OnStateChanged(); Repository.Status.Refresh(); throw; } } if (currentBranch != null) { currentBranch.Refresh(); } else { Refresh(); } var headRev = Revision; if (noCommit) { Repository.OnStateChanged(); Repository.Status.Refresh(); } else { if (noFastForward || !oldRevs.Contains(headRev)) //not fast-forwarded { Repository.OnCommitCreated(headRev); } } NotifyRelogRecordAdded(); return(headRev); }