Esempio n. 1
0
 public override string GetPathUrl(FilePath path)
 {
     lock (client) {
         Uri u = client.GetUriFromWorkingCopy(path);
         return(u != null?u.ToString() : null);
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Check if the given path is a working copy or not
 /// </summary>
 /// <param name="path">local path to the respository</param>
 /// <returns></returns>
 public static bool IsWorkingCopy(string path)
 {
     using (var client = new SvnClient())
     {
         var uri = client.GetUriFromWorkingCopy(path);
         return uri != null;
     }
 }
Esempio n. 3
0
 public bool IsWorkingCopy(string path)
 {
     using (var svnClient = new SvnClient()) {
         svnClient.Authentication.DefaultCredentials = _svnCredentials;
         var uri = svnClient.GetUriFromWorkingCopy(path);
         return(uri != null);
     }
 }
Esempio n. 4
0
 /// <summary>
 /// Check if the given path is a working copy or not
 /// </summary>
 /// <param name="path">local path to the respository</param>
 /// <returns></returns>
 public static bool IsWorkingCopy(string path)
 {
     using (var client = new SvnClient())
     {
         var uri = client.GetUriFromWorkingCopy(path);
         return(uri != null);
     }
 }
Esempio n. 5
0
        public void Tag(string name, string taggerName, string taggerEmail, string comment, DateTime localTime, string taggedPath)
        {
            /*
             * TempFile commentFile;
             *
             * var args = "tag";
             * AddComment(comment, ref args, out commentFile);
             *
             * // tag names are not quoted because they cannot contain whitespace or quotes
             * args += " -- " + name;
             *
             * using (commentFile)
             * {
             *  var startInfo = GetStartInfo(args);
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_NAME"] = taggerName;
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_EMAIL"] = taggerEmail;
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_DATE"] = GetUtcTimeString(localTime);
             *
             *  ExecuteUnless(startInfo, null);
             * }
             */
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);
                var svnCopyArgs = new SvnCopyArgs {
                    LogMessage = comment, CreateParents = true, AlwaysCopyAsChild = false
                };

                var workingCopyUri = client.GetUriFromWorkingCopy(workingCopyPath);
                var tagsUri        = client.GetUriFromWorkingCopy(tagPath);
                var sourceUri      = useSvnStandardDirStructure ? client.GetUriFromWorkingCopy(trunkPath) : workingCopyUri;
                var tagUri         = new Uri(useSvnStandardDirStructure ? tagsUri : workingCopyUri, name);

                var svnCommitResult = (SvnCommitResult)null;
                var result          = client.RemoteCopy(sourceUri, tagUri, svnCopyArgs, out svnCommitResult);
                if (result)
                {
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, taggerName);
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));
                }
                result &= client.Update(workingCopyPath, new SvnUpdateArgs {
                    AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false
                });
            }
        }
 private string CheckPath(string path)
 {
     using (SvnClient client = new SvnClient())
     {
         var checker = client.GetUriFromWorkingCopy(path);
         if (checker != null)
         {
             return(checker.ToString());
         }
     }
     return(path);
 }
        private static bool IsWorkingCopy(String path)
        {
            if (String.IsNullOrEmpty(path))
                return false;

            using (SvnClient client = new SvnClient())
            {
                var uri = client.GetUriFromWorkingCopy(path);

                return uri != null;
            }
        }
Esempio n. 8
0
 public static bool ValidateWorkingCopy(string repositoryPath)
 {
     using (var client = new SvnClient())
     {
         try
         {
             return(client.GetUriFromWorkingCopy(repositoryPath) != null);
         }
         catch (Exception)
         {
             return(false);
         }
     }
 }
Esempio n. 9
0
        /// <summary>
        /// Add to ignore list...
        /// </summary>
        /// <param name="filePath"></param>
        /// <returns></returns>
        public bool Ignore(string value)
        {
            var returnValue = false;

            try
            {
                //Get Uri from file path
                var uri = _svnClient.GetUriFromWorkingCopy(_repo);

                // To Get the Latest Revision on the Required SVN Folder
                SvnInfoEventArgs info;
                _svnClient.GetInfo(uri, out info);

                //SvnGetPropertyArgs getPropertyArgs = new SvnGetPropertyArgs()
                //{
                //    Revision = info.Revision
                //};

                //_svnClient.GetProperty(uri, "svn:ignore", getPropertyArgs, out SvnTargetPropertyCollection x);

                // Prepare a PropertyArgs object with latest revision and a commit message;
                SvnSetPropertyArgs setPropertyArgs = new SvnSetPropertyArgs()
                {
                    BaseRevision = info.Revision, LogMessage = "SVN Ignore"
                };

                // Set property to file in the svn directory
                returnValue = _svnClient.RemoteSetProperty(uri, "svn:ignore", value, setPropertyArgs);
                _svnClient.Update(_repo);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }

            return(returnValue);
        }
Esempio n. 10
0
        void UpdateSVNRevision(string file, string tag)
        {
            if (tag == "src")
            {
                Collection <SvnLogEventArgs> logitems;

                DateTime startDateTime = DateTime.Now.AddDays(-60);
                DateTime endDateTime   = DateTime.Now;
                var      svnRange      = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));

                List <SvnRevisionCombo> revisions = new List <SvnRevisionCombo>();

                using (SvnClient client = new SvnClient()) {
                    client.Authentication.SslServerTrustHandlers += delegate(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e) {
                        e.AcceptedFailures = e.Failures;
                        e.Save             = true; // Save acceptance to authentication store
                    };

                    if (client.GetUriFromWorkingCopy(file) != null)
                    {
                        SvnInfoEventArgs info;
                        client.GetInfo(file, out info);
                        var uri = info.Uri;

                        client.GetLog(uri, new SvnLogArgs(svnRange), out logitems);

                        foreach (var logentry in logitems)
                        {
                            var author  = logentry.Author;
                            var message = logentry.LogMessage;
                            var date    = logentry.Time;

                            revisions.Add(new SvnRevisionCombo()
                            {
                                Revision = string.Format("{0}[{1}]", author, message), ID = (int)logentry.Revision
                            });
                        }
                        revisions.Sort((a, b) => {
                            return(b.ID - a.ID);
                        });
                    }
                }
                SVNRevisionCombo.ItemsSource = revisions;
            }
        }
