Exemplo n.º 1
0
        /// <summary>
        /// Actual method to be executed for the implementing task
        /// </summary>
        /// <param name="client">The instance of the SVN client</param>
        /// <returns></returns>
        public override bool ExecuteCommand(SvnClient client)
        {
            SvnRevertArgs args = new SvnRevertArgs();
            args.Depth = Recursive ? SvnDepth.Infinity : SvnDepth.Children;

            return client.Revert(RepositoryPath, args);
        }
Exemplo n.º 2
0
        public void TestGetDeletions()
        {
            StatusCache cache = new StatusCache();
            this.Client.Delete(Path.Combine( this.WcPath, "Class1.cs" ));
            this.Client.Delete(Path.Combine( this.WcPath, "WindowsApplication.sln" ));

            // should be two deletions now
            cache.Status(this.WcPath, SvnDepth.Infinity);
            IList deletions = cache.GetDeletions( this.WcPath );
            Assert.AreEqual( 2, deletions.Count );

            // undelete one
            this.Client.Revert(Path.Combine( this.WcPath, "Class1.cs" ));
            deletions = cache.GetDeletions( this.WcPath );
            Assert.AreEqual( 1, deletions.Count );

            // this one should still be deleted
            Assert.AreEqual( Path.Combine( this.WcPath, "WindowsApplication.sln" ),
                ((SvnItem)deletions[0]).Path);

            // undelete all
            SvnRevertArgs a = new SvnRevertArgs();
            a.Depth = SvnDepth.Infinity;
            this.Client.Revert(this.WcPath, a);
            deletions = cache.GetDeletions( this.WcPath );
            Assert.AreEqual( 0, deletions.Count );
        }
Exemplo n.º 3
0
        public void TestGetDeletions()
        {
            StatusCache cache = new StatusCache();

            this.Client.Delete(Path.Combine(this.WcPath, "Class1.cs"));
            this.Client.Delete(Path.Combine(this.WcPath, "WindowsApplication.sln"));

            // should be two deletions now
            cache.Status(this.WcPath, SvnDepth.Infinity);
            IList deletions = cache.GetDeletions(this.WcPath);

            Assert.AreEqual(2, deletions.Count);

            // undelete one
            this.Client.Revert(Path.Combine(this.WcPath, "Class1.cs"));
            deletions = cache.GetDeletions(this.WcPath);
            Assert.AreEqual(1, deletions.Count);

            // this one should still be deleted
            Assert.AreEqual(Path.Combine(this.WcPath, "WindowsApplication.sln"),
                            ((SvnItem)deletions[0]).Path);

            // undelete all
            SvnRevertArgs a = new SvnRevertArgs();

            a.Depth = SvnDepth.Infinity;
            this.Client.Revert(this.WcPath, a);
            deletions = cache.GetDeletions(this.WcPath);
            Assert.AreEqual(0, deletions.Count);
        }
Exemplo n.º 4
0
        public override void Revert(FilePath[] paths, bool recurse, IProgressMonitor monitor)
        {
            SvnRevertArgs args = new SvnRevertArgs();

            BindMonitor(args, monitor);
            args.Depth = recurse ? SvnDepth.Infinity : SvnDepth.Children;
            client.Revert(paths.ToStringArray(), args);
        }
Exemplo n.º 5
0
        public override void Revert(FilePath[] paths, bool recurse, IProgressMonitor monitor)
        {
            var args = new SvnRevertArgs {
                Depth = recurse ? SvnDepth.Infinity : SvnDepth.Children,
            };

            BindMonitor(monitor);
            lock (client)
                client.Revert(paths.ToStringArray(), args);
        }
Exemplo n.º 6
0
        private void ModifyFile(out string oldContents, out string newContents, string filePath,
                                string revertPath, SvnDepth depth)
        {
            using (StreamReader reader = new StreamReader(filePath))
                oldContents = reader.ReadToEnd();
            using (StreamWriter writer = new StreamWriter(filePath))
                writer.WriteLine("mooooooo");

            SvnRevertArgs a = new SvnRevertArgs();

            a.Depth = depth;
            this.Client.Revert(revertPath, a);

            using (StreamReader reader = new StreamReader(filePath))
                newContents = reader.ReadToEnd();
        }
Exemplo n.º 7
0
        private void PrepareWorkingDir()
        {
            var workingDir = new DirectoryInfo(_g.WorkingDir);

            if (!workingDir.Exists)
            {
                _g.Svn.CheckOut(new SvnUriTarget(_g.Destination), _g.WorkingDir);
                return;
            }
            _g.Svn.CleanUp(_g.WorkingDir);
            Collection <SvnStatusEventArgs> statuses;

            _g.Svn.GetStatus(_g.WorkingDir, _infiniteStatus, out statuses);
            var infiniteRevert = new SvnRevertArgs {
                Depth = SvnDepth.Infinity
            };

            foreach (var e in from x in statuses orderby x.Path descending select x)
            {
                switch (e.LocalContentStatus)
                {
                case SvnStatus.Added:
                    _g.Svn.Revert(e.Path, infiniteRevert);
                    string destinationPath = e.Path;
                    if (File.Exists(destinationPath))
                    {
                        File.Delete(destinationPath);
                    }
                    if (Directory.Exists(destinationPath))
                    {
                        Directory.Delete(destinationPath, true);
                    }
                    break;

                case SvnStatus.NotVersioned:
                    DeleteFromFileSystem(e);
                    break;

                default:
                    _g.Svn.Revert(e.Path);
                    break;
                }
            }
            _g.Svn.Update(_g.WorkingDir, _ignoreExternalUpdate);
        }
