Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 1f6efe6

Browse files
committed
Throw NotFoundException from GetPullRequestMergeBase
Previously null was being returned and information about what went wrong was lost.
1 parent bad6ba0 commit 1f6efe6

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

src/GitHub.App/Services/GitClient.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ public Task Fetch(IRepository repository, string remoteName, params string[] ref
9898
var remote = repository.Network.Remotes[remoteName];
9999
repository.Network.Fetch(remote, refspecs, fetchOptions);
100100
}
101-
catch(Exception ex)
101+
catch (Exception ex)
102102
{
103103
log.Error("Failed to fetch", ex);
104104
#if DEBUG
@@ -394,7 +394,7 @@ public async Task<string> GetPullRequestMergeBase(IRepository repo,
394394
baseCommit = repo.Lookup<Commit>(baseSha);
395395
if (baseCommit == null)
396396
{
397-
return null;
397+
throw new NotFoundException($"Couldn't find {baseSha} after fetching from {baseCloneUrl}:{baseRef}.");
398398
}
399399
}
400400

@@ -405,14 +405,14 @@ public async Task<string> GetPullRequestMergeBase(IRepository repo,
405405
headCommit = repo.Lookup<Commit>(headSha);
406406
if (headCommit == null)
407407
{
408-
return null;
408+
throw new NotFoundException($"Couldn't find {headSha} after fetching from {headCloneUrl}:{headRef}.");
409409
}
410410
}
411411

412412
var mergeBaseCommit = repo.ObjectDatabase.FindMergeBase(baseCommit, headCommit);
413-
if(mergeBaseCommit == null)
413+
if (mergeBaseCommit == null)
414414
{
415-
return null;
415+
throw new NotFoundException($"Couldn't find merge base between {baseCommit} and {headCommit}.");
416416
}
417417

418418
return mergeBaseCommit.Sha;

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -316,11 +316,6 @@ public IObservable<string> ExtractFile(
316316
pullRequest.Head.Sha,
317317
pullRequest.Base.Ref,
318318
pullRequest.Head.Ref);
319-
320-
if (sha == null)
321-
{
322-
throw new NotFoundException($"Couldn't find merge base between {pullRequest.Base.Sha} and {pullRequest.Head.Sha}.");
323-
}
324319
}
325320

326321
var file = await ExtractToTempFile(repo, pullRequest.Number, sha, fileName, encoding);
@@ -350,7 +345,7 @@ static bool HasPreamble(string file, Encoding encoding)
350345
{
351346
foreach (var b in encoding.GetPreamble())
352347
{
353-
if(b != stream.ReadByte())
348+
if (b != stream.ReadByte())
354349
{
355350
return false;
356351
}
@@ -473,7 +468,7 @@ async Task<bool> IsBranchMarkedAsPullRequest(IRepository repo, string branchName
473468
{
474469
var prConfigKey = $"branch.{branchName}.{SettingGHfVSPullRequest}";
475470
var value = ParseGHfVSConfigKeyValue(await gitClient.GetConfig<string>(repo, prConfigKey));
476-
return value != null &&
471+
return value != null &&
477472
value.Item1 == pullRequest.Base.RepositoryCloneUrl.Owner &&
478473
value.Item2 == pullRequest.Number;
479474
}

src/GitHub.Exports.Reactive/Services/IGitClient.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ public interface IGitClient
197197
/// <returns>
198198
/// The merge base SHA or null.
199199
/// </returns>
200+
/// <exception cref="LibGit2Sharp.NotFoundException">Thrown when the merge base can't be found.</exception>
200201
Task<string> GetPullRequestMergeBase(IRepository repo, UriString baseCloneUrl, UriString headCloneUrl, string baseSha, string headSha, string baseRef, string headRef);
201202

202203
/// Checks whether the current head is pushed to its remote tracking branch.

0 commit comments

Comments
 (0)