Esempio n. 1
0
        /// <summary>
        /// Adds all files which are marked as to be added to subversion
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool PreCommit_AddNewFiles(PendingCommitState state)
        {
            Queue <string> toAdd = new Queue <string>();

            foreach (PendingChange pc in state.Changes)
            {
                if (pc.Change != null &&
                    (pc.Change.State == PendingChangeKind.New ||
                     pc.Change.State == PendingChangeKind.DeletedNew))
                {
                    SvnItem item = pc.SvnItem;

                    // HACK: figure out why PendingChangeKind.New is still true
                    if (item.IsVersioned && !item.IsDeleteScheduled)
                    {
                        continue; // No need to add
                    }
                    toAdd.Enqueue(item.FullPath);
                }
            }
            while (toAdd.Count > 0)
            {
                SvnException error = null;

                state.GetService <IProgressRunner>().RunModal(PccStrings.AddingTitle,
                                                              delegate(object sender, ProgressWorkerArgs e)
                {
                    SvnAddArgs aa   = new SvnAddArgs();
                    aa.AddParents   = true;
                    aa.Depth        = SvnDepth.Empty;
                    aa.ThrowOnError = false;

                    while (toAdd.Count > 0)
                    {
                        if (!e.Client.Add(toAdd.Dequeue(), aa))
                        {
                            error = aa.LastException;
                            break;
                        }
                    }
                });

                if (error != null)
                {
                    if (error.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_UNSUPPORTED_FORMAT)
                    {
                        state.MessageBox.Show(error.Message + Environment.NewLine + Environment.NewLine
                                              + PccStrings.YouCanDownloadAnkh, "", MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                        return(false);
                    }
                    else if (state.MessageBox.Show(error.Message, "", MessageBoxButtons.OKCancel, System.Windows.Forms.MessageBoxIcon.Error) != DialogResult.OK)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
Esempio n. 2
0
        /// <summary>
        /// Save all documents in the selection
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool PreCommit_SaveDirty(PendingCommitState state)
        {
            IAnkhOpenDocumentTracker tracker = state.GetService <IAnkhOpenDocumentTracker>();

            if (!tracker.SaveDocuments(state.CommitPaths))
            {
                state.MessageBox.Show(PccStrings.FailedToSaveBeforeCommit, "", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Exclamation);
                return(false);
            }

            return(true);
        }
Esempio n. 3
0
        /// <summary>
        /// Finalizes the action by committing to the repository
        /// </summary>
        /// <param name="state">The state.</param>
        /// <returns></returns>
        private bool Commit_CommitToRepository(PendingCommitState state)
        {
            bool            ok   = false;
            SvnCommitResult rslt = null;

            bool enableHooks = Config.Instance.EnableTortoiseSvnHooks;

            bool outOfDateError = false;
            bool otherError     = false;

            StringBuilder outOfDateMessage = null;

            state.GetService <IProgressRunner>().RunModal(PccStrings.CommitTitle,
                                                          delegate(object sender, ProgressWorkerArgs e)
            {
                string itemPath    = null;
                SvnCommitArgs ca   = new SvnCommitArgs();
                ca.Depth           = SvnDepth.Empty;
                ca.KeepLocks       = state.KeepLocks;
                ca.KeepChangeLists = state.KeepChangeLists;
                ca.LogMessage      = state.LogMessage;

                foreach (KeyValuePair <string, string> kv in state.CustomProperties)
                {
                    ca.LogProperties.Add(kv.Key, kv.Value);
                }

                ca.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_UP_TO_DATE);
                ca.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_FORBIDDEN_BY_SERVER);
                ca.AddExpectedError(SvnErrorCode.SVN_ERR_CLIENT_NO_LOCK_TOKEN);
                ca.AddExpectedError(SvnErrorCode.SVN_ERR_IO_INCONSISTENT_EOL);
                ca.AddExpectedError(SvnErrorCode.SVN_ERR_FS_TXN_OUT_OF_DATE);
                ca.AddExpectedError(SvnErrorCode.SVN_ERR_RA_OUT_OF_DATE);
                ca.AddExpectedError(SvnErrorCode.SVN_ERR_WC_FOUND_CONFLICT);
                ca.AddExpectedError(SvnErrorCode.SVN_ERR_WC_PATH_NOT_FOUND);
                ca.Notify += delegate(object notifySender, SvnNotifyEventArgs notifyE)
                {
                    switch (notifyE.Action)
                    {
                    case SvnNotifyAction.FailedOutOfDate:
                        if (notifyE.Error != null)
                        {
                            ca.AddExpectedError(notifyE.Error.SvnErrorCode);                     // Don't throw an exception for this error
                        }
                        outOfDateError = true;
                        itemPath       = itemPath ?? notifyE.FullPath;
                        break;

                    case SvnNotifyAction.FailedConflict:
                    case SvnNotifyAction.FailedMissing:
                    case SvnNotifyAction.FailedNoParent:
                    case SvnNotifyAction.FailedLocked:
                    case SvnNotifyAction.FailedForbiddenByServer:
                        if (notifyE.Error != null)
                        {
                            ca.AddExpectedError(notifyE.Error.SvnErrorCode);                     // Don't throw an exception for this error
                        }
                        otherError = true;
                        itemPath   = itemPath ?? notifyE.FullPath;
                        break;
                    }
                };
                ca.RunTortoiseHooks = enableHooks;

                ok = e.Client.Commit(
                    state.CommitPaths,
                    ca, out rslt);

                if (!ok && ca.LastException != null)
                {
                    if (!outOfDateError && !otherError)
                    {
                        outOfDateError = true;     // Remaining errors are handled as exception
                    }
                    outOfDateMessage = new StringBuilder();
                    Exception ex     = ca.LastException;

                    while (ex != null)
                    {
                        outOfDateMessage.AppendLine(ex.Message);
                        ex = ex.InnerException;
                    }

                    if (!string.IsNullOrEmpty(itemPath))
                    {
                        outOfDateMessage.AppendLine();
                        outOfDateMessage.AppendFormat(PccStrings.WhileCommittingX, itemPath);
                    }
                }
            });

            if (outOfDateMessage != null)
            {
                state.MessageBox.Show(outOfDateMessage.ToString(),
                                      outOfDateError ? PccStrings.OutOfDateCaption : PccStrings.CommitFailedCaption,
                                      MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            if (rslt != null)
            {
                IAnkhServiceEvents ci = GetService <IAnkhServiceEvents>();

                if (ci != null)
                {
                    ci.OnLastChanged(new LastChangedEventArgs(PccStrings.CommittedPrefix, rslt.Revision.ToString()));
                }

                if (!string.IsNullOrEmpty(rslt.PostCommitError))
                {
                    state.MessageBox.Show(rslt.PostCommitError, PccStrings.PostCommitError, MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }

                PostCommit_IssueTracker(state, rslt);
            }
            return(ok);
        }