Exemplo n.º 8
0
        public bool Rollback(string solutionDirectoryPath, RenameContext context)
        {
            using (SvnClient svnClient = new SvnClient())
            {
                // TODO NKO Do someting with the changelist
                Collection <SvnListChangeListEventArgs> changeList;
                svnClient.GetChangeList(solutionDirectoryPath, out changeList);

                SvnRevertArgs revertArgs = new SvnRevertArgs {
                    Depth = SvnDepth.Infinity
                };
                svnClient.Revert(solutionDirectoryPath, revertArgs);
            }

            // Now delete the folder that was created for the new project.
            // Note: Can not use svnclient.Delete because the folder and all containing files werent ever checked in.
            Directory.Delete(context.NewProject.ProjectDirectory, true);

            // And do an update to get a clean repository state again.
            UpdateWorkingCopy(solutionDirectoryPath);

            return(true);
        }
Exemplo n.º 9
0
        static int Main(string[] args)
        {
            try
            {
                Console.WriteLine("Svn2: {0}", Assembly.GetExecutingAssembly().GetName().Version);

                if (args.Length < 1)
                {
                    Usage();
                    return(-2);
                }

                string command = args[0];
                if (command == "/?" || command == "-?" || command == "--help")
                {
                    Usage();
                    return(-2);
                }

                string path = (args.Length == 2)
                    ? Path.GetFullPath(args[1])
                    : Path.GetFullPath(Environment.CurrentDirectory);

                SvnClient client = new SvnClient();

                switch (command)
                {
                case "sync":
                {
                    SvnStatusArgs statusArgs = new SvnStatusArgs();
                    statusArgs.Depth        = SvnDepth.Infinity;
                    statusArgs.ThrowOnError = true;
                    client.Status(path, statusArgs, new EventHandler <SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e)
                        {
                            switch (e.LocalContentStatus)
                            {
                            case SvnStatus.NotVersioned:
                                Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath);
                                if (File.Exists(e.FullPath))
                                {
                                    FileSystem.DeleteFile(e.FullPath, UIOption.OnlyErrorDialogs,
                                                          RecycleOption.SendToRecycleBin);
                                }
                                else if (Directory.Exists(e.FullPath))
                                {
                                    FileSystem.DeleteDirectory(e.FullPath, UIOption.OnlyErrorDialogs,
                                                               RecycleOption.SendToRecycleBin);
                                }
                                break;
                            }
                        }));
                }
                break;

                case "cleanup":
                {
                    Console.WriteLine("Cleaning up {0}", path);
                    SvnCleanUpArgs cleanupArgs = new SvnCleanUpArgs();
                    cleanupArgs.ThrowOnError = true;
                    cleanupArgs.Notify      += new EventHandler <SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e)
                        {
                            Console.WriteLine(" L {0}", e.FullPath);
                        });
                    client.CleanUp(path, cleanupArgs);
                }
                break;

                case "revert":
                {
                    Console.WriteLine("Reverting {0}", path);
                    SvnRevertArgs revertArgs = new SvnRevertArgs();
                    revertArgs.Depth        = SvnDepth.Infinity;
                    revertArgs.ThrowOnError = true;
                    revertArgs.Notify      += new EventHandler <SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e)
                        {
                            Console.WriteLine(" R {0}", e.FullPath);
                        });
                    client.Revert(path, revertArgs);
                }
                break;

                case "status":
                {
                    SvnStatusArgs statusArgs = new SvnStatusArgs();
                    statusArgs.Depth        = SvnDepth.Infinity;
                    statusArgs.ThrowOnError = true;
                    client.Status(path, statusArgs, new EventHandler <SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e)
                        {
                            Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath);
                        }));
                }
                break;

                default:
                    throw new Exception(string.Format("Unsupported '{0}' command", command));
                }

                return(0);
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
#if DEBUG
                Console.Error.WriteLine(ex.StackTrace);
#endif
                return(-1);
            }
        }
Exemplo n.º 10
0
        private void ModifyFile(out string oldContents, out string newContents, string filePath,
            string revertPath, SvnDepth depth)
        {
            using (StreamReader reader = new StreamReader(filePath))
                oldContents = reader.ReadToEnd();
            using (StreamWriter writer = new StreamWriter(filePath))
                writer.WriteLine("mooooooo");

            SvnRevertArgs a = new SvnRevertArgs();
            a.Depth = depth;
            this.Client.Revert(revertPath, a);

            using (StreamReader reader = new StreamReader(filePath))
                newContents = reader.ReadToEnd();
        }
