Exemple #1
0
        public void WcDirMissing()
        {
            SvnSandBox      sbox           = new SvnSandBox(this);
            Uri             CollabReposUri = sbox.CreateRepository(SandBoxRepository.MergeScenario);
            string          dir            = sbox.Wc;
            SvnUpdateResult r;

            Assert.That(Client.CheckOut(CollabReposUri, dir, out r));

            Directory.Move(Path.Combine(dir, "trunk"), Path.Combine(dir, "banaan"));

            SvnInfoEventArgs iaParent;
            SvnInfoEventArgs iaTrunk;

            Client.GetInfo(dir, out iaParent);
            Client.GetInfo(Path.Combine(dir, "trunk"), out iaTrunk);

            Assert.That(iaParent.FullPath, Is.EqualTo(dir));
            Assert.That(iaTrunk.FullPath, Is.Not.EqualTo(dir));
            //Assert.That(iaParent.Uri, Is.EqualTo(iaTrunk.Uri));

            SvnWorkingCopyVersion ver;
            SvnWorkingCopyClient  wcC = new SvnWorkingCopyClient();

            Assert.That(wcC.GetVersion(dir, out ver));
            Assert.That(ver, Is.Not.Null);

            Assert.That(ver.Modified, Is.True);
            Assert.That(ver.Switched, Is.False);
            Assert.That(ver.Start, Is.EqualTo(17));
            Assert.That(ver.End, Is.EqualTo(17));
            Assert.That(ver.IncompleteWorkingCopy, Is.False);
        }
        /// <exception cref="InvalidOperationException" />
        public override string[] GetCommitMessages()
        {
            SvnWorkingCopyVersion svnWorkingCopyVersion;

            using (var svnWorkingCopyClient = new SvnWorkingCopyClient())
            {
                if (!svnWorkingCopyClient.GetVersion(this.Path,
                                                     out svnWorkingCopyVersion))
                {
                    throw new InvalidOperationException($"Could not get version for {this.Path}.");
                }
            }

            if (svnWorkingCopyVersion.Modified)
            {
                throw new InvalidOperationException($"{this.Path} has uncommitted changes.");
            }

            Collection <SvnLogEventArgs> logItems;

            using (var svnClient = new SvnClient())
            {
                SvnRevision start;
                if (this.BaseRevision == null)
                {
                    start = SvnRevision.Zero;
                }
                else
                {
                    if (!int.TryParse(this.BaseRevision,
                                      out var startRevision))
                    {
                        throw new InvalidOperationException($"Could not parse {nameof(this.BaseRevision)}: {this.BaseRevision}");
                    }
                    start = startRevision;
                }

                var svnLogArgs = new SvnLogArgs
                {
                    StrictNodeHistory = false,
                    Range             = new SvnRevisionRange(start,
                                                             SvnRevision.Head)
                };
                if (!svnClient.GetLog(this.Path,
                                      svnLogArgs,
                                      out logItems))
                {
                    throw new InvalidOperationException($"Could not get log for {this.Path}.");
                }
            }

            var commitMessages = logItems.OrderBy(arg => arg.Revision)
                                 .Select(arg => arg.LogMessage)
                                 .ToArray();

            return(commitMessages);
        }
 public void SvnVersionRoot()
 {
     using (SvnWorkingCopyClient wcC = new SvnWorkingCopyClient())
     {
         SvnGetWorkingCopyVersionArgs sa = new SvnGetWorkingCopyVersionArgs();
         sa.ThrowOnError = false;
         SvnWorkingCopyVersion wcv;
         wcC.GetVersion("C:\\", sa, out wcv); // Used to throw an assertion error
     }
 }
        /// <summary>
        /// Obtiene el número de la última revisión de la copia de trabajo.
        /// </summary>
        /// <returns></returns>
        public static long ObtenerUltimaRevision()
        {
            SvnWorkingCopyVersion version;

            using (var copiaDeTrabajo = new SvnWorkingCopyClient())
            {
                copiaDeTrabajo.GetVersion(ObtenerRutaCopiaTrabajo(), out version);
            }

            return(version.End);
        }
