2017-08-14 66 views
1

我目前正在嘗試確定工作副本中的某個目錄是否是使用SharpSvn的外部目錄。對於一個文件來說很容易,因爲在SvnStatusEventArgs中有IsFileExternal這個選項,但是對於一個目錄來說,這似乎並不容易。使用SharpSvn檢查目錄是否是外部的

在目錄上運行svn status命令不會返回任何信息,這是合理的,因爲外部定義附加到父目錄。但在父目錄上運行svn status,表明由於外部定義,包含的目錄在那裏。

在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; 
    }