Exemplo n.º 11
0
		public override void Revert (FilePath[] paths, bool recurse, ProgressMonitor monitor)
		{
			var args = new SvnRevertArgs {
				Depth = recurse ? SvnDepth.Infinity : SvnDepth.Children,
			};
			BindMonitor (monitor);
			lock (client) 
				client.Revert (paths.ToStringArray (), args);
		}
Exemplo n.º 12
0
        private void MaybeRevert(string newName, SvnEntry toBefore)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            if (toBefore == null)
            {
                return;
            }

            SvnInfoArgs      ia   = new SvnInfoArgs();
            SvnInfoEventArgs info = null;

            ia.ThrowOnError = false;
            ia.Depth        = SvnDepth.Empty;
            ia.Info        += delegate(object sender, SvnInfoEventArgs e) { e.Detach(); info = e; };

            if (!Client.Info(newName, ia, null) || info == null)
            {
                return;
            }

            // Use SvnEntry to peek below the current delete
            if (toBefore.RepositoryId != info.RepositoryId ||
                toBefore.Uri != info.CopyFromUri ||
                toBefore.Revision != info.CopyFromRevision)
            {
                return;
            }

            using (MarkIgnoreRecursive(newName))
                using (MoveAway(newName))
                {
                    SvnRevertArgs ra = new SvnRevertArgs();
                    ra.Depth        = SvnDepth.Empty;
                    ra.ThrowOnError = false;

                    // Do a quick check if we can safely revert with depth infinity
                    using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0))
                    {
                        SvnStatusArgs sa = new SvnStatusArgs();
                        sa.IgnoreExternals = true;
                        sa.ThrowOnError    = false;
                        bool modifications = false;
                        if (Client.Status(newName, sa,
                                          delegate(object sender, SvnStatusEventArgs e)
                        {
                            if (e.Conflicted ||
                                (e.LocalPropertyStatus != SvnStatus.Normal &&
                                 e.LocalPropertyStatus != SvnStatus.None))
                            {
                                e.Cancel = modifications = true;
                            }
                            else if (e.FullPath == newName)
                            {
                                return;
                            }

                            switch (e.LocalNodeStatus)
                            {
                            case SvnStatus.None:
                            case SvnStatus.Normal:
                            case SvnStatus.Modified:               // Text only change is ok
                            case SvnStatus.Ignored:
                            case SvnStatus.External:
                            case SvnStatus.NotVersioned:
                                break;

                            default:
                                e.Cancel = modifications = true;
                                break;
                            }
                        }) &&
                            !modifications)
                        {
                            ra.Depth = SvnDepth.Infinity;
                        }
                    }

                    Client.Revert(newName, ra);
                }
        }