Esempio n. 11
0
        public override string GetTextAtRevision(string repositoryPath, Revision revision, string rootPath)
        {
            var          ms     = new MemoryStream();
            SvnUriTarget target = client.GetUriFromWorkingCopy(rootPath);

            // Redo path link.
            repositoryPath = repositoryPath.TrimStart(new [] { '/' });
            foreach (var segment in target.Uri.Segments)
            {
                if (repositoryPath.StartsWith(segment, StringComparison.Ordinal))
                {
                    repositoryPath = repositoryPath.Remove(0, segment.Length);
                }
            }

            lock (client) {
                // repositoryPath already contains the relative URL path.
                try {
                    client.Write(new SvnUriTarget(target.Uri.AbsoluteUri + repositoryPath, GetRevision(revision)), ms);
                } catch (SvnFileSystemException e) {
                    // File got added/deleted at some point.
                    if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_FS_NOT_FOUND)
                    {
                        return("");
                    }
                    throw;
                } catch (SvnClientNodeKindException e) {
                    // We're trying on a directory.
                    if (e.SvnErrorCode == SvnErrorCode.SVN_ERR_CLIENT_IS_DIRECTORY)
                    {
                        return("");
                    }
                    throw;
                }
            }
            return(TextFile.ReadFile(repositoryPath, ms).Text);
        }
Esempio n. 12
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();
                }
            }
        }
Esempio n. 13
0
        public bool Commit(string authorName, string authorEmail, string comment, DateTime localTime)
        {
            /*
             * TempFile commentFile;
             *
             * var args = "commit";
             * AddComment(comment, ref args, out commentFile);
             *
             * using (commentFile)
             * {
             *  var startInfo = GetStartInfo(args);
             *  startInfo.EnvironmentVariables["GIT_AUTHOR_NAME"] = authorName;
             *  startInfo.EnvironmentVariables["GIT_AUTHOR_EMAIL"] = authorEmail;
             *  startInfo.EnvironmentVariables["GIT_AUTHOR_DATE"] = GetUtcTimeString(localTime);
             *
             *  // also setting the committer is supposedly useful for converting to Mercurial
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_NAME"] = authorName;
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_EMAIL"] = authorEmail;
             *  startInfo.EnvironmentVariables["GIT_COMMITTER_DATE"] = GetUtcTimeString(localTime);
             *
             *  // ignore empty commits, since they are non-trivial to detect
             *  // (e.g. when renaming a directory)
             *  return ExecuteUnless(startInfo, "nothing to commit");
             * }
             */
            if (string.IsNullOrEmpty(authorName))
            {
                return(false);
            }
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);
                var svnCommitArgs = new SvnCommitArgs {
                    LogMessage = comment
                };

                var svnCommitResult = (SvnCommitResult)null;
                var result          = client.Commit(useSvnStandardDirStructure ? trunkPath : workingCopyPath, svnCommitArgs, out svnCommitResult);
                // commit without files results in result=true and svnCommitResult=null
                if (svnCommitResult != null)
                {
                    if (result)
                    {
                        var workingCopyUri = client.GetUriFromWorkingCopy(useSvnStandardDirStructure ? trunkPath : workingCopyPath);

                        result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, authorName);
                        result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));

                        result &= client.Update(workingCopyPath, new SvnUpdateArgs {
                            AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false
                        });
                    }
                    else
                    {
                        MessageBox.Show(string.Format("{0} Error Code: {1}{2}", svnCommitResult.PostCommitError, "", Environment.NewLine), "SVN Commit Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                return(result);
            }
            return(false);
        }
Esempio n. 14
0
        public void FileVersions_WalkKeywords()
        {
            SvnSandBox sbox = new SvnSandBox(this);
            sbox.Create(SandBoxRepository.Empty);

            string wc = sbox.Wc;
            string file = Path.Combine(wc, "myFile.txt");
            string nl = Environment.NewLine;

            File.WriteAllText(file, "Line1 $Id: FileVersions.cs 2139 2012-05-19 10:21:53Z rhuijben $" + nl + "$HeadURL$" + nl + nl);

            Client.Add(file);
            Client.SetProperty(file, SvnPropertyNames.SvnKeywords, "Id\nHeadURL");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl);
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "native");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl + "Line");
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "CR");
            Client.Commit(file);

            string f2 = file + "2";
            Client.Copy(file, f2);
            SvnCommitArgs xa = new SvnCommitArgs();
            xa.LogProperties.Add("extra", "value");
            Client.Commit(wc, xa);
            Client.Update(wc);

            SvnFileVersionsArgs va;

            using (SvnClient c2 = new SvnClient())
            {
                Uri fileUri = c2.GetUriFromWorkingCopy(file);
                Uri f2Uri = c2.GetUriFromWorkingCopy(f2);

                for (int L = 0; L < 2; L++)
                {
                    va = new SvnFileVersionsArgs();
                    va.RetrieveProperties = true;
                    switch (L)
                    {
                        case 0:
                            va.Start = SvnRevision.Zero;
                            va.End = SvnRevision.Head;
                            break;
                        default:
                            break;
                    }

                    int i = 0;
                    Client.FileVersions(f2, va,
                        delegate(object sender, SvnFileVersionEventArgs e)
                        {
                            Assert.That(e.Revision, Is.EqualTo(i + 1L));
                            Assert.That(e.RepositoryRoot, Is.Not.Null);
                            Assert.That(e.Uri, Is.EqualTo(i == 5 ? f2Uri : fileUri));
                            Assert.That(e.Author, Is.EqualTo(Environment.UserName));
                            Assert.That(e.Time, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 10, 0, 0)));
                            Assert.That(e.RevisionProperties.Count, Is.GreaterThanOrEqualTo(3));

                            if (i == 5)
                            {
                                Assert.That(e.RevisionProperties.Contains("extra"), "Contains extra property");
                                //Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.True, "Contains merge info in revision 5");
                            }
                            else
                                Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.False, "No mergeinfo");

                            MemoryStream ms1 = new MemoryStream();
                            MemoryStream ms2 = new MemoryStream();

                            e.WriteTo(ms1);
                            c2.Write(new SvnUriTarget(e.Uri, e.Revision), ms2);

                            string s1 = Encoding.UTF8.GetString(ms1.ToArray());
                            string s2 = Encoding.UTF8.GetString(ms2.ToArray());

                            //Assert.That(ms1.Length, Is.EqualTo(ms2.Length), "Export lengths equal");
                            Assert.That(s1, Is.EqualTo(s2));
                            i++;
                        });

                    Assert.That(i, Is.EqualTo(6), "Found 6 versions");
                }
            }
        }
