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

Commit 6399a34

Browse files
authored
Merge branch 'master' into fixes/1154-fix-links-in-inline-comments
2 parents 4d33573 + aa1fbbb commit 6399a34

File tree

5 files changed

+25
-46
lines changed

5 files changed

+25
-46
lines changed

src/GitHub.App/Services/GitClient.cs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -424,16 +424,7 @@ public Task<bool> IsHeadPushed(IRepository repo)
424424

425425
return Task.Factory.StartNew(() =>
426426
{
427-
if (repo.Head.IsTracking)
428-
{
429-
var trackedBranchTip = repo.Head.TrackedBranch.Tip;
430-
if (trackedBranchTip != null)
431-
{
432-
return repo.Head.Tip.Sha == trackedBranchTip.Sha;
433-
}
434-
}
435-
436-
return false;
427+
return repo.Head.TrackingDetails.AheadBy == 0;
437428
});
438429
}
439430

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -328,12 +328,14 @@ public IObservable<string> ExtractFile(
328328
});
329329
}
330330

331-
public Encoding GetEncoding(string path)
331+
public Encoding GetEncoding(ILocalRepositoryModel repository, string relativePath)
332332
{
333-
if (File.Exists(path))
333+
var fullPath = Path.Combine(repository.LocalPath, relativePath);
334+
335+
if (File.Exists(fullPath))
334336
{
335337
var encoding = Encoding.UTF8;
336-
if (HasPreamble(path, encoding))
338+
if (HasPreamble(fullPath, encoding))
337339
{
338340
return encoding;
339341
}

src/GitHub.App/ViewModels/PullRequestDetailViewModel.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,9 +478,9 @@ public async Task Load(IRemoteRepositoryModel remoteRepository, IPullRequestMode
478478
/// <returns>The path to a temporary file.</returns>
479479
public Task<string> ExtractFile(IPullRequestFileNode file, bool head)
480480
{
481-
var path = Path.Combine(file.DirectoryPath, file.FileName);
482-
var encoding = pullRequestsService.GetEncoding(path);
483-
return pullRequestsService.ExtractFile(LocalRepository, model, path, head, encoding).ToTask();
481+
var relativePath = Path.Combine(file.DirectoryPath, file.FileName);
482+
var encoding = pullRequestsService.GetEncoding(LocalRepository, relativePath);
483+
return pullRequestsService.ExtractFile(LocalRepository, model, relativePath, head, encoding).ToTask();
484484
}
485485

486486
/// <summary>

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,12 @@ IObservable<IPullRequestModel> CreatePullRequest(IRepositoryHost host,
124124
/// <summary>
125125
/// Gets the encoding for the specified file.
126126
/// </summary>
127-
/// <param name="path">The path to the file.</param>
128-
/// <returns>The file's encoding</returns>
129-
Encoding GetEncoding(string path);
127+
/// <param name="repository">The repository.</param>
128+
/// <param name="relativePath">The relative path to the file in the repository.</param>
129+
/// <returns>
130+
/// The file's encoding or <see cref="Encoding.Default"/> if the file doesn't exist.
131+
/// </returns>
132+
Encoding GetEncoding(ILocalRepositoryModel repository, string relativePath);
130133

131134
/// <summary>
132135
/// Gets a file as it appears in a pull request.

src/UnitTests/GitHub.App/Services/GitClientTests.cs

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,29 @@ public class GitClientTests
1414
public class TheIsHeadPushedMethod : TestBaseClass
1515
{
1616
[Theory]
17-
[InlineData(true, "sha", "sha", true)]
18-
[InlineData(true, "xxx", "yyy", false)]
19-
[InlineData(true, "headSha", null, false)]
20-
[InlineData(false, "sha", "sha", false)]
21-
public async Task IsHeadPushed(bool istracking, string headSha, string trackedBranchSha, bool expectHeadPushed)
17+
[InlineData(0, true)]
18+
[InlineData(2, false)]
19+
[InlineData(null, false)]
20+
public async Task IsHeadPushed(int? aheadBy, bool expected)
2221
{
2322
var gitClient = new GitClient(Substitute.For<IGitHubCredentialProvider>());
24-
var repository = MockTrackedBranchRepository(istracking, headSha, trackedBranchSha);
23+
var repository = MockTrackedBranchRepository(aheadBy);
2524

2625
var isHeadPushed = await gitClient.IsHeadPushed(repository);
2726

28-
Assert.Equal(expectHeadPushed, isHeadPushed);
27+
Assert.Equal(expected, isHeadPushed);
2928
}
3029

31-
static IRepository MockTrackedBranchRepository(bool isTracking, string headSha, string trackedBranchSha)
30+
static IRepository MockTrackedBranchRepository(int? aheadBy)
3231
{
33-
var trackedBranch = Substitute.For<Branch>();
34-
var trackedBranchTip = MockCommitOrNull(trackedBranchSha);
35-
trackedBranch.Tip.Returns(trackedBranchTip);
3632
var headBranch = Substitute.For<Branch>();
37-
var headTip = MockCommitOrNull(headSha);
38-
headBranch.Tip.Returns(headTip);
39-
headBranch.IsTracking.Returns(isTracking);
40-
headBranch.TrackedBranch.Returns(trackedBranch);
33+
var trackingDetails = Substitute.For<BranchTrackingDetails>();
34+
trackingDetails.AheadBy.Returns(aheadBy);
35+
headBranch.TrackingDetails.Returns(trackingDetails);
4136
var repository = Substitute.For<IRepository>();
4237
repository.Head.Returns(headBranch);
4338
return repository;
4439
}
45-
46-
static Commit MockCommitOrNull(string sha)
47-
{
48-
if (sha != null)
49-
{
50-
var commit = Substitute.For<Commit>();
51-
commit.Sha.Returns(sha);
52-
return commit;
53-
}
54-
55-
return null;
56-
}
5740
}
5841

5942
public class ThePushMethod : TestBaseClass

0 commit comments

Comments
 (0)