Exemplo n.º 13
0
        public override void OnExecute(CommandEventArgs e)
        {
            List <SvnItem>            toRevert     = new List <SvnItem>();
            HybridCollection <string> contained    = new HybridCollection <string>(StringComparer.OrdinalIgnoreCase);
            HybridCollection <string> checkedItems = null;

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
            {
                if (contained.Contains(i.FullPath))
                {
                    continue;
                }

                contained.Add(i.FullPath);

                if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty) || i.IsConflicted)
                {
                    toRevert.Add(i);
                }
            }

            Predicate <SvnItem> initialCheckedFilter = null;

            if (toRevert.Count > 0)
            {
                checkedItems = new HybridCollection <string>(contained, StringComparer.OrdinalIgnoreCase);

                initialCheckedFilter = delegate(SvnItem item)
                {
                    return(checkedItems.Contains(item.FullPath));
                };
            }

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(true))
            {
                if (contained.Contains(i.FullPath))
                {
                    continue;
                }

                contained.Add(i.FullPath);

                if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty))
                {
                    toRevert.Add(i);
                }
            }

            if (e.PromptUser || (!e.DontPrompt && !Shift))
            {
                using (PendingChangeSelector pcs = new PendingChangeSelector())
                {
                    pcs.Text = CommandStrings.RevertDialogTitle;

                    pcs.PreserveWindowPlacement = true;

                    pcs.LoadItems(toRevert, null, initialCheckedFilter);

                    if (pcs.ShowDialog(e.Context) != DialogResult.OK)
                    {
                        return;
                    }

                    toRevert.Clear();
                    toRevert.AddRange(pcs.GetSelectedItems());
                }
            }


            IAnkhOpenDocumentTracker documentTracker = e.GetService <IAnkhOpenDocumentTracker>();

            ICollection <string> revertPaths = SvnItem.GetPaths(toRevert);

            documentTracker.SaveDocuments(revertPaths);

            // Revert items backwards to make sure we revert children before their ancestors
            toRevert.Sort(delegate(SvnItem i1, SvnItem i2)
            {
                bool add1 = i1.IsAdded || i1.IsReplaced;
                bool add2 = i2.IsAdded || i2.IsReplaced;

                if (add1 && !add2)
                {
                    return(-1);
                }
                else if (add2 && !add1)
                {
                    return(1);
                }
                else if (add1 && add2)
                {
                    return(-StringComparer.OrdinalIgnoreCase.Compare(i1.FullPath, i2.FullPath));
                }

                return(StringComparer.OrdinalIgnoreCase.Compare(i1.FullPath, i2.FullPath));
            });

            // perform the actual revert
            using (DocumentLock dl = documentTracker.LockDocuments(revertPaths, DocumentLockType.NoReload))
                using (dl.MonitorChangesForReload())
                {
                    e.GetService <IProgressRunner>().RunModal(CommandStrings.Reverting,
                                                              delegate(object sender, ProgressWorkerArgs a)
                    {
                        SvnRevertArgs ra = new SvnRevertArgs();
                        ra.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_DIRECTORY, SvnErrorCode.SVN_ERR_WC_INVALID_OPERATION_DEPTH); // Parent revert invalidated this change
                        ra.Depth = SvnDepth.Empty;
                        List <SvnItem> toRevertWithInfinity = new List <SvnItem>();

                        foreach (SvnItem item in toRevert)
                        {
                            if (!a.Client.Revert(item.FullPath, ra))
                            {
                                switch (ra.LastException.SvnErrorCode)
                                {
                                case SvnErrorCode.SVN_ERR_WC_INVALID_OPERATION_DEPTH:
                                    toRevertWithInfinity.Add(item);
                                    break;
                                }
                            }
                        }

                        ra = new SvnRevertArgs();
                        ra.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_DIRECTORY);
                        ra.Depth = SvnDepth.Infinity;
                        foreach (SvnItem item in toRevertWithInfinity)
                        {
                            SvnStatusArgs sa          = new SvnStatusArgs();
                            sa.RetrieveIgnoredEntries = false;
                            sa.IgnoreExternals        = true;
                            sa.ThrowOnError           = false;
                            bool modifications        = false;

                            using (new SharpSvn.Implementation.SvnFsOperationRetryOverride(0))
                            {
                                if (!a.Client.Status(item.FullPath, sa,
                                                     delegate(object ss, SvnStatusEventArgs ee)
                                {
                                    if (ee.FullPath == item.FullPath)
                                    {
                                        return;
                                    }

                                    if (ee.Conflicted ||
                                        (ee.LocalPropertyStatus != SvnStatus.Normal && ee.LocalPropertyStatus != SvnStatus.None))
                                    {
                                        ee.Cancel = modifications = true;
                                    }
                                    else
                                    {
                                        switch (ee.LocalNodeStatus)
                                        {
                                        case SvnStatus.None:
                                        case SvnStatus.Normal:
                                        case SvnStatus.Ignored:
                                        case SvnStatus.External:
                                        case SvnStatus.NotVersioned:
                                            break;

                                        default:
                                            ee.Cancel = modifications = true;
                                            break;
                                        }
                                    }
                                }))
                                {
                                    modifications = true;
                                }
                            }

                            if (!modifications)
                            {
                                a.Client.Revert(item.FullPath, ra);
                            }
                        }
                    });
                }
        }
Exemplo n.º 14
0
        /// <summary>
        /// svn代码获取
        /// </summary>
        /// <param name="svnuri">svn地址</param>
        static void SVNUpdate(string svnuri, out string logmessage, out long reversion)
        {
            logmessage = "";
            reversion  = 0;
            using (SvnClient client = new SvnClient())
            {
                var localpath = "d:\\sharpsvn";
                localpath = @"E:\project\ccms\CCMS_V7_HBYD_R";
                var username = "";
                var pwd      = "";
                client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd);
                //如果项目不存在则checkout,否则进行update
                if (!Directory.Exists(localpath))
                {
                    client.CheckOut(new Uri(svnuri), localpath);
                    // Console.WriteLine("svn checkout success");
                }
                else
                {
                    SvnInfoEventArgs serverInfo;
                    SvnInfoEventArgs clientInfo;
                    SvnUriTarget     repos = new SvnUriTarget(svnuri);
                    SvnPathTarget    local = new SvnPathTarget(localpath);
                    SvnUpdateArgs    args  = new SvnUpdateArgs();
                    args.Depth = SvnDepth.Infinity;
                    var  svnService    = new SvnService();
                    long version       = 0;
                    long clientVersion = -1;
                    var  msg           = "";
                    args.Notify += delegate(object sender, SvnNotifyEventArgs e)
                    {
                        //if (svnService.GetNotifyAction(e.Action) == "添加")
                        //{
                        //    msg += "\r\n添加" + e.FullPath;
                        //}
                        //if (svnService.GetNotifyAction(e.Action) == "更新删除")
                        //{
                        //    msg += "\r\n删除:" + e.FullPath;
                        //}
                        //if (svnService.GetNotifyAction(e.Action) == "更新修改")
                        //{
                        //    msg += "\r\n修改" + e.FullPath;
                        //}
                        msg    += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath;
                        version = e.Revision;
                    };


                    client.GetInfo(repos, out serverInfo);
                    client.GetInfo(local, out clientInfo);
                    clientVersion = clientInfo.Revision;

                    //if (clientVersion < version)//客户端version必须小于服务端才更新
                    //{
                    client.CleanUp(localpath);

                    SvnRevertArgs args2 = new SvnRevertArgs()
                    {
                        Depth = SvnDepth.Infinity
                    };


                    client.Revert(localpath, args2);
                    client.Update(localpath, args);

                    //获取消息
                    Collection <SvnLogEventArgs> logitems;
                    //if (version > 0 && clientVersion < version)
                    if (msg.Length > 5)
                    {
                        reversion   = version;
                        logmessage += "\r\n变更文件:" + msg;
                        client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems);
                        // client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems);
                        foreach (var logentry in logitems)
                        {
                            string author  = logentry.Author;
                            string message = logentry.LogMessage;
                            //DateTime checkindate = logentry.Time;
                            logmessage += "\r\n";
                            logmessage += string.Format("提交人:{0} ,日志: {1}", author, message) + "\r\n";
                        }
                    }
                    //}


                    // Console.WriteLine(string.Format("serverInfo revision of {0} is {1}", repos, serverInfo.Revision));
                    //Console.WriteLine(string.Format("clientInfo revision of {0} is {1}", local, clientInfo.Revision));
                    // Console.WriteLine("代码获取成功");
                }
            }//
        }