Exemple #5
0
    static void CreateRevisionFile()
    {
        Console.Write("Writing revision to file: ");

        long   rev      = 0;
        string filename = Path.GetFullPath(".");
        SvnWorkingCopyClient  client = new SvnWorkingCopyClient();
        SvnWorkingCopyVersion version;

        if (client.GetVersion(filename, out version))
        {
            rev = version.Start;
        }
        Console.WriteLine(rev);
        using (StreamWriter writer = new StreamWriter("../REVISION")) {
            writer.Write(rev.ToString());
        }
    }
        private static long GetRevision(String path)
        {
            if (String.IsNullOrEmpty(path))
                return 0;

            if (!IsWorkingCopy(path))
                return 0;

            long remoteRevision = 0;
            long localRevision = 0;

            try
            {
                using (SvnClient client = new SvnClient())
                {
                    SvnStatusArgs statusargs = new SvnStatusArgs();
                    statusargs.Depth = SvnDepth.Empty; // Adjust this to check direct files, or (recursive) directories etc
                    statusargs.RetrieveAllEntries = true;
                    statusargs.RetrieveRemoteStatus = true;

                    Collection<SvnStatusEventArgs> statuses;
                    client.GetStatus(path, statusargs, out statuses);

                    remoteRevision = statuses[0].Revision;
                }
            }
            catch (Exception)
            {
                Logger.Write("Error while retrieving information from remote repo", LogLevel.Warning);
            }

            using (SvnWorkingCopyClient client = new SvnWorkingCopyClient())
            {
                SvnWorkingCopyVersion version;
                if (client.GetVersion(path, out version))
                {
                    if (version.End >= 0)
                        localRevision = version.End;
                }
            }

            if (remoteRevision > localRevision)
            {
                Logger.Write("Working copy seems to be out of date", LogLevel.Warning);
            }

            return localRevision;
        }
        protected override IEnumerable <string> GetCommitMessages()
        {
            SvnWorkingCopyVersion svnWorkingCopyVersion;

            using (var svnWorkingCopyClient = new SvnWorkingCopyClient())
            {
                if (!svnWorkingCopyClient.GetVersion(this.RepositoryPath,
                                                     out svnWorkingCopyVersion) ||
                    svnWorkingCopyVersion == null)
                {
                    this.LogError?.Invoke($"Could not get working copy version for {this.RepositoryPath}");
                    return(Enumerable.Empty <string>());
                }
            }

            if (svnWorkingCopyVersion.Modified)
            {
                this.LogError?.Invoke($"Could not calculate version for {this.RepositoryPath} due to local uncomitted changes");
                return(Enumerable.Empty <string>());
            }

            Collection <SvnLogEventArgs> logItems;

            using (var svnClient = new SvnClient())
            {
                SvnRevision start;
                if (this.BaseRevision == null)
                {
                    start = SvnRevision.Zero;
                }
                else
                {
                    int startRevision;
                    if (!int.TryParse(this.BaseRevision,
                                      out startRevision))
                    {
                        this.LogError?.Invoke($"could not parse {nameof(this.BaseRevision)} to {typeof (int).FullName}: {this.BaseRevision}");
                        return(Enumerable.Empty <string>());
                    }
                    start = startRevision;
                }

                this.LogInfo?.Invoke($"retrieving commits from {this.RepositoryPath} since {start}");

                var svnLogArgs = new SvnLogArgs
                {
                    StrictNodeHistory = false,
                    Range             = new SvnRevisionRange(start,
                                                             SvnRevision.Head)
                };
                if (!svnClient.GetLog(this.RepositoryPath,
                                      svnLogArgs,
                                      out logItems) ||
                    logItems == null)
                {
                    this.LogError?.Invoke($"Could not get log for repository in {this.RepositoryPath}");
                    return(null);
                }
            }

            var commitMessages = logItems.OrderBy(arg => arg.Revision)
                                 .Select(arg => arg.LogMessage);

            return(commitMessages);
        }