Esempio n. 15
0
        public bool Commit(string authorName, string authorEmail, string comment, DateTime localTime)
        {
            /*
            TempFile commentFile;

            var args = "commit";
            AddComment(comment, ref args, out commentFile);

            using (commentFile)
            {
                var startInfo = GetStartInfo(args);
                startInfo.EnvironmentVariables["GIT_AUTHOR_NAME"] = authorName;
                startInfo.EnvironmentVariables["GIT_AUTHOR_EMAIL"] = authorEmail;
                startInfo.EnvironmentVariables["GIT_AUTHOR_DATE"] = GetUtcTimeString(localTime);

                // also setting the committer is supposedly useful for converting to Mercurial
                startInfo.EnvironmentVariables["GIT_COMMITTER_NAME"] = authorName;
                startInfo.EnvironmentVariables["GIT_COMMITTER_EMAIL"] = authorEmail;
                startInfo.EnvironmentVariables["GIT_COMMITTER_DATE"] = GetUtcTimeString(localTime);

                // ignore empty commits, since they are non-trivial to detect
                // (e.g. when renaming a directory)
                return ExecuteUnless(startInfo, "nothing to commit");
            }
            */
            if (string.IsNullOrEmpty(authorName))
            {
                return false;
            }
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);
                var svnCommitArgs = new SvnCommitArgs { LogMessage = comment };

                var svnCommitResult = (SvnCommitResult)null;
                var result = client.Commit(useSvnStandardDirStructure ? trunkPath : workingCopyPath, svnCommitArgs, out svnCommitResult);
                // commit without files results in result=true and svnCommitResult=null
                if (svnCommitResult != null)
                {
                    if (result)
                    {

                        var workingCopyUri = client.GetUriFromWorkingCopy(useSvnStandardDirStructure ? trunkPath : workingCopyPath);

                        result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, authorName);
                        result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));

                        result &= client.Update(workingCopyPath, new SvnUpdateArgs { AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false });
                    }
                    else
                    {
                        MessageBox.Show(string.Format("{0} Error Code: {1}{2}", svnCommitResult.PostCommitError, "", Environment.NewLine), "SVN Commit Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                return result;
            }
            return false;
        }
Esempio n. 16
0
        public void VssLabel(string name, string taggerName, string taggerEmail, string comment, DateTime localTime, string taggedPath)
        {
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);

                var codeBasePath = useSvnStandardDirStructure ? this.trunkPath : workingCopyPath;
                var relativePath = taggedPath.StartsWith(codeBasePath) ? taggedPath.Substring(codeBasePath.Length) : null;
                if (relativePath == null || client.GetUriFromWorkingCopy(taggedPath) == null)
                    throw new ArgumentException(string.Format("invalid path {0}", taggedPath));

                var fullLabelPath = Path.Combine(labelPath, name + relativePath);

                Uri repositoryRootUri = client.GetUriFromWorkingCopy(workingCopyPath);

                var codeBaseUri = client.GetUriFromWorkingCopy(codeBasePath);
                var labelBaseUri = client.GetUriFromWorkingCopy(labelPath);

                var relativeSourceUri = new Uri(taggedPath.Substring(workingCopyPath.Length), UriKind.Relative);
                relativeSourceUri = repositoryRootUri.MakeRelativeUri(new Uri(repositoryRootUri, relativeSourceUri));

                var relativeLabelUri = new Uri(fullLabelPath.Substring(workingCopyPath.Length), UriKind.Relative);
                relativeLabelUri = repositoryRootUri.MakeRelativeUri(new Uri(repositoryRootUri, relativeLabelUri));

                var sourceUri = client.GetUriFromWorkingCopy(taggedPath);
                var labelUri = new Uri(labelBaseUri, name + "/" + sourceUri.ToString().Substring(codeBaseUri.ToString().Length));

                var fullLabelPathExists = client.GetUriFromWorkingCopy(fullLabelPath) != null;

                // check intermediate parents
                var intermediateParentNames = labelUri.ToString().Substring(labelBaseUri.ToString().Length).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Reverse().Skip(1).Reverse();
                var intermediateParentRelativeUriToCreate = new List<string>();
                {
                    var intermediatePath = labelPath;
                    var intermediateUriPath = repositoryRootUri.MakeRelativeUri(labelBaseUri).ToString();
                    foreach (var parent in intermediateParentNames)
                    {
                        intermediatePath = Path.Combine(intermediatePath, parent);
                        intermediateUriPath += parent + "/";
                        if (client.GetUriFromWorkingCopy(intermediatePath) == null)
                            intermediateParentRelativeUriToCreate.Add(intermediateUriPath.Substring(0, intermediateUriPath.Length - 1));
                    }
                }

                // perform svn copy or svn delete + svn copy if necessary
                var result = true;
                var svnCommitResult = (SvnCommitResult)null;

                client.RepositoryOperation(repositoryRootUri, new SvnRepositoryOperationArgs { LogMessage = comment }, delegate (SvnMultiCommandClient muccClient)
                {
                    // if label path already exists, delete first
                    if (fullLabelPathExists)
                        result &= muccClient.Delete(Uri.UnescapeDataString(relativeLabelUri.ToString()));

                    // create intermediate parents if necessary
                    foreach (var parentRelativeUri in intermediateParentRelativeUriToCreate)
                        result &= muccClient.CreateDirectory(Uri.UnescapeDataString(parentRelativeUri));

                    result &= muccClient.Copy(Uri.UnescapeDataString(relativeSourceUri.ToString()), Uri.UnescapeDataString(relativeLabelUri.ToString()));

                }, out svnCommitResult);

                if (result)
                {
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, taggerName);
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));
                }

                result &= client.Update(workingCopyPath, new SvnUpdateArgs { AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false });

            }
        }