Exemplo n.º 15
0
        /// <summary>
        /// svn代码获取
        /// </summary>
        /// <param name="svnuri">svn地址</param>
        static void SVNUpdate(string svnuri, out string logmessage, out long reversion)
        {
            logmessage = "";
            reversion  = 0;
            long clientVersion = -1;

            using (SvnClient client = new SvnClient())
            {
                try
                {
                    var localpath = WorkPath + @"\" + ProjCode + @"\" + BranchName;
                    var username  = ConfigHelper.GetValue("SVNUser");
                    var pwd       = ConfigHelper.GetValue("SVNpwd");
                    client.Authentication.DefaultCredentials = new System.Net.NetworkCredential(username, pwd);
                    //notiny = "正在检查本地版本...";
                    //ShowInfo();
                    //SvnInfoEventArgs clientInfo;
                    //bool okc = SC.GetInfo(local, out clientInfo);
                    //if (oks && okc) //如果客户端服务端都会成功, 则对比服务器版本, 否则返回true 执行更新命令
                    //{
                    //    result = (serverInfo.Revision > clientInfo.Revision);
                    //}

                    //如果项目不存在则checkout,否则进行update
                    if (!Directory.Exists(localpath))
                    {
                        client.CheckOut(new Uri(svnuri), localpath);
                        Console.WriteLine("svn checkout success");
                    }
                    else
                    {
                        SvnInfoEventArgs serverInfo;
                        SvnInfoEventArgs clientInfo;
                        SvnUriTarget     repos = new SvnUriTarget(svnuri);
                        SvnPathTarget    local = new SvnPathTarget(localpath);
                        SvnUpdateArgs    args  = new SvnUpdateArgs();
                        args.Depth = SvnDepth.Infinity;
                        var  svnService = new SvnService();
                        long version    = 0;

                        var msg = "";
                        args.Notify += delegate(object sender, SvnNotifyEventArgs e)
                        {
                            //if (svnService.GetNotifyAction(e.Action) == "添加")
                            //{
                            //    msg += "\r\n添加" + e.FullPath;
                            //}
                            //if (svnService.GetNotifyAction(e.Action) == "更新删除")
                            //{
                            //    msg += "\r\n删除:" + e.FullPath;
                            //}
                            //if (svnService.GetNotifyAction(e.Action) == "更新修改")
                            //{
                            //    msg += "\r\n修改" + e.FullPath;
                            //}
                            msg    += "\r\n" + (svnService.GetNotifyAction(e.Action)) + ":" + e.FullPath;
                            version = e.Revision;
                            Console.WriteLine(msg);
                        };


                        client.GetInfo(repos, out serverInfo);
                        client.GetInfo(local, out clientInfo);
                        clientVersion = clientInfo.Revision;



                        //if (clientVersion < version)//客户端version必须小于服务端才更新
                        //{


                        //client.Resolve(localpath, SvnAccept.Base);//解决冲突
                        ////解决冲突
                        //Collection<SvnStatusEventArgs> statuses;
                        //client.GetStatus(localpath, out statuses);

                        //foreach (var item in statuses)
                        //{
                        //    if (item.Conflicted)
                        //    {
                        //        client.Resolve(item.FullPath, SvnAccept.Working);
                        //        Console.WriteLine("处理冲突文件:" + item.FullPath);
                        //        logmessage += "处理冲突文件:" + item.FullPath;
                        //    }
                        //}


                        client.CleanUp(localpath);

                        SvnRevertArgs revertArgs = new SvnRevertArgs()
                        {
                            Depth = SvnDepth.Infinity
                        };                                                                           //撤销本地所做的修改
                        client.Revert(localpath, revertArgs);
                        client.Update(localpath, args);

                        //获取消息
                        Collection <SvnLogEventArgs> logitems;
                        //if (version > 0 && clientVersion < version)
                        logmessage += "变更文件:" + msg;

                        if (version > 0 && clientVersion < version)
                        {
                            reversion = version;
                            client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(clientVersion + 1, version)), out logitems);
                            //client.GetLog(new Uri(svnuri), new SvnLogArgs(new SvnRevisionRange(version, version)), out logitems);
                            foreach (var logentry in logitems)
                            {
                                string author  = logentry.Author;
                                string message = logentry.LogMessage;
                                //DateTime checkindate = logentry.Time;
                                logmessage += string.Format("\r\n提交人:{0} ,日志: {1}", author, message);
                            }
                        }
                        //}
                    }
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);
                    logmessage = ex.ToString();
                }
            }
        }
