Пример #1
1
        private static void CheckoutUpdate(Parameters parameters)
        {
            using (var client = new SharpSvn.SvnClient())
            {
                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");
            }
        }
        private long GetLatestCheckinVersion(string serverUrl, string branch)
        {
            try
            {
                using (SharpSvn.SvnClient client = new SharpSvn.SvnClient())
                {
                    client.Authentication.Clear(); // Clear a previous authentication
                    client.Authentication.DefaultCredentials      = new System.Net.NetworkCredential(svnuser, svnpasssword);
                    client.Authentication.SslServerTrustHandlers += Authentication_SslServerTrustHandlers;

                    SvnInfoEventArgs info;

                    string endpoint = serverUrl.TrimEnd('/') + @"/" + branch;

                    client.GetInfo(endpoint, out info);
                    long lastRevision = info.LastChangeRevision;

                    return(lastRevision);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("EXCEPTION - " + ex.Message);
                Console.WriteLine(ex.StackTrace);
                return(-1);
            }
        }
Пример #3
0
        public static string GetInfo(string[] args, string revision)
        {
            Parameters parameters;

            if (!Parameters.TryParse(args, out parameters))
            {
                return("False");
            }

            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

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

                if (!client.GetInfo(target, out svnInfoEventArgs))
                {
                    throw new Exception("SVN info failed");
                }
                Uri svnUrl = svnInfoEventArgs.Uri;
                return(svnInfoEventArgs.Revision.ToString());

                throw new Exception("SVN update failed");
            }
            return("jhgjg");
        }
Пример #4
0
        public static string GetLogText(string[] args, string revision, out Collection <SvnLogEventArgs> logItemsColl)
        {
            Parameters parameters;

            if (!Parameters.TryParse(args, out parameters))
            {
                throw new Exception("TryParse failed");
            }

            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

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

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

                Uri  svnUrl       = svnInfoEventArgs.Uri;
                long revisionLong = long.Parse(revision);

                long revisionLongTo = svnInfoEventArgs.Revision;


                SvnLogArgs Logargs = new SvnLogArgs
                {
                    Range = new SvnRevisionRange(revisionLong, revisionLongTo)
                };
                Collection <SvnLogEventArgs> logItems;
                //  client.GetLog(svnUrl, Logargs, out logItems);
                client.GetLog(svnUrl, out logItemsColl);

                string AlllogText = "";
                for (int i = logItemsColl.Count - 1; i > 0; i--)
                {
                    AlllogText = AlllogText + (Char)13 + (Char)10 +
                                 logItemsColl[i].Revision.ToString() + " " + logItemsColl[i].Time.ToString() + " " + logItemsColl[i].LogMessage;
                }



                return(AlllogText);

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



            return("jhgjg");
        }
Пример #5
0
        public static string UpdateToRevision(string[] args, string revision)
        {
            Parameters parameters;

            if (!Parameters.TryParse(args, out parameters))
            {
                return("False");
            }

            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

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

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

                Uri  svnUrl       = svnInfoEventArgs.Uri;
                long revisionLong = long.Parse(revision);


                //update to revision

                //DebugMessage(parameters, "Updating");
                SvnUpdateArgs SvnArgs = new SvnUpdateArgs();
                //// If args.Revision is not set, it defaults to fetch the HEAD revision.
                SvnArgs.Revision = revisionLong;
                if (client.Update(parameters.Path, SvnArgs, out svnUpdateResult))
                {
                    DebugMessage(parameters, "Done");

                    Console.WriteLine("Updated to r" + svnUpdateResult.Revision);
                    return("true");
                }
                throw new Exception("SVN update failed");
            }
            return("jhgjg");
        }
Пример #6
0
        private static void CheckoutUpdate(Parameters parameters)
        {
            using (var client = new SharpSvn.SvnClient())
            {
                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");
            }
        }
Пример #7
0
        public static void Diff_ReposDiff(string[] args, long Rev1, long Rev2)
        {
            //string clientDiff = this.RunCommand("svn", "diff -r 1:5 " + this.ReposUrl);

            MemoryStream outstream = new MemoryStream();
            MemoryStream errstream = new MemoryStream();

            SvnDiffArgs a = new SvnDiffArgs();

            Parameters parameters;

            if (!Parameters.TryParse(args, out parameters))
            {
                return;
            }

            using (var client = new SharpSvn.SvnClient())
            {
                SetUpClient(parameters, client);

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

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

                Uri svnUrl = svnInfoEventArgs.Uri;

                a.ErrorStream = errstream;

                try
                {
                    client.Diff(target, new SvnRevisionRange(Rev1, Rev2), a, outstream);
                }

                catch (Exception)
                {
                    throw new Exception("SVN diff failed");
                    //  return ;
                }


                return;
            }



            //string err = Encoding.Default.GetString(errstream.ToArray());
            //Assert.That(err, Is.EqualTo(string.Empty), "Error in diff: " + err);

            //string apiDiff = Encoding.Default.GetString(outstream.ToArray());
            //string[] clientLines = clientDiff.Split('\n');
            //string[] apiLines = apiDiff.Split('\n');
            //Array.Sort<string>(clientLines);
            //Array.Sort<string>(apiLines);

            //Assert.That(apiLines, Is.EqualTo(clientLines), "Diffs differ");
        }