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

Commit e2ef9f3

Browse files
committed
Fetch PR head before base
This avoids two fetches in the simple case where head is downstream of base.
1 parent d339a8e commit e2ef9f3

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/GitHub.App/Services/GitClient.cs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,6 @@ public async Task<string> GetPullRequestMergeBase(IRepository repo,
386386
Guard.ArgumentNotNull(targetCloneUrl, nameof(targetCloneUrl));
387387
Guard.ArgumentNotEmptyString(baseRef, nameof(baseRef));
388388

389-
var baseCommit = repo.Lookup<Commit>(baseSha);
390-
if (baseCommit == null)
391-
{
392-
await Fetch(repo, targetCloneUrl, baseRef);
393-
baseCommit = repo.Lookup<Commit>(baseSha);
394-
if (baseCommit == null)
395-
{
396-
throw new NotFoundException($"Couldn't find {baseSha} after fetching from {targetCloneUrl}:{baseRef}.");
397-
}
398-
}
399-
400389
var headCommit = repo.Lookup<Commit>(headSha);
401390
if (headCommit == null)
402391
{
@@ -409,6 +398,17 @@ public async Task<string> GetPullRequestMergeBase(IRepository repo,
409398
}
410399
}
411400

401+
var baseCommit = repo.Lookup<Commit>(baseSha);
402+
if (baseCommit == null)
403+
{
404+
await Fetch(repo, targetCloneUrl, baseRef);
405+
baseCommit = repo.Lookup<Commit>(baseSha);
406+
if (baseCommit == null)
407+
{
408+
throw new NotFoundException($"Couldn't find {baseSha} after fetching from {targetCloneUrl}:{baseRef}.");
409+
}
410+
}
411+
412412
var mergeBaseCommit = repo.ObjectDatabase.FindMergeBase(baseCommit, headCommit);
413413
if (mergeBaseCommit == null)
414414
{

0 commit comments

Comments
 (0)