Search code examples
c#svn

How to check for modifications on local svn checkout with C#?


I want to find out if there are any modifications/uncommited changes in a local svn-checkout folder (without opening any dialog).

I used to use the svn-command-line commands but I did not find a way to do it there.

Edit:

To cleariefy: I want to create a C#-function without user interaction which looks like this:

bool CheckForModifications(string svnCheckoutPath)


Solution

  • With the help of Victor Mikó's Answer I was able to use the SharpSvn-library (installed with nuGet). I created the following function to check if a given folder has svn-modifications:

    public static bool? HasFolderSvnModifications(string localPath)
    {
        using (var client = new SvnClient())
        {
            // Check if there are any modifications in the checkout
            Collection<SvnStatusEventArgs> statuses;
            if (client.GetStatus(localPath, out statuses))
            {
                foreach (var item in statuses)
                {
                    if (item.Modified)
                    {
                        
                        return true;
                    }
    
                }
                return false;
            }
            return null;
        }
    }
    

    And this is how I use the function:

    var hasModifications = HasFolderSvnModifications(localPath);
    if (hasModifications.HasValue)
    {
        if (hasModifications.Value)
        {
            MessageBox.Show("There is at least one modified item in " + localPath);
        }
        else
        {
            MessageBox.Show("There are no modifications in " + localPath);
        }
    }
    else
    {
        MessageBox.Show("Problem with queryind for svn-modifications in " + localPath);
    }