Esempio n. 17
0
        public void Tag(string name, string taggerName, string taggerEmail, string comment, DateTime localTime, string taggedPath)
        {
            /*
            TempFile commentFile;

            var args = "tag";
            AddComment(comment, ref args, out commentFile);

            // tag names are not quoted because they cannot contain whitespace or quotes
            args += " -- " + name;

            using (commentFile)
            {
                var startInfo = GetStartInfo(args);
                startInfo.EnvironmentVariables["GIT_COMMITTER_NAME"] = taggerName;
                startInfo.EnvironmentVariables["GIT_COMMITTER_EMAIL"] = taggerEmail;
                startInfo.EnvironmentVariables["GIT_COMMITTER_DATE"] = GetUtcTimeString(localTime);

                ExecuteUnless(startInfo, null);
            }
            */
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);
                var svnCopyArgs = new SvnCopyArgs { LogMessage = comment, CreateParents = true, AlwaysCopyAsChild = false };

                var workingCopyUri = client.GetUriFromWorkingCopy(workingCopyPath);
                var tagsUri = client.GetUriFromWorkingCopy(tagPath);
                var sourceUri = useSvnStandardDirStructure ? client.GetUriFromWorkingCopy(trunkPath) : workingCopyUri;
                var tagUri = new Uri(useSvnStandardDirStructure ? tagsUri : workingCopyUri, name);

                var svnCommitResult = (SvnCommitResult)null;
                var result = client.RemoteCopy(sourceUri, tagUri, svnCopyArgs, out svnCommitResult);
                if (result)
                {
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, taggerName);
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));
                }
                result &= client.Update(workingCopyPath, new SvnUpdateArgs { AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false });
            }
        }
