private static GitBranch ToBranch(Match match)
        {
            bool      isCurrent       = match.Groups[1].Value == "*";
            bool      isDetached      = !string.IsNullOrEmpty(match.Groups[3].Value);
            string    branchName      = isDetached ? $"({match.Groups[3].Value})" : match.Groups[4].Value;
            CommitSha tipSha          = new CommitSha(match.Groups[5].Value);
            string    boundBranchName = match.Groups[8].Value;

            int.TryParse(match.Groups[11].Value, out int aheadCount);
            int.TryParse(match.Groups[14].Value, out int behindCount);
            bool   isRemoteMissing = match.Groups[15].Value == "gone";
            string message         = (match.Groups[17].Value ?? "").TrimEnd('\r');

            GitBranch branch = new GitBranch(
                branchName, tipSha, isCurrent, message, boundBranchName, aheadCount, behindCount, isRemoteMissing, isDetached);

            return(branch);
        }
        public async Task <R <IReadOnlyList <GitBranch> > > GetBranchesAsync(CancellationToken ct)
        {
            List <GitBranch> branches = new List <GitBranch>();
            R <CmdResult2>   result   = await gitCmdService.RunAsync("branch -vv --no-color --no-abbrev --all", ct);

            if (result.IsFaulted)
            {
                return(R.Error("Failed to get branches", result.Exception));
            }

            var matches = BranchesRegEx.Matches(result.Value.Output);

            foreach (Match match in matches)
            {
                if (!IsPointerBranch(match))
                {
                    GitBranch branch = ToBranch(match);
                    branches.Add(branch);
                }
            }

            Log.Info($"Got {branches.Count} branches");
            return(branches);
        }
Esempio n. 3
0
 public static bool TryGet(this IEnumerable <GitBranch> branches, string branchName, out GitBranch branch)
 {
     branch = branches.FirstOrDefault(b => b.Name == branchName);
     return(branch != null);
 }
Esempio n. 4
0
 public static bool TryGetCurrent(this IEnumerable <GitBranch> branches, out GitBranch branch)
 {
     branch = branches.FirstOrDefault(b => b.IsCurrent);
     return(branch != null);
 }