From 5873bdb2a6936aab9aab126519d36d51b86dce4d Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Tue, 23 Aug 2022 19:31:39 -0400 Subject: [PATCH] try catch all the things --- BLL/CommitDetail.cs | 57 ++++++++++++++++++++++++++++----------------- Program.cs | 2 +- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/BLL/CommitDetail.cs b/BLL/CommitDetail.cs index d4c56c2..b9702f6 100644 --- a/BLL/CommitDetail.cs +++ b/BLL/CommitDetail.cs @@ -93,11 +93,19 @@ public class CommitDetail { var branchResult = repo.Branches[branchName]; - if (branchResult == null) + try { - branchResult = repo.Branches[$"origin/{branchName}"]; - var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip); - repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{branchName}"); + if (branchResult == null) + { + branchResult = repo.Branches[$"origin/{branchName}"]; + var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip); + repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{branchName}"); + } + } + catch (System.Exception) + { + Console.WriteLine($"Cannot fetch {branchName} branch."); + Environment.Exit(1); } foreach (var c in branchResult.Commits) @@ -120,29 +128,36 @@ public class CommitDetail { using (var repo = new Repository(Directory.GetCurrentDirectory())) { - var tagResult = repo.Tags[tagName].Target.Sha; - - var commitFilter = new CommitFilter + try { - IncludeReachableFrom = tagResult, - }; - - var query = repo.Commits.QueryBy(commitFilter); - - foreach (var c in query) - { - if (!_authors.Contains(c.Author.Name)) + var tagResult = repo.Tags[tagName].Target.Sha; + + var commitFilter = new CommitFilter { - _authors.Add(c.Author.Name); + IncludeReachableFrom = tagResult, + }; + + var query = repo.Commits.QueryBy(commitFilter); + + foreach (var c in query) + { + if (!_authors.Contains(c.Author.Name)) + { + _authors.Add(c.Author.Name); + } + } + + foreach (var a in _authors) + { + int commitCount = query.Where(r => r.Author.Name == a).Count(); + _commitDetails.Add(a, commitCount); } } - - foreach (var a in _authors) + catch (System.Exception) { - int commitCount = query.Where(r => r.Author.Name == a).Count(); - _commitDetails.Add(a, commitCount); + Console.WriteLine($"Cannot find the tag {tagName}"); + Environment.Exit(3); } - } } } diff --git a/Program.cs b/Program.cs index 7413e47..a156caa 100644 --- a/Program.cs +++ b/Program.cs @@ -130,7 +130,7 @@ static class Program break; default: System.Console.WriteLine("This should not happen..."); - Environment.Exit(90); + Environment.Exit(4); break; } },