コード例 #1
0
        public override void OnExecute(CommandEventArgs e)
        {
            using (ProjectCommitDialog dlg = new ProjectCommitDialog())
            {
                dlg.Context = e.Context;
                dlg.PreserveWindowPlacement = true;
                dlg.LoadChanges(GetChanges(e));

                dlg.LogMessageText = logMessage ?? "";

                DialogResult dr = dlg.ShowDialog(e.Context);

                logMessage = dlg.LogMessageText;

                if (dr == DialogResult.OK)
                {
                    PendingChangeCommitArgs pca = new PendingChangeCommitArgs();
                    pca.StoreMessageOnError = true;
                    // TODO: Commit it!
                    List<PendingChange> toCommit = new List<PendingChange>(dlg.GetSelection());
                    dlg.FillArgs(pca);

                    if (e.GetService<IPendingChangeHandler>().Commit(toCommit, pca))
                    {
                        logMessage = null;
                    }
                }
            }
        }
コード例 #2
0
        public override void OnExecute(CommandEventArgs e)
        {
            using (ProjectCommitDialog pcd = new ProjectCommitDialog())
            {
                pcd.Context = e.Context;
                pcd.LogMessageText = storedLogMessage;
                pcd.AmendLastCommit = storedAmendCommit;

                pcd.PreserveWindowPlacement = true;

                pcd.LoadItems(e.Selection.GetSelectedGitItems(true));

                DialogResult dr = pcd.ShowDialog(e.Context);

                storedLogMessage = pcd.LogMessageText;
                storedAmendCommit = pcd.AmendLastCommit;

                if (dr != DialogResult.OK)
                    return;

                PendingChangeCommitArgs pca = new PendingChangeCommitArgs();
                pca.StoreMessageOnError = true;
                // TODO: Commit it!
                List<PendingChange> toCommit = new List<PendingChange>(pcd.GetSelection());
                pcd.FillArgs(pca);

                e.GetService<IPendingChangeHandler>().Commit(toCommit, pca);
            }

            // not in the finally, because we want to preserve the message for a
            // non-successful commit
            storedLogMessage = null;
            storedAmendCommit = false;
        }
コード例 #3
0
        public bool Commit(IEnumerable<PendingChange> changes, PendingChangeCommitArgs args)
        {
            // Ok, to make a commit happen we have to take 'a few' steps
            ILastChangeInfo ci = GetService<ILastChangeInfo>();

            if (ci != null)
                ci.SetLastChange(null, null);

            bool storeMessage = args.StoreMessageOnError;

            foreach (PendingCommitState state in GetCommitRoots(changes))
            {
                if (state == null)
                    return false;

                using (state)
                    try
                    {
                        state.LogMessage = args.LogMessage;
                        state.AmendLastCommit = args.AmendLastCommit;

                        if (!PreCommit_VerifyConfiguration(state))
                            return false;

                        if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'first'
                            return false;

                        if (!PreCommit_VerifyLogMessage(state))
                            return false;

                        if (!PreCommit_VerifyNoConflicts(state))
                            return false;

                        if (!PreCommit_SaveDirty(state))
                            return false;

                        if (!PreCommit_AddNewFiles(state))
                            return false;

                        if (!PreCommit_HandleMissingFiles(state))
                            return false;

                        state.FlushState();

                        if (!PreCommit_AddNeededParents(state))
                            return false;

                        if (!PreCommit_VerifySingleRoot(state)) // Verify single root 'again'
                            return false;
                        // if(!PreCommit_....())
                        //  return;

                        bool ok = false;
                        using (DocumentLock dl = GetService<IVisualGitOpenDocumentTracker>().LockDocuments(state.CommitPaths, DocumentLockType.NoReload))
                        using (dl.MonitorChangesForReload()) // Monitor files that are changed by keyword expansion
                        {
                            if (Commit_CommitToRepository(state))
                            {
                                storeMessage = true;
                                ok = true;
                            }
                        }

                        if (!ok)
                            return false;
                    }
                    finally
                    {
                        if (storeMessage)
                        {
                            if (state.LogMessage != null && state.LogMessage.Trim().Length > 0)
                            {
                                IVisualGitConfigurationService config = GetService<IVisualGitConfigurationService>();

                                if (config != null)
                                {
                                    config.GetRecentLogMessages().Add(state.LogMessage);
                                }
                            }
                        }
                    }
            }

            return true;
        }
コード例 #4
0
        public void DoCommit()
        {
            List<PendingChange> changes = new List<PendingChange>();

            foreach (PendingCommitItem pci in _listItems.Values)
            {
                if (pci.Checked)
                {
                    changes.Add(pci.PendingChange);
                }
            }

            IPendingChangeHandler pch = Context.GetService<IPendingChangeHandler>();

            PendingChangeCommitArgs a = new PendingChangeCommitArgs();
            a.LogMessage = logMessageEditor.Text;
            a.AmendLastCommit = amendBox.Checked;

            if (pch.Commit(changes, a))
            {
                logMessageEditor.Clear(true);
                amendBox.Checked = false;
            }
        }