handle0088
handle0088

Reputation: 71

How to get all branches of repository with SharpSvn?

I'm trying to get all branches of repository by using SharpSvn but I can not find any method can do it.

Is it possible to get all branches by using SharpSvn?

Upvotes: 6

Views: 2516

Answers (3)

JosephStyons
JosephStyons

Reputation: 58685

I think Matt Z was on the right track, but that code doesn't compile. Here is an adjusted version that should work with the latest version of SharpSVN (as of Dec 2015).

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using SharpSvn;
....

private List<string> GetSVNPaths()
{
  List<string> files = new List<string>();
  using (SvnClient svnClient = new SvnClient())
  {
    Collection<SvnListEventArgs> contents;
    //you can get the url from the TortoiseSVN repo-browser if you aren't sure
    if (svnClient.GetList(new Uri(@"https://your-repository-url/"), out contents))
    {
      files.AddRange(contents.Select(item => item.Path));
    }
  }
  return files;
}

Upvotes: 4

Matt Zappitello
Matt Zappitello

Reputation: 897

The SharpSvn.SvnClient class has a GetList() function that works really well:

using (SvnClient svnClient = new SvnClient())
{
    Collection contents;
    List files = new List();
    if (svnClient.GetList(new Uri(svnUrl), out contents))
    {
        foreach(SvnListEventArgs item in contents) 
        {
            files.Add(item.Path);
        }
    }
}

Once you have the collection, you can get the path of each item at the location. You can also use the Entry object to get information concerning each item, including whether it is a directory or a file, when it was last modified, etc.

Upvotes: 0

timdev
timdev

Reputation: 62894

I don't know anything about SharpSVN, but branches in Subversion are just directory trees -- there's nothing special about them.

If your repository follows they typical layout with three top-level directories (trunk/ branches/ tags/), you can just check out the /branches directory to get all the branches side-by-side.

Upvotes: 0

Related Questions