Example #1
0
        private static void RevertChangesInDirectory(string directory)
        {
            _log.Debug("Reverting changes in " + directory);

            var revertAttempts = 0;

            while (revertAttempts < 5)
            {
                _log.Debug($"Attempting revert (attempt {++revertAttempts})");

                using (var client = new SvnClient())
                {
                    var result = client.Revert(directory, new SvnRevertArgs
                    {
                        Depth = SvnDepth.Infinity,
                    });

                    if (result)
                    {
                        _log.Debug("Revert succeeded");
                        return;
                    }
                    _log.Warn("Revert attempt failed");
                }
            }

            throw new InvalidOperationException("Unable to revert: " + directory);
        }
Example #2
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);
        }
 public void RevertFile(string pathFile)
 {
     using (var svnClient = new SvnClient())
     {
         svnClient.Revert(pathFile);
     }
 }
Example #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);
        }
 /// <summary>
 /// 执行SVN的Revert操作
 /// </summary>
 public static bool Revert(string localPath, out SvnException svnException)
 {
     try
     {
         bool result = _svnClient.Revert(localPath);
         svnException = null;
         return(result);
     }
     catch (SvnException exception)
     {
         svnException = exception;
         return(false);
     }
 }
Example #6
0
 public void Revert(string[] files, Recurse recurse)
 {
     Debug("SVN: Revert(" + string.Join(",", files) + ", " + recurse + ")");
     BeforeWriteOperation("revert");
     try {
         client.Revert(
             files,
             new SvnRevertArgs {
             Depth = ConvertDepth(recurse)
         });
     } catch (SvnException ex) {
         throw new SvnClientException(ex);
     } finally {
         AfterOperation();
     }
 }
 public override void Revert(string Path)
 {
     if (client == null)
     {
         Init();
     }
     try
     {
         client.Revert(Path, new SvnRevertArgs {
             Depth = SvnDepth.Infinity
         });                                                                 //throw all local changes and return to base copy
     }
     catch (Exception e)
     {
         Reporter.ToUser(eUserMsgKeys.GeneralErrorOccured, e.Message + Environment.NewLine + e.InnerException);
     }
 }
Example #8
0
 public override bool Revert(string Path, ref string error)
 {
     if (client == null)
     {
         Init();
     }
     try
     {
         client.Revert(Path, new SvnRevertArgs {
             Depth = SvnDepth.Infinity
         });                                                                 //throw all local changes and return to base copy
     }
     catch (Exception e)
     {
         error = e.Message + Environment.NewLine + e.InnerException;
         return(false);
     }
     return(true);
 }
Example #9
0
            public bool Update()
            
    {
                    ShowInfo("正在更新....");

                    SC.CleanUp(GetAppLoc());

                    bool ok = SC.Update(GetAppLoc());

                    if(!ok)
                    
        {
                            ShowInfo("未成功,正在清理...");

                            SC.CleanUp(GetAppLoc());
                            ShowInfo("清理完毕,正在更新....");

                            ok = SC.Update(GetAppLoc());
                              if (!ok)
            {
                                {
                                        ShowInfo("正在撤销本地修改....");

                                        SC.Revert(GetAppLoc());
                                        ShowInfo("正在清理....");

                                        SC.CleanUp(GetAppLoc());
                                        ShowInfo("正在更新....");

                                        ok = SC.Update(GetAppLoc());
                                      
                }
            }
                        
        }

                    ShowInfo("更新操作完成");

                    return ok;
                
    }
Example #10
0
        /// <summary>
        /// Revert
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns>true success, false otherwise</returns>
        public bool Revert(string filePath)
        {
            var returnValue = false;
            //try
            //{
            var status = GetSingleItemStatus(filePath);

            if (status.IsModified)
            {
                returnValue = _svnClient.Revert(filePath);
                if (returnValue)
                {
                    UpdateCache(filePath);
                }
            }
            //}
            //catch (Exception e)
            //{
            //    Console.WriteLine(e);
            //}

            return(returnValue);
        }
Example #11
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);
        }
        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;
        }
Example #13
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("代码获取成功");
                }
            }//
        }
