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

2

12

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".

Grijalva answered 15/5, 2009 at 13:33 Comment(0)
V
10

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));
}
Volt answered 19/5, 2009 at 21:22 Comment(2)
Checking with .GetInfo() is a bit cheaper (io-wise) if you only need to know if the file is under source control and not if the file is modified.Spencerspencerian
.Status() will do a file comparison if the file might have been modified, so worst case in case only the last byte of a 2 GByte file was modified it might almost read 2*2 GByte to determine this. With .Info() you are sure this never happens.Spencerspencerian
S
6

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.

Spencerspencerian answered 9/8, 2009 at 21:35 Comment(1)
.Status() will do a file comparison if the file might have been modified, so worst case in case only the last byte of a 2 GByte file was modified it might almost read 2*2 GByte to determine this. With .Info() you are sure this never happens.Spencerspencerian

© 2022 - 2024 — McMap. All rights reserved.