Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if file is under source control in SharpSvn?

Tags:

c#

svn

sharpsvn

Hi I use C# and SharpSvn library. I would like to check if file is under source control before adding it with SvnClient.Add. When I do it on file that already is under SVN than I get error : "is already under version control".

like image 617
Tom Smykowski Avatar asked May 15 '09 13:05

Tom Smykowski


2 Answers

This pretty well demonstrates how to do it using status

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

    Collection<SvnStatusEventArgs> statuses;
    client.GetStatus("c:\\somefile.txt", sa, out statuses); 

    Assert.That(statuses.Count, Is.EqualTo(1));
    Assert.That(SvnStatus.NotVersioned, Is.EqualTo(statuses[0].LocalContentStatus));
}
like image 111
Sander Rijken Avatar answered Sep 20 '22 13:09

Sander Rijken


If you only want to know if the file is under source control you could use .Info() / .GetInfo(). That method is generally faster as it doesn't have to check if the file has changed since it was checked out.

like image 36
Bert Huijben Avatar answered Sep 22 '22 13:09

Bert Huijben