Skip to content

Commit d6ad928

Browse files
committed
Ensure that the branch Tip is not null and throw a more intuitive exception than NulReferenceException if it is.
TODO: Need to document how to fix this and add the URI for it to the exception.
1 parent 7c17eb8 commit d6ad928

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/GitVersionCore/LibGitExtensions.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,28 @@ public static SemanticVersion LastVersionTagOnBranch(this Branch branch, IReposi
5050

5151
public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branch, IRepository repository, params Branch[] excludedBranches)
5252
{
53+
const string missingTipFormat = "{0} has no tip. Please see http://example.com/docs for information on how to fix this.";
54+
5355
if (branch == null)
5456
{
5557
throw new ArgumentNullException("branch");
5658
}
5759

60+
if (branch.Tip == null)
61+
{
62+
throw new ArgumentException(String.Format(missingTipFormat, branch.Name));
63+
}
64+
5865
using (Logger.IndentLog("Finding branch source"))
5966
{
6067
var otherBranches = repository.Branches.Except(excludedBranches).Where(b => IsSameBranch(branch, b)).ToList();
6168
var mergeBases = otherBranches.Select(b =>
6269
{
70+
if (b.Tip == null)
71+
{
72+
throw new InvalidOperationException(String.Format(missingTipFormat, b.Name));
73+
}
74+
6375
var otherCommit = b.Tip;
6476
if (b.Tip.Parents.Contains(branch.Tip))
6577
{
@@ -72,6 +84,7 @@ public static Commit FindCommitBranchWasBranchedFrom([NotNull] this Branch branc
7284
}
7385
}
7486

87+
7588
static bool IsSameBranch(Branch branch, Branch b)
7689
{
7790
return (b.IsRemote ? b.Name.Replace(b.Remote.Name + "/", string.Empty) : b.Name) != branch.Name;

0 commit comments

Comments
 (0)