Esempio n. 18
0
        static void Main(string[] args)
        {
            client.Authentication.Clear();
            client.Authentication.UserNamePasswordHandlers += (sender, e) =>
            {
                e.UserName = "******";
                e.Password = "******";
            };
            client.Conflict += (sender, e) =>
            {
                Console.WriteLine(" {0}", "there is conflict in your local, please dealing with it first!");
            };
            while (true)
            {
                Console.Write(">");
                var cmd_str = Console.ReadLine();
                if (String.IsNullOrEmpty(cmd_str))
                {
                    continue;
                }
                var arr_cmd   = cmd_str.Split(new String[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                var cmd       = arr_cmd[0];
                var cmd_param = String.Empty;
                if (arr_cmd.Length >= 2)
                {
                    cmd_param = arr_cmd[1];
                }
                if (cmd == "getinfo")
                {
                    if (cmd_param == String.Empty || cmd_param == "remote")
                    {
                        string repoUrl = "svn://118.25.197.165/test_szp";
                        Console.WriteLine(" to getinfo {0} ...", repoUrl);
                        SvnInfoEventArgs info;
                        client.GetInfo(new Uri(repoUrl), out info);
                        Console.WriteLine(" Reversion:{0} lastChangedReversion:{1} lastChangedTime:{2} islocked:{3}"
                                          , info.Revision
                                          , info.LastChangeRevision
                                          , info.LastChangeTime
                                          , info.Lock != null
                                          );
                    }
                    else
                    {
                        var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                        Console.WriteLine(" to getinfo {0} ...", local_path);
                        try
                        {
                            SvnInfoEventArgs info;
                            client.GetInfo(new SvnPathTarget(local_path), out info);
                            Console.WriteLine(" Reversion:{0} lastChangedReversion:{1} lastChangedTime:{2} islocked:{3}"
                                              , info.Revision
                                              , info.LastChangeRevision
                                              , info.LastChangeTime
                                              , info.Lock != null
                                              );
                        }
                        catch (SvnException svnEx)
                        {
                            if (svnEx.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_PATH_NOT_FOUND)
                            {
                                Console.WriteLine(" {0}", "it is not a svn path! your should add it into svn.");
                            }
                            else if (svnEx.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_NOT_WORKING_COPY)
                            {
                                Console.WriteLine(" {0}", "it is not a svn dir! your should checkout this dir.");
                            }
                            else
                            {
                                Console.WriteLine(" {0}({1})", svnEx.Message, svnEx.SvnErrorCode);
                            }
                        }
                    }
                }
                else if (cmd == "checkout")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}\", cmd_param);
                    Console.WriteLine(" to checkout {0} ...", local_path);
                    var repo_url = "svn://118.25.197.165/test_szp";

                    var r = client.CheckOut(new SvnUriTarget(repo_url), local_path);
                    if (r)
                    {
                        Console.WriteLine(" {0}", "check out successfully!");
                    }
                    else
                    {
                        Console.WriteLine(" {0}", "check out faild!");
                    }
                }
                else if (cmd == "getstate")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to getstate {0} ...", local_path);
                    var r = SvnTools.IsManagedPath(local_path);
                    if (r)
                    {
                        Console.WriteLine(" {0} is svn local path", local_path);
                    }
                    else
                    {
                        Console.WriteLine(" {0} is not svn local path", local_path);
                    }
                }
                else if (cmd == "geturi")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to geturi {0} ...", local_path);
                    var uri = client.GetUriFromWorkingCopy(local_path);
                    Console.WriteLine(" {0} ====svn==== {1}", local_path, uri);
                }
                else if (cmd == "add")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to add {0} ...", local_path);
                    var r = client.Add(local_path);
                    if (r)
                    {
                        Console.WriteLine(" add {0} successfully!", local_path);
                    }
                    else
                    {
                        Console.WriteLine(" faild to add {0} !", local_path);
                    }
                }
                else if (cmd == "commit")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to commit {0} ...", local_path);
                    var arg = new SvnCommitArgs();
                    arg.LogMessage = String.Format("test {0:MM:dd HH:mm}", DateTime.Now);
                    SvnCommitResult result;
                    try
                    {
                        var r = client.Commit(local_path, arg, out result);
                        if (r)
                        {
                            Console.WriteLine(" {0}", "commit successfully!");
                        }
                        else
                        {
                            Console.WriteLine(" {0}", "faild to commit!");
                        }
                    }
                    catch (SvnException svnEx)
                    {
                        if (svnEx.SvnErrorCode == SvnErrorCode.SVN_ERR_FS_BAD_LOCK_TOKEN)
                        {
                            Console.WriteLine(" {0} ({1})", "faild to commit!", "another locked this node!");
                        }
                        else if (svnEx.SvnErrorCode == SvnErrorCode.SVN_ERR_FS_TXN_OUT_OF_DATE)
                        {
                            Console.WriteLine(" {0} ({1})", "faild to commit!", "please first update!");
                        }
                        else if (svnEx.SvnErrorCode == SvnErrorCode.SVN_ERR_WC_FOUND_CONFLICT)
                        {
                            Console.WriteLine(" {0} ({1})", "faild to commit!", "please dealing with conflict!");
                        }
                        else
                        {
                            Console.WriteLine(" {0} ({1})", svnEx.Message, svnEx.SvnErrorCode);
                        }
                    }
                }
                else if (cmd == "update")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to update {0} ...", local_path);
                    var r = client.Update(local_path);
                    if (r)
                    {
                        Console.WriteLine(" {0}", "Update successfully!");
                    }
                    else
                    {
                        Console.WriteLine(" {0}", "Update faild!");
                    }
                }
                else if (cmd == "remotelock")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to lock {0} ...", local_path);
                    var uri = client.GetUriFromWorkingCopy(local_path);
                    var r   = client.RemoteLock(uri, String.Format("test lock {0:MM-dd HH:mm}", DateTime.Now));
                    if (r)
                    {
                        Console.WriteLine(" remote lock {0} successfully!", local_path);
                    }
                    else
                    {
                        Console.WriteLine(" faild to remote lock {0}!", local_path);
                    }
                }
                else if (cmd == "remoteunlock")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to unlock {0} ...", local_path);
                    var uri = client.GetUriFromWorkingCopy(local_path);
                    var r   = client.RemoteUnlock(uri);
                    if (r)
                    {
                        Console.WriteLine(" remote unlock {0} successfully!", local_path);
                    }
                    else
                    {
                        Console.WriteLine(" faild to remote lock {0}!", local_path);
                    }
                }
                else if (cmd == "lock")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to lock {0} ...", local_path);
                    //var uri = client.GetUriFromWorkingCopy(local_path);
                    var r = client.Lock(local_path, String.Format("test lock {0:MM-dd HH:mm}", DateTime.Now));
                    if (r)
                    {
                        Console.WriteLine(" lock {0} successfully!", local_path);
                    }
                    else
                    {
                        Console.WriteLine(" faild to lock {0}!", local_path);
                    }
                }
                else if (cmd == "unlock")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    Console.WriteLine(" to unlock {0} ...", local_path);
                    //var uri = client.GetUriFromWorkingCopy(local_path);
                    var r = client.Unlock(local_path);
                    if (r)
                    {
                        Console.WriteLine(" unlock {0} successfully!", local_path);
                    }
                    else
                    {
                        Console.WriteLine(" faild to lock {0}!", local_path);
                    }
                }
                else if (cmd == "export")
                {
                    var local_path = String.Format(@"E:\SVN_BASE\{0}", cmd_param);
                    var dest_path  = arr_cmd[2];
                    Console.WriteLine(" to unlock {0} ...", local_path);
                    var uri = client.GetUriFromWorkingCopy(local_path);
                    try
                    {
                        var r = client.Export(new SvnUriTarget(uri), dest_path);
                        if (r)
                        {
                            Console.WriteLine(" export {0} to {1} successfully!", uri, dest_path);
                        }
                        else
                        {
                            Console.WriteLine(" faild to export {0} to {1}!", uri, dest_path);
                        }
                    }
                    catch (SvnException svnEx)
                    {
                        Console.WriteLine(" {0}(1)", svnEx.Message, svnEx.SvnErrorCode);
                    }
                }
                else if (cmd == "help" || cmd == "?")
                {
                    Console.WriteLine(" 1.getinfo [localpath] or [null] or [remotepath]");
                    Console.WriteLine(" 2.getstate [localpath]");
                    Console.WriteLine(" 2.geturi [localpath]");
                    Console.WriteLine(" 3.checkout [localpath]");
                    Console.WriteLine(" 4.add [localpath]");
                    Console.WriteLine(" 5.commit [localpath]");
                    Console.WriteLine(" 6.update [localpath]");
                    Console.WriteLine(" 7.lock [localpath]");
                    Console.WriteLine(" 8.unlock [localpath]");
                    Console.WriteLine(" 9.remotelock [localpath]");
                    Console.WriteLine(" 10.remoteunlock [localpath]");
                    Console.WriteLine(" 10.export [localpath] [localpath]");
                }
            }
        }
