【问题标题】:Check if directory is external using SharpSvn使用 SharpSvn 检查目录是否是外部的
【发布时间】:2017-08-14 09:24:54
【问题描述】:

我目前正在尝试确定工作副本中的目录是否是外部目录或不使用 SharpSvn。对于文件来说这很容易,因为SvnStatusEventArgs 中有IsFileExternal 选项,但对于目录来说似乎不是那么容易。

在目录上运行svn status 命令不会返回任何信息,这是有道理的,因为外部定义附加到父目录。但是在父目录上运行 svn status 表明包含的目录由于外部定义而存在。

在 SharpSvn 中做同样的事情并没有帮助。没有迹象表明任何子目录是外部的。

我的第一个想法是检查父目录是否有任何外部定义,但是如果有外部文件和目录的定义,这可能会出现问题。

有没有人知道如何解决这个问题?

【问题讨论】:

    标签: c# svn sharpsvn


    【解决方案1】:

    看来我的第一个想法成功了。要检查任何项目是否是外部的,以下将有所帮助:

    private bool CheckIfItemIsExternal(string itemPath)
        {
            List<SvnStatusEventArgs> svnStates = new List<SvnStatusEventArgs>();
            using (SvnClient svnClient = new SvnClient())
            {
                // use throw on error to avoid exception in case the item is not versioned
                // use retrieve all entries option to secure that all status properties are retrieved
                SvnStatusArgs svnStatusArgs = new SvnStatusArgs()
                {
                    ThrowOnError = false,
                    RetrieveAllEntries = true,
                };
                Collection<SvnStatusEventArgs> svnStatusResults;
                if (svnClient.GetStatus(itemPath, svnStatusArgs, out svnStatusResults))
                    svnStates = new List<SvnStatusEventArgs>(svnStatusResults);
            }
    
            foreach (var status in svnStates)
            {
                if (status.IsFileExternal)
                    return true;
                else if (status.NodeKind == SvnNodeKind.Directory)
                {
                    string parentDirectory = Directory.GetParent(itemPath).ToString();
                    List<SvnPropertyListEventArgs> svnProperties = RetrieveSvnProperties(parentDirectory);
                    foreach (var itemProperties in svnProperties)
                    {
                        foreach (var property in itemProperties.Properties)
                        {
                            if (property.Key == "svn:externals" && property.StringValue.Contains(new DirectoryInfo(itemPath).Name))
                                return true;
                        }
                    }
                }
            }
            return false;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-11
      • 2017-07-14
      • 2015-04-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多