当前位置: 首页>>代码示例>>C#>>正文


C# Repository.GetLocalBranches方法代码示例

本文整理汇总了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);
         }
     }
 }
开发者ID:ap0llo,项目名称:SyncTool,代码行数:13,代码来源:CachingGitTransaction.cs

示例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;

        } 
开发者ID:ap0llo,项目名称:SyncTool,代码行数:49,代码来源:RepositoryVerifier.cs

示例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;
        }
开发者ID:ap0llo,项目名称:SyncTool,代码行数:54,代码来源:CachingGitTransaction.cs

示例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);
                }               
            }
        }
开发者ID:ap0llo,项目名称:SyncTool,代码行数:21,代码来源:AbstractGitTransactionTest.cs


注:本文中的LibGit2Sharp.Repository.GetLocalBranches方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。