Esempio n. 19
0
 public static bool ValidateWorkingCopy(string repositoryPath)
 {
     using (var client = new SvnClient())
     {
         try
         {
             return client.GetUriFromWorkingCopy(repositoryPath) != null;
         }
         catch (Exception)
         {
             return false;
         }
     }
 }
        private void DoVersionDiff_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(FilterCommits.Text))
            {
                TextTip.Content = "需要填写单号,多个单号空格隔开";
                return;
            }
            if (src.files.Count <= 0)
            {
                TextTip.Content = "拖目标文件夹进来,或目标文件夹下没有xls";
                return;
            }

            Collection <SvnLogEventArgs> logitems;

            DateTime startDateTime = DateTime.Now.AddDays(-60);
            DateTime endDateTime   = DateTime.Now;
            var      svnRange      = new SvnRevisionRange(new SvnRevision(startDateTime), new SvnRevision(endDateTime));

            List <SvnRevisionCombo> revisions = new List <SvnRevisionCombo>();

            var files = new Dictionary <string, RevisionRange>();

            var filter = FilterCommits.Text.Split(" #".ToArray(), StringSplitOptions.RemoveEmptyEntries);

            var sfilter   = string.Join("|", filter);
            var regfilter = new Regex(sfilter);

            using (SvnClient client = new SvnClient()) {
                client.Authentication.SslServerTrustHandlers += delegate(object _sender, SharpSvn.Security.SvnSslServerTrustEventArgs _e) {
                    _e.AcceptedFailures = _e.Failures;
                    _e.Save             = true; // Save acceptance to authentication store
                };

                if (client.GetUriFromWorkingCopy(src.root) != null)
                {
                    SvnInfoEventArgs info;
                    client.GetInfo(src.root, out info);
                    var uri = info.Uri;

                    var rootPath = info.Path;

                    client.GetLog(uri, new SvnLogArgs(svnRange), out logitems);

                    foreach (var logentry in logitems)
                    {
                        var author   = logentry.Author;
                        var message  = logentry.LogMessage;
                        var date     = logentry.Time;
                        var revision = logentry.Revision;

                        if (regfilter.IsMatch(message))
                        {
                            foreach (var filepath in logentry.ChangedPaths)
                            {
                                var path = filepath.Path;

                                RevisionRange minmax = null;
                                if (!files.TryGetValue(path, out minmax))
                                {
                                    minmax = new RevisionRange()
                                    {
                                        min = revision, max = revision, file = path
                                    };
                                    files[path] = minmax;
                                }
                                if (revision > minmax.max)
                                {
                                    minmax.max = revision;
                                }
                                if (revision < minmax.min)
                                {
                                    minmax.min = revision;
                                }
                            }
                        }
                    }
                }
            }

            results.Clear();
            resultRevisions.Clear();

            foreach (var file in files.Keys)
            {
                var range = files[file];
                var res   = new DiffResult <string>(file + "-" + range.min, file + "-" + range.max, DiffStatus.Modified);

                results.Add(res);
                resultRevisions.Add(range);
            }

            DstDataGrid.refreshData();
            SrcDataGrid.refreshData();
        }
        static int Main(string[] args)
        {
#if DEBUG
            Console.Write("ProjectBuildInfo command line: ");
            foreach (var arg in args) Console.Write(arg + " ");
#endif
            Console.WriteLine();
            string namespaceName = null;
            string className = null;
            string outputFilename = null;
            string versionFile = null;
            string versionNumber = null;
            string assemblyVersionFile = null;
            string wixVersionFile = null;
            string webVersionFile = null;
            string installer32 = null;
            string installer64 = null;
            string productName = null;
            for (var i = 0; i < args.Length; i++)
            {
                switch (args[i])
                {
                    case "-namespace":
                        namespaceName = args[++i];
                        break;
                    case "-class":
                        className = args[++i];
                        break;
                    case "-output":
                        outputFilename = args[++i];
                        break;
                    case "-version":
                        versionFile = args[++i].Trim();
                        break;
                    case "-assemblyversion":
                        assemblyVersionFile = args[++i].Trim();
                        break;
                    case "-wixversion":
                        wixVersionFile = args[++i].Trim();
                        break;
                    case "-webversion":
                        webVersionFile = args[++i].Trim();
                        break;
                    case "-installer32bit":
                        installer32 = args[++i].Trim();
                        break;
                    case "-installer64bit":
                        installer64 = args[++i].Trim();
                        break;
                    case "-productName":
                        productName = args[++i].Trim();
                        break;
                    default:
                        Usage();
                        return -1;
                }
            }
            try
            {
                var gitUrl = Repository.FindRepository(outputFilename);
                if (gitUrl == null || !Repository.IsValid(gitUrl))
                    throw new ApplicationException("Given path doesn't seem to refer to a git repository: " + outputFilename);
                var repo = new Repository(gitUrl);
                var target = repo.Head.Target;

                if (versionFile != null)
                {
                    foreach (var versionFields in from curLine in File.ReadAllLines(versionFile)
                                                  select curLine.Trim()
                                                  into trimmedLine
                                                  where !string.IsNullOrEmpty(trimmedLine) && !trimmedLine.StartsWith("//")
                                                  select trimmedLine.Split('.'))
                    {
                        switch (versionFields.Length)
                        {
                            case 4:
                            case 3:
                                int major, minor, build;
                                if (!int.TryParse(versionFields[0], out major) || !int.TryParse(versionFields[1], out minor) || !int.TryParse(versionFields[2], out build) || major < 0 || minor < 0 ||
                                    build < 0)
                                    throw new FormatException(
                                        string.Format(
                                            "Version file not in expected format. There should be only one line that does not begin with a comment mark ('//') and that line should contain a version number template in the form 1.2.3 where 1 is the Major version number of this application, 2 is the Minor version number and 3 is the Build number.  A fourth field, taken from the Subversion revision number of the output directory, will be appended to this and used for assembly and installer version numbers later in the build process."));
                                versionNumber = string.Format("{0}.{1}.{2}", versionFields[0], versionFields[1], versionFields[2]);
                                break;
                            default:
                                throw new FormatException(
                                    string.Format(
                                        "Version file not in expected format. There should be only one line that does not begin with a comment mark ('//') and that line should contain a version number template in the form 1.2.3 where 1 is the Major version number of this application, 2 is the Minor version number and 3 is the Build number.  A fourth field, taken from the git hash of the output directory, will be appended to this and used for assembly and installer version numbers later in the build process."));
                        }
                    }
                }
                if (assemblyVersionFile != null)
                {
                    if (versionNumber == null) throw new ApplicationException("if -assemblyversion is specified, -version must also be specified");
                    using (var writer = new StreamWriter(assemblyVersionFile))
                    {
                        writer.WriteLine("using System.Reflection;");
                        writer.WriteLine();
                        writer.WriteLine("[assembly: AssemblyVersion(\"{0}\")]", versionNumber);
                        writer.WriteLine("[assembly: AssemblyFileVersion(\"{0}\")]", versionNumber);
                    }
                }

                if (wixVersionFile != null)
                {
                    if (versionNumber == null) throw new ApplicationException("if -wixversion is specified, -version must also be specified");
                    using (var writer = new StreamWriter(wixVersionFile))
                    {
                        writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        writer.WriteLine("<Include>");
                        writer.WriteLine("  <?define ProductFullVersion = \"{0}\" ?>", versionNumber);
                        writer.WriteLine("</Include>");
                    }
                }
                if (namespaceName != null && className != null) GenerateCode(namespaceName, className, target.Hash, outputFilename);
                if (webVersionFile != null)
                {
                    using (var writer = new StreamWriter(webVersionFile))
                    {
                        writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        writer.WriteLine("<product>");
                        if (productName != null)
                        {
                            writer.WriteLine("  <name>{0}</name>", productName);
                        }
                        if (installer32 != null)
                        {
                            writer.WriteLine("  <x86>");
                            writer.WriteLine(GenerateWebVersionXml(installer32));
                            writer.WriteLine("  </x86>");
                        }
                        if (installer64 != null)
                        {
                            writer.WriteLine("  <x64>");
                            writer.WriteLine(GenerateWebVersionXml(installer64));
                            writer.WriteLine("  </x64>");
                        }
                        writer.WriteLine("</product>");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Usage();
                return -1;
            }
#if false
            try
            {
                string svnVersionString;
                using (var client = new SvnClient())
                {
                    if (string.IsNullOrEmpty(outputFilename)) outputFilename = assemblyVersionFile;
                    SvnInfoEventArgs svnInfo;
                    client.GetInfo(new SvnUriTarget(client.GetUriFromWorkingCopy(Path.GetDirectoryName(outputFilename))), out svnInfo);
                    svnVersionString = svnInfo.Revision.ToString(CultureInfo.InvariantCulture);
                }
                if (versionFile != null)
                {
                    var inputLines = File.ReadAllLines(versionFile);
                    foreach (var inputLine in inputLines)
                    {
                        var curLine = inputLine.Trim();
                        if (string.IsNullOrEmpty(curLine) || curLine.StartsWith("//")) continue;
                        var versionFields = curLine.Split('.');
                        switch (versionFields.Length)
                        {
                            case 4:
                            case 3:
                                int major, minor, build;
                                if (!int.TryParse(versionFields[0], out major) || !int.TryParse(versionFields[1], out minor) || !int.TryParse(versionFields[2], out build) || major < 0 || minor < 0 || build < 0) throw new FormatException(string.Format("Version file not in expected format. There should be only one line that does not begin with a comment mark ('//') and that line should contain a version number template in the form 1.2.3 where 1 is the Major version number of this application, 2 is the Minor version number and 3 is the Build number.  A fourth field, taken from the Subversion revision number of the output directory, will be appended to this and used for assembly and installer version numbers later in the build process."));
                                versionNumber = string.Format("{0}.{1}.{2}.{3}", versionFields[0], versionFields[1], versionFields[2], svnVersionString);
                                break;
                            default:
                                throw new FormatException(string.Format("Version file not in expected format. There should be only one line that does not begin with a comment mark ('//') and that line should contain a version number template in the form 1.2.3 where 1 is the Major version number of this application, 2 is the Minor version number and 3 is the Build number.  A fourth field, taken from the Subversion revision number of the output directory, will be appended to this and used for assembly and installer version numbers later in the build process."));
                        }
                    }
                }
                if (assemblyVersionFile != null)
                {
                    if (versionNumber == null) throw new ApplicationException("if -assemblyversion is specified, -version must also be specified");
                    using (var writer = new StreamWriter(assemblyVersionFile))
                    {
                        writer.WriteLine("using System.Reflection;");
                        writer.WriteLine();
                        writer.WriteLine("[assembly: AssemblyVersion(\"{0}\")]", versionNumber);
                        writer.WriteLine("[assembly: AssemblyFileVersion(\"{0}\")]", versionNumber);
                    }
                }

                if (wixVersionFile != null)
                {
                    if (versionNumber == null) throw new ApplicationException("if -wixversion is specified, -version must also be specified");
                    using (var writer = new StreamWriter(wixVersionFile))
                    {
                        writer.WriteLine("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
                        writer.WriteLine("<Include>");
                        writer.WriteLine("  <?define ProductFullVersion = \"{0}\" ?>", versionNumber);
                        writer.WriteLine("</Include>");
                    }
                }
                if (namespaceName != null && className != null) GenerateCode(namespaceName, className, svnVersionString, outputFilename);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                Usage();
                return -1;
            }
#endif
            return 0;
        }
Esempio n. 22
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();
                }
            }
        }
