即使特定目录不是repo的根目录,我如何获得该目录的分支?iow相当于
git branch --show-current
(即使在子目录中也能正常工作(。
根据这个类似问题的答案,我做了如下操作,它只在repo的根目录中工作:
using (var git = new Repository("repo_rootsubdir")) // throws if subdir
{
return git.Head.FriendlyName;
}
Oops,找到它:
using (var git = new Repository(
LibGit2Sharp.Repository.Discover(@"repo_rootsubdir")))
{
return git.Head.FriendlyName;
}