Exemple #8
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lbInfo.Content = "一切正常";

            String curDir = Directory.GetCurrentDirectory();
            String curExe = System.Reflection.Assembly.GetExecutingAssembly().Location;


            SvnClient = new SvnClient();

            SvnTarget svnTargetCurDir = SvnTarget.FromString(curDir);
            SvnTarget snvTargetCurExe = SvnTarget.FromString(curExe);

            // 未使用 - 获取目录下的文件状态
            Collection<SvnStatusEventArgs> svnStatusEventArgsCollection;
            SvnClient.GetStatus(Directory.GetCurrentDirectory(), out svnStatusEventArgsCollection);

            // 未使用 - 空的
            Collection<SvnPropertyListEventArgs> svnPropertyListEventArgsCollection;
            SvnClient.GetPropertyList(Directory.GetCurrentDirectory(), out svnPropertyListEventArgsCollection);

            // 未使用 - 获取一个文件的状态
            Collection<SvnFileVersionEventArgs> svnFileVersionEventArgsCollection;
            try
            {
                SvnClient.GetFileVersions(snvTargetCurExe, out svnFileVersionEventArgsCollection);
            }
            catch(SvnWorkingCopyPathNotFoundException ex)
            {
                // 如果查询的文件未加入Repo,会抛此异常
            }

            // 未使用 - 一个好像没什么用的信息列表,目录是第一个项,没有版本号
            Collection<SvnListEventArgs> svnListEventArgsCollection;
            SvnClient.GetList(svnTargetCurDir, out svnListEventArgsCollection);

            // 未使用 - 工作目录全路径
            String workingCopyRoot = SvnClient.GetWorkingCopyRoot(Directory.GetCurrentDirectory());
            
            // 未使用 - 整个仓库的最新版本
            long revision = 0;
            SvnClient.Youngest(Directory.GetCurrentDirectory(), out revision);

            // 此目录的相关变更 和 GUI中的ShowLog一样 是此目录的相关变更           
            Collection<SvnLogEventArgs> logList;
            try
            {
                SvnClient.GetLog(Directory.GetCurrentDirectory(), out logList);
            }
            catch(SvnInvalidNodeKindException ex)
            {
                lbInfo.Content = "当前目录不是SVN目录,停用更新检查功能";
                btnUpdateAndLaunch.Visibility = Visibility.Hidden;
                return;
            }

            // 获取本地目录信息,当前版本和修改版本都是本地的
            SvnInfoEventArgs svnInfoEventArgs;
            SvnClient.GetInfo(svnTargetCurDir, out svnInfoEventArgs);

            long curRevision = svnInfoEventArgs.Revision;       // 当前的SVN版本
            long changeRevision = logList[0].Revision;          // 当前目录的最新远程变更版本

            lbVersionChange.Content = changeRevision;
            lbVersionCur.Content = svnInfoEventArgs.Revision;

            if (curRevision < changeRevision)
            {
                btnUpdateAndLaunch.Visibility = Visibility.Visible;
                lbInfo.Content = "发现新版本";
            }
            else
            {
                btnUpdateAndLaunch.Visibility = Visibility.Hidden;
                lbInfo.Content = "已经是最新版";
            }

            // --------------------------------------------------------
            // SvnWorkingCopyClient
            // --------------------------------------------------------
            SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient();

            // 未使用 只有一个值IsText 没看出有什么用处
            SvnWorkingCopyState svnWorkingCopyState;
            svnWorkingCopyClient.GetState(Directory.GetCurrentDirectory(), out svnWorkingCopyState);

            // 未使用 返回仅本地存在的所有修改版本 
            SvnWorkingCopyVersion svnWorkingCopyVersion;
            svnWorkingCopyClient.GetVersion(curDir, out svnWorkingCopyVersion);

            // --------------------------------------------------------
            // SvnTools
            // --------------------------------------------------------
            // 未使用 传入正确的目录却返回false????
            bool isCurDirInWorkingCopy = SvnTools.IsManagedPath(curDir);

        }
