How to get latest revision number from SharpSVN?
Asked Answered
A

6

31

How to get latest revision number using SharpSVN?

Asis answered 26/3, 2009 at 8:36 Comment(0)
E
40

The least expensive way to retrieve the head revision from a repository is the Info command.

using(SvnClient client = new SvnClient())
{
   SvnInfoEventArgs info;
   Uri repos = new Uri("http://my.server/svn/repos");

   client.GetInfo(repos, out info);

   Console.WriteLine(string.Format("The last revision of {0} is {1}", repos, info.Revision));
}
Expander answered 26/3, 2009 at 9:8 Comment(2)
this code is not working for me as below using (SvnClient client = new SvnClient()) { SvnInfoEventArgs info; Uri repos = new Uri("svn://india01/repository/branches/mybranch1"); client.GetInfo(repos, out info); lblMsg.Visible = true; lblMsg.Text = (string.Format("The last revision of {0} is {1}", repos, info.Revision)); } whenever i m running my webpage it's keep on searching only.. any solution for this.Cornejo
If you want the latest revision for a given path (not the entire repo) you can return info.LastChangeRevision instead.Quilting
E
18

I am checking the latest version of the working copy using SvnWorkingCopyClient:

var workingCopyClient = new SvnWorkingCopyClient();

SvnWorkingCopyVersion version;

workingCopyClient.GetVersion(workingFolder, out version);

The latest version of the local working repository is then available through

long localRev = version.End;

For a remote repository, use

 var client = new SvnClient();

 SvnInfoEventArgs info;

 client.GetInfo(targetUri, out info);

 long remoteRev = info.Revision;

instead.

This is similar to using the svnversion tool from the command line. Hope this helps.

Efflorescence answered 31/8, 2010 at 13:4 Comment(0)
A
9

Ok, I figured it by myself:

SvnInfoEventArgs statuses;
client.GetInfo("svn://repo.address", out statuses);
int LastRevision = statuses.LastChangeRevision;
Asis answered 26/3, 2009 at 9:4 Comment(0)
W
1

i googled also a lot but the only one thing which was working for me to get really the last revision was:

public static long GetRevision(String target)
    {
        SvnClient client = new SvnClient();

        //SvnInfoEventArgs info;
        //client.GetInfo(SvnTarget.FromString(target), out info); //Specify the repository root as Uri
        //return info.Revision
        //return info.LastChangeRevision

        Collection<SvnLogEventArgs> info = new Collection<SvnLogEventArgs>();
        client.GetLog(target, out info);
        return info[0].Revision;
    }

the other solutions are commented out. Try by yourself and see the difference . . .

Watchmaker answered 27/7, 2010 at 9:24 Comment(1)
This command retrieves all revisions to obtain a single revision number... That is a bit of overkill and certainly not the fastest way to obtain the information.Expander
Y
0

Well, a quick google search gave me that, and it works (just point at the /trunk/ URI):

http://sharpsvn.open.collab.net/ds/viewMessage.do?dsForumId=728&dsMessageId=89318

Yea answered 26/3, 2009 at 9:0 Comment(0)
C
0

This is a very old question, and it has been answered well in the top two answers. Still, in the hopes it might be of some help to someone I'm posting the following C# method to illustrate how to not only get the revision numbers from both the repository and the working copy, but also how to test for typical situations that might be considered as problems, for example in an automated build process.

  /// <summary>
  /// Method to get the Subversion revision number for the top folder of the build collection, 
  /// assuming these files were checked-out from Merlinia's Subversion repository. This also 
  /// checks that the working copy is up-to-date. (This does require that a connection to the 
  /// Subversion repository is possible, and that it is running.)
  /// 
  /// One minor problem is that SharpSvn is available in 32-bit or 64-bit DLLs, so the program 
  /// needs to target one or the other platform, not "Any CPU".
  /// 
  /// On error an exception is thrown; caller must be prepared to catch it.
  /// </summary>
  /// <returns>Subversion repository revision number</returns>
  private int GetSvnRevisionNumber()
  {
     try
     {
        // Get the latest revision number from the Subversion repository
        SvnInfoEventArgs svnInfoEventArgs;
        using (SvnClient svnClient = new SvnClient())
        {
           svnClient.GetInfo(new Uri("svn://99.99.99.99/Merlinia/Trunk"), out svnInfoEventArgs);
        }

        // Get the current revision numbers from the working copy that is the "build collection"
        SvnWorkingCopyVersion svnWorkingCopyVersion;
        using (SvnWorkingCopyClient svnWorkingCopyClient = new SvnWorkingCopyClient())
        {
           svnWorkingCopyClient.GetVersion(_collectionFolder, out svnWorkingCopyVersion);
        }

        // Check the build collection has not been modified since last commit or update
        if (svnWorkingCopyVersion.Modified)
        {
           throw new MerliniaException(0x3af34e1u, 
                  "Build collection has been modified since last repository commit or update.");
        }

        // Check the build collection is up-to-date relative to the repository
        if (svnInfoEventArgs.Revision != svnWorkingCopyVersion.Start)
        {
           throw new MerliniaException(0x3af502eu, 
             "Build collection not up-to-date, its revisions = {0}-{1}, repository = {2}.",
             svnWorkingCopyVersion.Start, svnWorkingCopyVersion.End, svnInfoEventArgs.Revision);
        }

        return (int)svnInfoEventArgs.Revision;
     }
     catch (Exception e)
     {
        _fLog.Error(0x3af242au, e);
        throw;
     }
  }

(This code does include a couple of things specific for the program it was copied from, but that shouldn't make the SharpSvn parts difficult to understand.)

Caine answered 27/7, 2014 at 23:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.