Exemplo n.º 16
0
        static int Main(string[] args)
        {
            try
            {
                Console.WriteLine("Svn2: {0}", Assembly.GetExecutingAssembly().GetName().Version);

                if (args.Length < 1)
                {
                    Usage();
                    return -2;
                }

                string command = args[0];
                if (command == "/?" || command == "-?" || command == "--help")
                {
                    Usage();
                    return -2;
                }

                string path = (args.Length == 2) 
                    ? Path.GetFullPath(args[1])
                    : Path.GetFullPath(Environment.CurrentDirectory);

                SvnClient client = new SvnClient();

                switch (command)
                {
                    case "sync":
                        {
                            SvnStatusArgs statusArgs = new SvnStatusArgs();
                            statusArgs.Depth = SvnDepth.Infinity;
                            statusArgs.ThrowOnError = true;
                            client.Status(path, statusArgs, new EventHandler<SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e)
                            {
                                switch (e.LocalContentStatus)
                                {
                                    case SvnStatus.NotVersioned:
                                        Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath);
                                        if (File.Exists(e.FullPath))
                                        {
                                            FileSystem.DeleteFile(e.FullPath, UIOption.OnlyErrorDialogs,
                                                RecycleOption.SendToRecycleBin);
                                        }
                                        else if (Directory.Exists(e.FullPath))
                                        {
                                            FileSystem.DeleteDirectory(e.FullPath, UIOption.OnlyErrorDialogs,
                                                RecycleOption.SendToRecycleBin);
                                        }
                                        break;
                                }
                            }));
                        }
                        break;
                    case "cleanup":
                        {
                            Console.WriteLine("Cleaning up {0}", path);
                            SvnCleanUpArgs cleanupArgs = new SvnCleanUpArgs();
                            cleanupArgs.ThrowOnError = true;
                            cleanupArgs.Notify += new EventHandler<SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e)
                                {
                                    Console.WriteLine(" L {0}", e.FullPath);
                                });
                            client.CleanUp(path, cleanupArgs);
                        }
                        break;
                    case "revert":
                        {
                            Console.WriteLine("Reverting {0}", path);
                            SvnRevertArgs revertArgs = new SvnRevertArgs();
                            revertArgs.Depth = SvnDepth.Infinity;
                            revertArgs.ThrowOnError = true;
                            revertArgs.Notify += new EventHandler<SvnNotifyEventArgs>(delegate(object sender, SvnNotifyEventArgs e)
                                {
                                    Console.WriteLine(" R {0}", e.FullPath);
                                });
                            client.Revert(path, revertArgs);
                        }
                        break;
                    case "status":
                        {
                            SvnStatusArgs statusArgs = new SvnStatusArgs();
                            statusArgs.Depth = SvnDepth.Infinity;
                            statusArgs.ThrowOnError = true;
                            client.Status(path, statusArgs, new EventHandler<SvnStatusEventArgs>(delegate(object sender, SvnStatusEventArgs e)
                                {
                                    Console.WriteLine(" {0} {1}", StatusToChar(e.LocalContentStatus), e.FullPath);
                                }));
                        }
                        break;
                    default:
                        throw new Exception(string.Format("Unsupported '{0}' command", command));
                }

                return 0;
            }
            catch (Exception ex)
            {
                Console.Error.WriteLine(ex.Message);
#if DEBUG
                Console.Error.WriteLine(ex.StackTrace);
#endif
                return -1;
            }
        }
