I am currently trying to determine if a directory within a working copy is an external or not using SharpSvn. For a file it is quite easy, since there is the option IsFileExternal
in the SvnStatusEventArgs
, but for a directory it seems to be not this easy.
Running the svn status
command on the directory does not return any information, which makes sense, since the externals definition is attached to the parent directory. But running svn status
on the parent directory, signals that the contained directory is there because of an externals definition.
Doing the same thing in SharpSvn does not help. There is no indication that any subdirectory is an external.
My first idea was to check if there is any external definitions for the parent directory, but this might be a problem if there are definitions for a file and a directory external.
Does anybody has a solution or idea how to solve this problem?
It seems that my first idea worked out. To check if any item is an external, the following will help:
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;
}