Esempio n. 23
0
        public void VssLabel(string name, string taggerName, string taggerEmail, string comment, DateTime localTime, string taggedPath)
        {
            using (var client = new SvnClient())
            {
                SvnUI.Bind(client, parentWindow);

                var codeBasePath = useSvnStandardDirStructure ? this.trunkPath : workingCopyPath;
                var relativePath = taggedPath.StartsWith(codeBasePath) ? taggedPath.Substring(codeBasePath.Length) : null;
                if (relativePath == null || client.GetUriFromWorkingCopy(taggedPath) == null)
                {
                    throw new ArgumentException(string.Format("invalid path {0}", taggedPath));
                }

                var fullLabelPath = Path.Combine(labelPath, name + relativePath);

                Uri repositoryRootUri = client.GetUriFromWorkingCopy(workingCopyPath);

                var codeBaseUri  = client.GetUriFromWorkingCopy(codeBasePath);
                var labelBaseUri = client.GetUriFromWorkingCopy(labelPath);

                var relativeSourceUri = new Uri(taggedPath.Substring(workingCopyPath.Length), UriKind.Relative);
                relativeSourceUri = repositoryRootUri.MakeRelativeUri(new Uri(repositoryRootUri, relativeSourceUri));

                var relativeLabelUri = new Uri(fullLabelPath.Substring(workingCopyPath.Length), UriKind.Relative);
                relativeLabelUri = repositoryRootUri.MakeRelativeUri(new Uri(repositoryRootUri, relativeLabelUri));

                var sourceUri = client.GetUriFromWorkingCopy(taggedPath);
                var labelUri  = new Uri(labelBaseUri, name + "/" + sourceUri.ToString().Substring(codeBaseUri.ToString().Length));

                var fullLabelPathExists = client.GetUriFromWorkingCopy(fullLabelPath) != null;

                // check intermediate parents
                var intermediateParentNames = labelUri.ToString().Substring(labelBaseUri.ToString().Length).Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Reverse().Skip(1).Reverse();
                var intermediateParentRelativeUriToCreate = new List <string>();
                {
                    var intermediatePath    = labelPath;
                    var intermediateUriPath = repositoryRootUri.MakeRelativeUri(labelBaseUri).ToString();
                    foreach (var parent in intermediateParentNames)
                    {
                        intermediatePath     = Path.Combine(intermediatePath, parent);
                        intermediateUriPath += parent + "/";
                        if (client.GetUriFromWorkingCopy(intermediatePath) == null)
                        {
                            intermediateParentRelativeUriToCreate.Add(intermediateUriPath.Substring(0, intermediateUriPath.Length - 1));
                        }
                    }
                }


                // perform svn copy or svn delete + svn copy if necessary
                var result          = true;
                var svnCommitResult = (SvnCommitResult)null;

                client.RepositoryOperation(repositoryRootUri, new SvnRepositoryOperationArgs {
                    LogMessage = comment
                }, delegate(SvnMultiCommandClient muccClient)
                {
                    // if label path already exists, delete first
                    if (fullLabelPathExists)
                    {
                        result &= muccClient.Delete(Uri.UnescapeDataString(relativeLabelUri.ToString()));
                    }

                    // create intermediate parents if necessary
                    foreach (var parentRelativeUri in intermediateParentRelativeUriToCreate)
                    {
                        result &= muccClient.CreateDirectory(Uri.UnescapeDataString(parentRelativeUri));
                    }

                    result &= muccClient.Copy(Uri.UnescapeDataString(relativeSourceUri.ToString()), Uri.UnescapeDataString(relativeLabelUri.ToString()));
                }, out svnCommitResult);

                if (result)
                {
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnAuthor, taggerName);
                    result &= client.SetRevisionProperty(svnCommitResult.RepositoryRoot, new SvnRevision(svnCommitResult.Revision), SvnPropertyNames.SvnDate, SvnPropertyNames.FormatDate(localTime));
                }

                result &= client.Update(workingCopyPath, new SvnUpdateArgs {
                    AddsAsModifications = false, AllowObstructions = false, Depth = SvnDepth.Infinity, IgnoreExternals = true, KeepDepth = true, Revision = SvnRevision.Head, UpdateParents = false
                });
            }
        }
