Esempio n. 1
0
        protected virtual void SetRevisionProperties(SvnClient svnClient, SvnCommitResult commitResult, Changeset changeset)
        {
            Boolean success = false;
            String  str_exception_msg;

            str_exception_msg = "";
            try
            {
                success  = true;
                success &= svnClient.SetRevisionProperty(this.SvnFullRepositoryUri, commitResult.Revision, "svn:author", changeset.Username);
                DateTime utc_time = changeset.DateTime.ToUniversalTime();
                success &= svnClient.SetRevisionProperty(this.SvnFullRepositoryUri, commitResult.Revision, "svn:date", utc_time.ToString("O"));
            }
            catch (SharpSvn.SvnException ex)
            {
                success           = false;
                str_exception_msg = ex.ToString();
            }

            if (!success)
            {
                this.LogMessage("Couldn't set author and date for revision! Did you remember to set pre-revprop-change hook?\n\n" + str_exception_msg, commitResult.Revision);
                throw new InvalidOperationException("Failed to set Revision Property");
            }
        }
Esempio n. 2
0
 internal void Commit(string text, SvnCommitArgs args, SvnCommitResult result)
 {
     using (SharpSvn.SvnClient client = new SharpSvn.SvnClient())
     {
         SvnCommitArgs ca = new SvnCommitArgs();
         client.Commit(args.LogMessage, ca);
     }
 }