Example #14
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();
            }
        }
Example #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();
                }
            }
        }
Example #16
0
        /// <summary>
        /// While the server isn't up to date
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void doSvnUpdate(object sender, DoWorkEventArgs e)
        {
            client         = new SvnClient();
            client.Notify += onSvnNotify;
            client.Authentication.Clear();
            client.Authentication.DefaultCredentials = null;

            System.Console.Out.WriteLine(client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory()));

            Uri rep = client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory());
            Uri rel = new Uri("http://subversion.assembla.com/svn/skyrimonlineupdate/");

            if (rep == null || rep != rel)
            {
                SvnDelete.findSvnDirectories(System.IO.Directory.GetCurrentDirectory());
                exploreDirectory(rel);

                download.Maximum = iCount;
                updating         = true;

                SvnCheckOutArgs args = new SvnCheckOutArgs();
                args.AllowObstructions = true;

                if (client.CheckOut(rel, System.IO.Directory.GetCurrentDirectory(), args, out mResult))
                {
                    updated = true;
                }
            }
            else
            {
                downloadprogress.Text = "Building update list, please be patient...";


                updating = true;
                SvnStatusArgs sa = new SvnStatusArgs();
                sa.RetrieveRemoteStatus = true;

                Collection <SvnStatusEventArgs> r;
                client.GetStatus(System.IO.Directory.GetCurrentDirectory(), sa, out r);

                foreach (SvnStatusEventArgs i in r)
                {
                    client.Revert(i.FullPath);

                    if (i.IsRemoteUpdated)
                    {
                        iCount++;
                    }
                }

                download.Maximum = iCount;
                SvnUpdateArgs args = new SvnUpdateArgs();
                args.AllowObstructions = true;

                if (client.Update(System.IO.Directory.GetCurrentDirectory(), args))
                {
                    updated = true;
                }
                else
                {
                    Application.Exit();
                }
            }
        }
Example #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;

                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();
            }
        }
Example #18
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);
            }
        }
Example #19
0
		public void Revert(string file)
		{
			using (var svn = new SvnClient())
			{
				svn.Revert(file);
			}
		}
Example #20
0
        /// <summary>
        /// While the server isn't up to date
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void doSvnUpdate(object sender, DoWorkEventArgs e)
        {
            client = new SvnClient();
            client.Notify += onSvnNotify;
            client.Authentication.Clear();
            client.Authentication.DefaultCredentials = null;

            System.Console.Out.WriteLine(client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory()));

            Uri rep = client.GetUriFromWorkingCopy(System.IO.Directory.GetCurrentDirectory());
            Uri rel = new Uri("http://subversion.assembla.com/svn/skyrimonlineupdate/");

            if (rep == null || rep != rel)
            {
                SvnDelete.findSvnDirectories(System.IO.Directory.GetCurrentDirectory());
                exploreDirectory(rel);

                download.Maximum = iCount;
                updating = true;

                SvnCheckOutArgs args = new SvnCheckOutArgs();
                args.AllowObstructions = true;

                if (client.CheckOut(rel, System.IO.Directory.GetCurrentDirectory(), args, out mResult))
                {
                    updated = true;
                }

            }
            else
            {
                downloadprogress.Text = "Building update list, please be patient...";

                updating = true;
                SvnStatusArgs sa = new SvnStatusArgs();
                sa.RetrieveRemoteStatus = true;

                Collection<SvnStatusEventArgs> r;
                client.GetStatus(System.IO.Directory.GetCurrentDirectory(), sa, out r);

                foreach (SvnStatusEventArgs i in r)
                {
                    client.Revert(i.FullPath);

                    if (i.IsRemoteUpdated)
                        iCount++;
                }

                download.Maximum = iCount;
                SvnUpdateArgs args = new SvnUpdateArgs();
                args.AllowObstructions = true;

                if (client.Update(System.IO.Directory.GetCurrentDirectory(), args))
                {
                    updated = true;
                }
                else
                {
                    Application.Exit();
                }
            }
        }