Esempio n. 24
0
        public void FileVersions_WalkKeywords()
        {
            SvnSandBox sbox = new SvnSandBox(this);

            sbox.Create(SandBoxRepository.Empty);

            string wc   = sbox.Wc;
            string file = Path.Combine(wc, "myFile.txt");
            string nl   = Environment.NewLine;

            File.WriteAllText(file, "Line1 $Id: FileVersions.cs 2139 2012-05-19 10:21:53Z rhuijben $" + nl + "$HeadURL$" + nl + nl);

            Client.Add(file);
            Client.SetProperty(file, SvnPropertyNames.SvnKeywords, "Id\nHeadURL");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl);
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "native");
            Client.Commit(file);
            File.AppendAllText(file, "Line" + nl + "Line");
            Client.Commit(file);
            Client.SetProperty(file, SvnPropertyNames.SvnEolStyle, "CR");
            Client.Commit(file);

            string f2 = file + "2";

            Client.Copy(file, f2);
            SvnCommitArgs xa = new SvnCommitArgs();

            xa.LogProperties.Add("extra", "value");
            Client.Commit(wc, xa);
            Client.Update(wc);

            SvnFileVersionsArgs va;

            using (SvnClient c2 = new SvnClient())
            {
                Uri fileUri = c2.GetUriFromWorkingCopy(file);
                Uri f2Uri   = c2.GetUriFromWorkingCopy(f2);

                for (int L = 0; L < 2; L++)
                {
                    va = new SvnFileVersionsArgs();
                    va.RetrieveProperties = true;
                    switch (L)
                    {
                    case 0:
                        va.Start = SvnRevision.Zero;
                        va.End   = SvnRevision.Head;
                        break;

                    default:
                        break;
                    }

                    int i = 0;
                    Client.FileVersions(f2, va,
                                        delegate(object sender, SvnFileVersionEventArgs e)
                    {
                        Assert.That(e.Revision, Is.EqualTo(i + 1L));
                        Assert.That(e.RepositoryRoot, Is.Not.Null);
                        Assert.That(e.Uri, Is.EqualTo(i == 5 ? f2Uri : fileUri));
                        Assert.That(e.Author, Is.EqualTo(Environment.UserName));
                        Assert.That(e.Time, Is.GreaterThan(DateTime.UtcNow - new TimeSpan(0, 0, 10, 0, 0)));
                        Assert.That(e.RevisionProperties.Count, Is.GreaterThanOrEqualTo(3));

                        if (i == 5)
                        {
                            Assert.That(e.RevisionProperties.Contains("extra"), "Contains extra property");
                            //Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.True, "Contains merge info in revision 5");
                        }
                        else
                        {
                            Assert.That(e.Properties.Contains(SvnPropertyNames.SvnMergeInfo), Is.False, "No mergeinfo");
                        }

                        MemoryStream ms1 = new MemoryStream();
                        MemoryStream ms2 = new MemoryStream();

                        e.WriteTo(ms1);
                        c2.Write(new SvnUriTarget(e.Uri, e.Revision), ms2);

                        string s1 = Encoding.UTF8.GetString(ms1.ToArray());
                        string s2 = Encoding.UTF8.GetString(ms2.ToArray());

                        //Assert.That(ms1.Length, Is.EqualTo(ms2.Length), "Export lengths equal");
                        Assert.That(s1, Is.EqualTo(s2));
                        i++;
                    });

                    Assert.That(i, Is.EqualTo(6), "Found 6 versions");
                }
            }
        }