Praveen Praveen - 26 days ago 11
C# Question

Check local directory is a working copy before updating from svn

I am working on extracting svn repository using c# programming. I have added sharpsvn dll to my project and wrote following code

string localFolder= @"C:\Users\Desktop\LocalFolder\Dev\Websites\Service";
SvnClient client = new SvnClient();

SvnUriTarget target = new SvnUriTarget(@"http://svn.user.com/svn/websites/Branches/InternalServices");

SvnInfoEventArgs info;

client.GetInfo(target, out info);

//Specify the repository root as Uri
//Console.WriteLine("Repository version: {0}", info.Revision);
Console.WriteLine("Started checking out. Please wait few minutes");

client.CheckOut(target, localFolder);
//client.Update(localFolder);


I have checked out using 'client.checkout' method and i can update using 'client.update' method.

Let say i have folder 'services' in my machine. I am checking out files/folders initially using 'client.checkout' to this folder.

Next time when i run the program it should update automatically without checkout. How can i know if the service folder has already done a checkout once and now it should update?

Answer

You can determine whether a directory is a working copy like this:

public static bool IsWorkingCopy(string path)
{
    using (var client = GetSvnClient())
    {
        var uri = client.GetUriFromWorkingCopy(path);
        return uri != null;
    }
}