Example #21
0
        public static void CheckoutUpdate(Parameters parameters)
        {
            using var client = new SvnClient();
            client.Progress += new EventHandler <SvnProgressEventArgs>(Client_Progress);
            SetUpClient(parameters, client);

            var target = SvnTarget.FromString(parameters.Path);
            SvnInfoEventArgs svnInfoEventArgs;
            SvnUpdateResult  svnUpdateResult;

            var nonExistentUrl = false;
            EventHandler <SvnErrorEventArgs> ignoreNonexistent = (o, eventArgs) =>
            {
                nonExistentUrl = false;
                //if (eventArgs.Exception.SubversionErrorCode == 170000)
                if (eventArgs.Exception.Message.Contains("non-existent in revision"))
                {
                    nonExistentUrl   = true;
                    eventArgs.Cancel = true;
                }
            };

            if (client.GetWorkingCopyRoot(parameters.Path) == null)
            {
                client.SvnError += ignoreNonexistent;
                var getInfoSucceeded = client.GetInfo(SvnUriTarget.FromString(parameters.Url), out svnInfoEventArgs);
                client.SvnError -= ignoreNonexistent;

                if (!getInfoSucceeded)
                {
                    if (nonExistentUrl)
                    {
                        Console.WriteLine("SVN info reported nonexistent URL; creating remote directory.");
                        if (!client.RemoteCreateDirectory(new Uri(parameters.Url), new SvnCreateDirectoryArgs {
                            CreateParents = true, LogMessage = parameters.Message
                        }))
                        {
                            throw new Exception("Create directory failed on " + parameters.Url);
                        }
                    }
                    else
                    {
                        throw new Exception("SVN info failed");
                    }
                }

                DebugMessage(parameters, "Checking out");
                if (client.CheckOut(SvnUriTarget.FromString(parameters.Url), parameters.Path, out svnUpdateResult))
                {
                    DebugMessage(parameters, "Done");
                    Console.WriteLine("Checked out r" + svnUpdateResult.Revision);
                    return;
                }

                throw new Exception("SVN checkout failed");
            }

            if (!client.GetInfo(target, out svnInfoEventArgs))
            {
                throw new Exception("SVN info failed");
            }

            if (!UrlsMatch(svnInfoEventArgs.Uri.ToString(), parameters.Url))
            {
                throw new Exception(string.Format("A different URL is already checked out ({0} != {1})", svnInfoEventArgs.Uri, parameters.Url));
            }

            if (parameters.Cleanup)
            {
                DebugMessage(parameters, "Cleaning up");
                client.CleanUp(parameters.Path);
                DebugMessage(parameters, "Done");
            }

            if (parameters.Revert)
            {
                DebugMessage(parameters, "Reverting");
                client.Revert(parameters.Path);
                DebugMessage(parameters, "Done");
            }

            if (parameters.DeleteUnversioned)
            {
                DebugMessage(parameters, "Deleting unversioned files");
                Collection <SvnStatusEventArgs> changedFiles;
                client.GetStatus(parameters.Path, out changedFiles);
                foreach (var changedFile in changedFiles)
                {
                    if (changedFile.LocalContentStatus == SvnStatus.NotVersioned)
                    {
                        if (changedFile.NodeKind == SvnNodeKind.Directory)
                        {
                            DebugMessage(parameters, "NodeKind is directory for [" + changedFile.FullPath + "]");
                        }
                        if ((File.GetAttributes(changedFile.FullPath) & FileAttributes.Directory) == FileAttributes.Directory)
                        {
                            DebugMessage(parameters, "Deleting directory [" + changedFile.FullPath + "] recursively!");
                            Directory.Delete(changedFile.FullPath, true);
                        }
                        else
                        {
                            DebugMessage(parameters, "Deleting file [" + changedFile.FullPath + "]");
                            File.Delete(changedFile.FullPath);
                        }
                    }
                }
                DebugMessage(parameters, "Done");
            }

            DebugMessage(parameters, "Updating");
            if (client.Update(parameters.Path, out svnUpdateResult))
            {
                DebugMessage(parameters, "Done");
                Console.WriteLine("Updated to r" + svnUpdateResult.Revision);
                return;
            }

            throw new Exception("SVN update failed");
        }
Example #22
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;
            }
        }