Exemplo n.º 17
0
        public void repoStart()
        {
            SvnRevertArgs revertArgs = new SvnRevertArgs()
            {
                Depth = SvnDepth.Infinity
            };

            Stopwatch stopwatch = Stopwatch.StartNew();

            Parallel.ForEach(repoDataSet.Tables["Repo"].Rows.Cast <DataRow>(), row =>
            {
                string repoName = row[0].ToString();
                string repoType = row[1].ToString() + "s";
                string repoUrl  = row[2].ToString();
                string repoPath = $@"{repoType}\{repoName}";


                long currentLap;
                long totalLap;
                currentLap = stopwatch.ElapsedMilliseconds;

                try
                {
                    using (SvnClient client = new SvnClient())
                    {
                        if (System.IO.Directory.Exists($@"{repoPath}\.svn"))
                        {
                            Collection <SvnLogEventArgs> logitems;

                            SvnInfoEventArgs remoteRev;
                            client.GetInfo(repoUrl, out remoteRev);

                            SvnInfoEventArgs localRev;
                            client.GetInfo(repoPath, out localRev);

                            SvnLogArgs logArgs = new SvnLogArgs()
                            {
                                Start = localRev.Revision + 1,
                                End   = remoteRev.Revision
                            };

                            if (localRev.Revision < remoteRev.Revision)
                            {
                                client.Revert(repoPath, revertArgs);
                                client.Update(repoPath);
                                totalLap = stopwatch.ElapsedMilliseconds - currentLap;

                                client.GetLog(repoPath, logArgs, out logitems);

                                foreach (var logentry in logitems)
                                {
                                    String logString = logentry.LogMessage.Replace(System.Environment.NewLine, " ");
                                    WriteLog(repoLog, $@"[{Name}-v{Version}] {repoName} r{logentry.Revision}: {logString}");
                                }

                                WriteLog(repoLog, $"[{Name}-v{Version}] updated [{repoType}] {repoName} from {localRev.Revision} to {remoteRev.Revision} in {totalLap} ms.");
                                if (repoType != "Profiles")
                                {
                                    restartNeeded = true;
                                }
                            }
                        }
                        else
                        {
                            client.CheckOut(new Uri(repoUrl), repoPath);
                            totalLap = stopwatch.ElapsedMilliseconds - currentLap;
                            WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} checkout complete in {totalLap} ms.");
                            if (repoType != "Profiles")
                            {
                                restartNeeded = true;
                            }
                        }
                    }
                }
                catch (SharpSvn.SvnAuthenticationException e)
                {
                    WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} No more credentials or we tried too many times. {e}");
                }
                catch (System.AccessViolationException e)
                {
                    WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} Access Violation, something is locking the folder. {e}");
                }
                catch (SharpSvn.SvnFileSystemException e)
                {
                    WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} FileSystemException, repo has probably been moved/deleted. {e}");
                }
                catch (SharpSvn.SvnException e)
                {
                    WriteLog(repoLog, $"[{Name}-v{Version}] {repoName} Generic SvnException, do you have tortoiseSVN monitoring this folder? CN users may need a VPN to access GitHub. {e}");

                    WriteLog(repoLog, $"[{Name}-v{Version}] **************************");
                    WriteLog(repoLog, $"[{Name}-v{Version}] This will prevent further updates, delete the {repoName} .svn folder and make sure tortoiseSVN doesn't manage anything repoBuddy does.");
                    WriteLog(repoLog, $"[{Name}-v{Version}] **************************");
                    restartNeeded = false;
                }
            });
            stopwatch.Stop();
            Logging.Write(LogColor, $"[{Name}-v{Version}] processes complete in {stopwatch.ElapsedMilliseconds} ms.");

            MigrateLlamaLibrary();

            if (repoLog.Count > 0)
            {
                using (StreamWriter file = File.CreateText(@"Plugins\repoBuddy\repoLog.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, repoLog);
                }
            }
            if (restartNeeded)
            {
                Logging.Write(LogColor, $"[{Name}-v{Version}] Restarting to reload assemblies.");
                RestartRebornBuddy();
            }
        }
Exemplo n.º 18
0
		public override void Revert (FilePath[] paths, bool recurse, IProgressMonitor monitor)
		{
			SvnRevertArgs args = new SvnRevertArgs ();
			BindMonitor (args, monitor);
			args.Depth = recurse ? SvnDepth.Infinity : SvnDepth.Children;
			lock (client) 
				client.Revert (paths.ToStringArray (), args);
		}
