Reputation: 162
We are using LibGit2Sharp library to process the commits in Github.
Issue: We need to get all the repository names for the selected branch in Github through LibGit2Sharp library.
Which class will be having the collection of repository names for the particular branch.
We searched through the below LibGit2Sharp documentation but we did not get any idea.
http://www.nudoq.org/#!/Projects/LibGit2Sharp
Can anyone please propose any solution.
Upvotes: 4
Views: 1976
Reputation: 153
I am going to take a guess and assume that you mean the following:
Try to list all the files and directories for a given repository.
This would essentially mean that you want to run the command: git ls-files
I have referred the following link : https://github.com/libgit2/libgit2sharp/wiki/Git-ls-files
The following code snip should do the trick:
using System;
using LibGit2Sharp;
class Program
{
public static void Main(string[] args)
{
using (var repo = new Repository(@"C:\Repo"))
{
foreach (IndexEntry e in repo.Index)
{
Console.WriteLine("{0} {1}", e.Path, e.StageLevel);
}
}
Console.ReadLine();
}
}
I would also like to add that, if you know the git command, then you can find the corresponding api on the github project wiki for libgit2sharp:
Hope this helps.
Best.
Upvotes: 0
Reputation: 14813
Disclaimer:
In the following answer, I assume that you mean:
We need to get all the branch names for the selected repository in Github through LibGit2Sharp library.
The following program with use the Repository.Branches
property and then iterate on it:
class Program
{
// Tested with LibGit2Sharp version 0.21.0.176
static void Main(string[] args)
{
// Load the repository with the path (Replace E:\mono2 with a valid git path)
Repository repository = new Repository(@"E:\mono2");
foreach (var branch in repository.Branches)
{
// Display the branch name
System.Console.WriteLine(branch.Name);
}
System.Console.ReadLine();
}
}
The output of the program will display something like that:
origin/mono-4.0.0-branch
origin/mono-4.0.0-branch-ServiceModelFix
upstream/mono-4.0.0-branch-c5sr2
If you need something else like the Remote
or the UpstreamBranchCanonicalName
of a branch, you have the related property.
Upvotes: 1