Esempio n. 3
0
        public static bool Commit(string path, SvnCommitArgs args, out SvnCommitResult result)
        {
            result = null;

            try
            {
                return m_Client.Commit(path, args, out result);
            }
            catch (SvnException ex)
            {
                MessageBox.Show("提交失败 : " + ex.Message, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }

            return false;
        }
Esempio n. 4
0
        public static bool Commit(String path, out SvnCommitResult result)
        {
            result = null;

            try
            {
                return(m_Client.Commit(path, out result));
            }
            catch (SvnException ex)
            {
                MessageBox.Show("提交失败 : " + ex.Message, "系统提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation);
            }

            return(false);
        }
Esempio n. 5
0
        public bool SvnCommit(string path)
        {
            return(DoWithSvn(path, svnClient => {
                svnClient.Authentication.DefaultCredentials = _svnCredentials;
                var args = new SvnCommitArgs {
                    LogMessage = string.Format("Commited by SvnAutoCommitter service via SharpSvn. {0}", path),
                    Depth = SvnDepth.Infinity
                };

                SvnCommitResult svnCommitResult = null;
                var result = svnClient.Commit(path, args, out svnCommitResult);
                if (result)
                {
                    _logger.InfoFormat(
                        svnCommitResult != null
                            ? "SharpSvn has committed {0}"
                            : "SharpSvn tried to commit {0}, but no modification was detected", path
                        );
                }

                return result;
            }));
        }
Esempio n. 6
0
        private void PostCommit_IssueTracker(PendingCommitState state, SvnCommitResult result)
        {
            IssueRepository iRepo = IssueService.CurrentIssueRepository;

            if (iRepo == null)
            {
                return;
            }

            List <Uri> uris = new List <Uri>();

            foreach (PendingChange pc in state.Changes)
            {
                uris.Add(pc.Uri);
            }

            PostCommitArgs pca = new PostCommitArgs(uris.ToArray(), result.Revision, state.LogMessage);

            try
            {
                iRepo.PostCommit(pca);
            }
            catch (Exception ex)
            {
                IAnkhErrorHandler eh = GetService <IAnkhErrorHandler>();

                if (eh != null && eh.IsEnabled(ex))
                {
                    eh.OnError(ex);
                }
                else
                {
                    throw;
                }
            }
        }
Esempio n. 7
0
        public void Copy()
        {
            long lastSyncRevision = 0;

            if (_args.Incremental)
            {
                SvnLogParser logParser = new SvnLogParser(_args.Destination);
                lastSyncRevision = logParser.GetLastSyncedRevisionFromDestination();
                Console.WriteLine("Last revision synched: {0}", lastSyncRevision);
            }

            Console.Write("Collecting svn log: ");

            if (_args.RevisionRange != null)
            {
                Console.Write("{0}:{1} ",
                              _args.RevisionRange.StartRevision,
                              _args.RevisionRange.EndRevision);
            }

            // fetch the source svn respository and
            SvnInfo sourceInfo = new SvnInfo(_args.Source);

            Console.WriteLine("Source SVN root: {0}", sourceInfo.Info.RepositoryRoot);
            Console.WriteLine("Source SVN uri: {0}", sourceInfo.Info.Uri);

            string sourceRelativePath = sourceInfo.Info.Uri.ToString().Remove(
                0, sourceInfo.Info.RepositoryRoot.ToString().Length - 1);

            Console.WriteLine("Relative path: {0}", sourceRelativePath);

            if (!string.IsNullOrEmpty(_args.Root))
            {
                sourceRelativePath = _args.Root;
                Console.WriteLine("Substituting relative path: {0}", sourceRelativePath);
            }

            SvnLogArgs logArgs = new SvnLogArgs();

            logArgs.StrictNodeHistory = _args.StopOnCopy;
            logArgs.ThrowOnError      = true;
            logArgs.Range             = _args.RevisionRange;

            logArgs.RetrieveChangedPaths = true;

            _client.Log(_args.Source, logArgs, new EventHandler <SvnLogEventArgs>(OnLog));
            Console.WriteLine();
            Console.WriteLine("Collected {0} revisions.", _revisions.Count);

            SvnTarget fromSvnTarget = SvnTarget.FromString(_args.Source);

            foreach (KeyValuePair <long, SvnLogEventArgs> revisionPair in _revisions)
            {
                SvnLogEventArgs revision = revisionPair.Value;

                if (_args.Incremental && lastSyncRevision != 0 && lastSyncRevision >= revision.Revision)
                {
                    Console.WriteLine("Skipping revision {0} ({1})", revision.Revision, revision.Time);
                    continue;
                }

                Console.WriteLine("Revision {0} ({1})", revision.Revision, revision.Time);

                if (_args.SimulationOnly)
                {
                    continue;
                }

                SvnExportArgs exportArgs = new SvnExportArgs();
                exportArgs.Overwrite    = true;
                exportArgs.ThrowOnError = true;
                exportArgs.Revision     = revision.Revision;

                SvnUpdateResult exportResult = null;
                _client.Export(fromSvnTarget, _args.Destination, exportArgs, out exportResult);

                if (revision.ChangedPaths == null)
                {
                    throw new Exception(string.Format("No changed paths in rev. {0}",
                                                      revision.Revision));
                }

                SortedList <string, SvnChangeItem> changeItems = new SortedList <string, SvnChangeItem>();

                foreach (SvnChangeItem changeItem in revision.ChangedPaths)
                {
                    changeItems.Add(changeItem.Path, changeItem);
                }

                List <string> filesAdd    = new List <string>();
                List <string> filesDelete = new List <string>();
                List <string> filesModify = new List <string>();

                // add files in forward order (add directories first)
                // delete files in reverse order (delete files first)
                foreach (SvnChangeItem changeItem in changeItems.Values)
                {
                    // anything above (outside) of the source path is ignored, we didn't export that
                    if (!changeItem.Path.StartsWith(sourceRelativePath))
                    {
                        Console.WriteLine("Skipping {0}. Did you need to specify /root:<path>?)", changeItem.Path);
                        continue;
                    }

                    string targetSvnPath = changeItem.Path.Remove(0, sourceRelativePath.Length);
                    string targetOSPath  = targetSvnPath.Replace("/", @"\");
                    string targetPath    = Path.Combine(_args.Destination, targetOSPath);
                    Console.WriteLine(" {0} {1}", changeItem.Action, changeItem.Path);
                    switch (changeItem.Action)
                    {
                    case SvnChangeAction.Add:
                    case SvnChangeAction.Replace:
                        filesAdd.Add(targetPath);
                        break;

                    case SvnChangeAction.Delete:
                        filesDelete.Insert(0, targetPath);
                        break;

                    case SvnChangeAction.Modify:
                        filesModify.Add(targetPath);
                        break;
                    }
                }

                Console.WriteLine("Applying changes @ rev. {0} ...", revision.Revision);

                foreach (string targetPath in filesModify)
                {
                    Console.WriteLine(" M {0}", targetPath);
                }

                foreach (string targetPath in filesAdd)
                {
                    if (!File.Exists(targetPath))
                    {
                        throw new Exception(string.Format("Added file '{0}' doesn't exist. Did you need to specify /root:<path>?",
                                                          targetPath));
                    }

                    Console.WriteLine(" A {0}", targetPath);
                    SvnAddArgs svnAddArgs = new SvnAddArgs();
                    svnAddArgs.ThrowOnError = true;
                    svnAddArgs.Depth        = SvnDepth.Empty;
                    _client.Add(targetPath, svnAddArgs);
                }

                foreach (string targetPath in filesDelete)
                {
                    Console.WriteLine(" D {0}", targetPath);
                    SvnDeleteArgs svnDeleteArgs = new SvnDeleteArgs();
                    svnDeleteArgs.ThrowOnError = true;
                    svnDeleteArgs.Force        = true;
                    _client.Delete(targetPath, svnDeleteArgs);
                }


                SvnCommitArgs commitArgs = new SvnCommitArgs();
                commitArgs.LogMessage  = revision.LogMessage;
                commitArgs.LogMessage += string.Format("\nCopied from {0}, rev. {1} by {2} @ {3} {4}",
                                                       sourceInfo.Info.Uri, revision.Revision, revision.Author, revision.Time.ToShortDateString(), revision.Time.ToShortTimeString());
                commitArgs.ThrowOnError = true;

                Console.WriteLine("Committing changes @ rev. {0} in {1}", revision.Revision, _args.Destination);
                Console.WriteLine("----------------------------------------------------------------------------");
                Console.WriteLine(commitArgs.LogMessage);
                Console.WriteLine("----------------------------------------------------------------------------");

                if (_args.Prompt)
                {
                    while (true)
                    {
                        Console.Write("Commit? [Y/N] ");
                        char k = Char.ToLower(Console.ReadKey().KeyChar);
                        Console.WriteLine();
                        if (k == 'y')
                        {
                            break;
                        }
                        if (k == 'n')
                        {
                            throw new Exception("Aborted by user.");
                        }
                    }
                }

                SvnCommitResult commitResult = null;
                _client.Commit(_args.Destination, commitArgs, out commitResult);
                if (commitResult != null)
                {
                    Console.WriteLine("Commited revision {0}.", commitResult.Revision);
                }
                else
                {
                    Console.WriteLine("There were no committable changes.");
                    Console.WriteLine("Subversion property changes are not supported.");
                }
            }
        }
Esempio n. 8
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);
        }
Esempio n. 9
0
        private void PostCommit_IssueTracker(PendingCommitState state, SvnCommitResult result)
        {
            IAnkhIssueService iService = GetService<IAnkhIssueService>();
            if (iService != null)
            {
                IssueRepository iRepo = iService.CurrentIssueRepository;
                if (iRepo != null)
                {
                    List<Uri> uris = new List<Uri>();
                    foreach (PendingChange pc in state.Changes)
                    {
                        uris.Add(pc.Uri);
                    }

                    PostCommitArgs pca = new PostCommitArgs(uris.ToArray(), result.Revision, state.LogMessage);
                    try
                    {
                        iRepo.PostCommit(pca);
                    }
                    catch { };
                }
            }
        }