GetStatus and Status

This post will go into how to use GetStatus and Status.

The GetStatus methods retrieve the status for the file(s) and directory(s) specified. This is similar to running svn status on the command line.

GetStatus(String path, 
          out Collection<SvnStatusEventArgs> statuses)
GetStatus(String path, 
          SvnStatusArgs args, 
          Collection(SvnStatusEventArgs) statuses)

With this call you pass in a path and optional args, and it will run a recursive status on that path. The path needs to be a valid working copy. The statuses that are encountered during the scan are added to the collection.

You can check the properties of SvnStatusEventArgs to determine the dir/file and its Subversion status. The properties prefixed with Remote are only valid when you’re doing a remote status.

Example:

Collection<SvnStatusEventArgs> statuses;
client.GetStatus(path, statuses);
foreach(SvnStatusEventArgs arg in statuses)
{
    Console.WriteLine(arg.LocalContentStatus +
                      " - " + arg.FullPath);
}

To execute a remote status, you need to use the overload with the StatusArgs parameter, and set the ContactRepository property to true:

Collection<SvnStatusEventArgs> statuses;
client.GetStatus(path, 
                 new SvnStatusArgs
                 {
                     ContactRepository = true
                 },
                 statuses);
foreach(SvnStatusEventArgs arg in statuses)
{
    Console.WriteLine("Remote status: " + 
                      arg.RemoteContentStatus + 
                      " - " + arg.FullPath);
}

As a general rule in SharpSvn, the Command methods execute the command and call an event handler every time a status is found in this case, whereas the GetCommand calls wait until all statuses are retrieved, adding them to the collection out parameter. It’s using an out parameter because the exception throwing can be (partially) disabled, making the function return false when something went wrong.

For example:

client.Status(
    String path, 
    (sender, ea)
    {
        Console.WriteLine(ea.LocalContentStatus +
                          " - " + ea.FullPath);
    });

About