Exemple #9
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            lbInfo.Content = "一切正常";

            String curDir = Directory.GetCurrentDirectory();
            String curExe = System.Reflection.Assembly.GetExecutingAssembly().Location;


            SvnClient = new SvnClient();

            SvnTarget svnTargetCurDir = SvnTarget.FromString(curDir);
            SvnTarget snvTargetCurExe = SvnTarget.FromString(curExe);

            // 未使用 - 获取目录下的文件状态
            Collection <SvnStatusEventArgs> svnStatusEventArgsCollection;

            SvnClient.GetStatus(Directory.GetCurrentDirectory(), out svnStatusEventArgsCollection);

            // 未使用 - 空的
            Collection <SvnPropertyListEventArgs> svnPropertyListEventArgsCollection;

            SvnClient.GetPropertyList(Directory.GetCurrentDirectory(), out svnPropertyListEventArgsCollection);

            // 未使用 - 获取一个文件的状态
            Collection <SvnFileVersionEventArgs> svnFileVersionEventArgsCollection;

            try
            {
                SvnClient.GetFileVersions(snvTargetCurExe, out svnFileVersionEventArgsCollection);
            }
            catch (SvnWorkingCopyPathNotFoundException ex)
            {
                // 如果查询的文件未加入Repo,会抛此异常
            }

            // 未使用 - 一个好像没什么用的信息列表,目录是第一个项,没有版本号
            Collection <SvnListEventArgs> svnListEventArgsCollection;

            SvnClient.GetList(svnTargetCurDir, out svnListEventArgsCollection);

            // 未使用 - 工作目录全路径
            String workingCopyRoot = SvnClient.GetWorkingCopyRoot(Directory.GetCurrentDirectory());

            // 未使用 - 整个仓库的最新版本
            long revision = 0;

            SvnClient.Youngest(Directory.GetCurrentDirectory(), out revision);

            // 此目录的相关变更 和 GUI中的ShowLog一样 是此目录的相关变更
            Collection <SvnLogEventArgs> logList;

            try
            {
                SvnClient.GetLog(Directory.GetCurrentDirectory(), out logList);
            }
            catch (SvnInvalidNodeKindException ex)
            {
                lbInfo.Content = "当前目录不是SVN目录,停用更新检查功能";
                btnUpdateAndLaunch.Visibility = Visibility.Hidden;
                return;
            }

            // 获取本地目录信息,当前版本和修改版本都是本地的
            SvnInfoEventArgs svnInfoEventArgs;

            SvnClient.GetInfo(svnTargetCurDir, out svnInfoEventArgs);

            long curRevision    = svnInfoEventArgs.Revision;    // 当前的SVN版本
            long changeRevision = logList[0].Revision;          // 当前目录的最新远程变更版本

            lbVersionChange.Content = changeRevision;
            lbVersionCur.Content    = svnInfoEventArgs.Revision;

            if (curRevision < changeRevision)
            {
                btnUpdateAndLaunch.Visibility = Visibility.Visible;
                lbInfo.Content = "发现新版本";
            }
            else
            {
                btnUpdateAndLaunch.Visibility = Visibility.Hidden;
                lbInfo.Content = "已经是最新版";
            }

            // --------------------------------------------------------
            // SvnWorkingCopyClient
            // --------------------------------------------------------
            SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient();

            // 未使用 只有一个值IsText 没看出有什么用处
            SvnWorkingCopyState svnWorkingCopyState;

            svnWorkingCopyClient.GetState(Directory.GetCurrentDirectory(), out svnWorkingCopyState);

            // 未使用 返回仅本地存在的所有修改版本
            SvnWorkingCopyVersion svnWorkingCopyVersion;

            svnWorkingCopyClient.GetVersion(curDir, out svnWorkingCopyVersion);

            // --------------------------------------------------------
            // SvnTools
            // --------------------------------------------------------
            // 未使用 传入正确的目录却返回false????
            bool isCurDirInWorkingCopy = SvnTools.IsManagedPath(curDir);
        }