Exemplo n.º 19
0
        public void repoStart()
        {
            SvnRevertArgs revertArgs = new SvnRevertArgs()
            {
                Depth = SvnDepth.Infinity
            };

            Stopwatch stopwatch = Stopwatch.StartNew();

            Parallel.ForEach(repoDataSet.Tables["Repo"].Rows.Cast <DataRow>(), row =>
            {
                string repoName = row[0].ToString();
                string repoType = row[1].ToString() + "s";
                string repoUrl  = row[2].ToString();
                string repoPath = $@"{repoType}\{repoName}";

                long currentLap;
                long totalLap;
                currentLap = stopwatch.ElapsedMilliseconds;

                using (SvnClient client = new SvnClient())
                {
                    if (System.IO.Directory.Exists($@"{repoPath}\.svn"))
                    {
                        SvnInfoEventArgs remoteRev;
                        client.GetInfo(repoUrl, out remoteRev);

                        SvnInfoEventArgs localRev;
                        client.GetInfo(repoPath, out localRev);

                        if (localRev.Revision < remoteRev.Revision)
                        {
                            client.Revert(repoPath, revertArgs);
                            client.Update(repoPath);
                            totalLap = stopwatch.ElapsedMilliseconds - currentLap;
                            WriteLog(repoLog, $"[{Name}] updated [{repoType}] {repoName} from {localRev.Revision} to {remoteRev.Revision} in {totalLap} ms.");
                            if (repoType != "Profiles")
                            {
                                restartNeeded = true;
                            }
                        }
                    }
                    else
                    {
                        client.CheckOut(new Uri(repoUrl), repoPath);
                        totalLap = stopwatch.ElapsedMilliseconds - currentLap;
                        WriteLog(repoLog, $"[{Name}] {repoName} checkout complete in {totalLap} ms.");
                        if (repoType != "Profiles")
                        {
                            restartNeeded = true;
                        }
                    }
                }
            });
            stopwatch.Stop();
            Logging.Write(LogColor, $"[{Name}] processes complete in {stopwatch.ElapsedMilliseconds} ms.");

            if (repoLog.Count > 0)
            {
                using (StreamWriter file = File.CreateText(@"Plugins\repoBuddy\repoLog.json"))
                {
                    JsonSerializer serializer = new JsonSerializer();
                    serializer.Serialize(file, repoLog);
                }
            }
            if (restartNeeded)
            {
                Logging.Write(LogColor, $"[{Name}] Restarting to reload assemblies.");
                RestartRebornBuddy();
            }
        }
        public bool Rollback(string solutionDirectoryPath, RenameContext context)
        {
            using(SvnClient svnClient = new SvnClient())
            {
                // TODO NKO Do someting with the changelist
                Collection<SvnListChangeListEventArgs> changeList;
                svnClient.GetChangeList(solutionDirectoryPath, out changeList);

                SvnRevertArgs revertArgs = new SvnRevertArgs { Depth = SvnDepth.Infinity };
                svnClient.Revert(solutionDirectoryPath, revertArgs);
            }

            // Now delete the folder that was created for the new project.
            // Note: Can not use svnclient.Delete because the folder and all containing files werent ever checked in.
            Directory.Delete(context.NewProject.ProjectDirectory, true);

            // And do an update to get a clean repository state again.
            UpdateWorkingCopy(solutionDirectoryPath);

            return true;
        }
Exemplo n.º 21
0
        public override void OnExecute(CommandEventArgs e)
        {
            List<SvnItem> toRevert = new List<SvnItem>();
            HybridCollection<string> contained = new HybridCollection<string>(StringComparer.OrdinalIgnoreCase);
            HybridCollection<string> checkedItems = null;

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(false))
            {
                if (contained.Contains(i.FullPath))
                    continue;

                contained.Add(i.FullPath);

                if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty) || i.IsConflicted)
                    toRevert.Add(i);
            }

            Predicate<SvnItem> initialCheckedFilter = null;
            if (toRevert.Count > 0)
            {
                checkedItems = new HybridCollection<string>(contained, StringComparer.OrdinalIgnoreCase);

                initialCheckedFilter = delegate(SvnItem item)
                    {
                        return checkedItems.Contains(item.FullPath);
                    };
            }

            foreach (SvnItem i in e.Selection.GetSelectedSvnItems(true))
            {
                if (contained.Contains(i.FullPath))
                    continue;

                contained.Add(i.FullPath);

                if (i.IsModified || (i.IsVersioned && i.IsDocumentDirty))
                    toRevert.Add(i);
            }

            if (e.PromptUser || (!e.DontPrompt && !Shift))
            {
                using (PendingChangeSelector pcs = new PendingChangeSelector())
                {
                    pcs.Text = CommandStrings.RevertDialogTitle;

                    pcs.PreserveWindowPlacement = true;

                    pcs.LoadItems(toRevert, null, initialCheckedFilter);

                    if (pcs.ShowDialog(e.Context) != DialogResult.OK)
                        return;

                    toRevert.Clear();
                    toRevert.AddRange(pcs.GetSelectedItems());
                }
            }

            IAnkhOpenDocumentTracker documentTracker = e.GetService<IAnkhOpenDocumentTracker>();

            ICollection<string> revertPaths = SvnItem.GetPaths(toRevert);
            documentTracker.SaveDocuments(revertPaths);

            // perform the actual revert
            using (DocumentLock dl = documentTracker.LockDocuments(revertPaths, DocumentLockType.NoReload))
            using (dl.MonitorChangesForReload())
            {
                e.GetService<IProgressRunner>().RunModal(CommandStrings.Reverting,
                delegate(object sender, ProgressWorkerArgs a)
                {
                    SvnRevertArgs ra = new SvnRevertArgs();
                    ra.Depth = SvnDepth.Empty;
                    ra.AddExpectedError(SvnErrorCode.SVN_ERR_WC_NOT_DIRECTORY); // Parent revert invalidated this change

                    foreach (SvnItem item in toRevert)
                    {
                        a.Client.Revert(item.FullPath, ra);
                    }
                });
            }
        }