本文整理汇总了C#中LibGit2Sharp.Repository.GetLocalBranches方法的典型用法代码示例。如果您正苦于以下问题:C# Repository.GetLocalBranches方法的具体用法?C# Repository.GetLocalBranches怎么用?C# Repository.GetLocalBranches使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LibGit2Sharp.Repository
的用法示例。
在下文中一共展示了Repository.GetLocalBranches方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RemoveRedundantBranches
/// <summary>
/// Removes all local branches that are not tracking any remote branch
/// </summary>
private void RemoveRedundantBranches()
{
using (var repository = new Repository(this.LocalPath))
{
foreach (var localBranch in repository.GetLocalBranches().Where(b => !b.IsTracking))
{
repository.Branches.Remove(localBranch);
}
}
}
示例2: IsValid
/// <summary>
/// Verifies that the specified path points to a valid repository usable by SyncTool
/// (a repository with the expected tags and default branches as created by RepositoryInitHelper)
/// </summary>
public static bool IsValid(string path)
{
// check if the directory exists and is a valid git repository
if (!Directory.Exists(path) || !Repository.IsValid(path))
{
return false;
}
using (var repository = new Repository(path))
{
// the repository needs to be a bare repository
if (!repository.Info.IsBare)
{
return false;
}
// ensure there is a configuration branch
if (!repository.LocalBranchExists(RepositoryInitHelper.ConfigurationBranchName))
{
return false;
}
// ensure there is a tag for the initial commit
if (repository.Tags[RepositoryInitHelper.InitialCommitTagName] == null)
{
return false;
}
// check if there is a repository info file in the root (on all branches)
foreach (var localBranch in repository.GetLocalBranches())
{
var gitDirectory = new GitDirectory(null, "Irrelevant", localBranch.Tip);
if (!gitDirectory.FileExists(RepositoryInfoFile.RepositoryInfoFileName))
{
return false;
}
//TODO: verify content of repository info file
}
}
return true;
}
示例3: CanReuseLocalRepository
internal bool CanReuseLocalRepository()
{
// if the directory does not exist, there is nothing to reuse
if (!Directory.Exists(LocalPath))
{
return false;
}
// if the directory is empty, there is nothing to reuse
if (!Directory.EnumerateFileSystemEntries(LocalPath).Any())
{
return false;
}
// check if the directory is a git repository
if (!Repository.IsValid(LocalPath))
{
return false;
}
using (var repository = new Repository(LocalPath))
{
// check if the repository is a bare repository
if (!repository.Info.IsBare)
{
return false;
}
// make sure the repository has a remote named "origin" that points to RemotePath
if (repository.Network.Remotes[s_Origin]?.Url != RemotePath)
{
return false;
}
var localBranches = repository.GetLocalBranches().ToList();
// make sure there are no branches that are not tracking a remote
if (localBranches.Any(b => b.IsTracking == false))
{
return false;
}
//fetch all branches
repository.Network.Fetch(repository.Network.Remotes[s_Origin]);
// make sure there are no unpushed changes
if (localBranches.Any(b => b.TrackingDetails.AheadBy > 0))
{
return false;
}
}
return true;
}
示例4: Begin_creates_local_branches_for_all_remote_branches
public void Begin_creates_local_branches_for_all_remote_branches()
{
var transaction = CreateTransaction();
Directory.CreateDirectory(transaction.LocalPath);
transaction.Begin();
using (var localRepository = new Repository(transaction.LocalPath))
{
Assert.Equal(m_RemoteRepository.Branches.Count(), localRepository.GetLocalBranches().Count());
Assert.Equal(m_RemoteRepository.Branches.Select(x => x.FriendlyName), localRepository.GetLocalBranches().Select(b => b.FriendlyName));
// make sure all local branches are set up to track the remote branches
foreach (var branch in localRepository.GetLocalBranches())
{
Assert.True(branch.IsTracking);
Assert.Equal("origin/" + branch.FriendlyName, branch.TrackedBranch.FriendlyName);
}
}
}