Skip to content

Commit 7a482c0

Browse files
committed
Write warnings and try to continue when the branch tip is null instead of throwing exceptions.
1 parent d6ad928 commit 7a482c0

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,21 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
5757
throw new ArgumentNullException("branch");
5858
}
5959

60-
if (branch.Tip == null)
61-
{
62-
throw new ArgumentException(String.Format(missingTipFormat, branch.Name));
63-
}
64-
6560
using (Logger.IndentLog("Finding branch source"))
6661
{
62+
if (branch.Tip == null)
63+
{
64+
Logger.WriteWarning(String.Format(missingTipFormat, branch.Name));
65+
return null;
66+
}
67+
6768
var otherBranches = repository.Branches.Except(excludedBranches).Where(b => IsSameBranch(branch, b)).ToList();
6869
var mergeBases = otherBranches.Select(b =>
6970
{
7071
if (b.Tip == null)
7172
{
72-
throw new InvalidOperationException(String.Format(missingTipFormat, b.Name));
73+
Logger.WriteWarning(String.Format(missingTipFormat, b.Name));
74+
return null;
7375
}
7476

7577
var otherCommit = b.Tip;
@@ -90,12 +92,17 @@ static bool IsSameBranch(Branch branch, Branch b)
9092
return (b.IsRemote ? b.Name.Replace(b.Remote.Name + "/", string.Empty) : b.Name) != branch.Name;
9193
}
9294

93-
public static IEnumerable<Branch> GetBranchesContainingCommit(this Commit commit, IRepository repository, bool onlyTrackedBranches)
95+
public static IEnumerable<Branch> GetBranchesContainingCommit([NotNull] this Commit commit, IRepository repository, bool onlyTrackedBranches)
9496
{
97+
if (commit == null)
98+
{
99+
throw new ArgumentNullException("commit");
100+
}
101+
95102
var directBranchHasBeenFound = false;
96103
foreach (var branch in repository.Branches)
97104
{
98-
if (branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
105+
if (branch.Tip != null && branch.Tip.Sha != commit.Sha || (onlyTrackedBranches && !branch.IsTracking))
99106
{
100107
continue;
101108
}

0 commit comments

Comments
 (0)