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

Commit 3a5731f

Browse files
authored
Merge branch 'master' into cleanup/LogManager-CA1004
2 parents 4c0dcd1 + 988bf19 commit 3a5731f

File tree

35 files changed

+1911
-656
lines changed

35 files changed

+1911
-656
lines changed

appveyor.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
version: '2.4.2.{build}'
1+
version: '2.4.3.{build}'
22
skip_tags: true
33
install:
44
- ps: |

src/GitHub.Api/SimpleApiClient.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async Task<Repository> GetRepositoryInternal()
7272
if (repo != null)
7373
{
7474
hasWiki = await HasWikiInternal(repo);
75-
isEnterprise = await IsEnterpriseInternal();
75+
isEnterprise = isEnterprise ?? await IsEnterpriseInternal();
7676
repositoryCache = repo;
7777
}
7878
owner = ownerLogin;
@@ -99,9 +99,14 @@ public bool HasWiki()
9999
return hasWiki.HasValue && hasWiki.Value;
100100
}
101101

102-
public bool IsEnterprise()
102+
public async Task<bool> IsEnterprise()
103103
{
104-
return isEnterprise.HasValue && isEnterprise.Value;
104+
if (!isEnterprise.HasValue)
105+
{
106+
isEnterprise = await IsEnterpriseInternal();
107+
}
108+
109+
return isEnterprise ?? false;
105110
}
106111

107112
async Task<bool> HasWikiInternal(Repository repo)

src/GitHub.App/Api/ApiClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ static string GetMachineNameSafe()
157157
}
158158
catch (Exception e)
159159
{
160-
log.Information(e, "Failed to retrieve host name using `DNS.GetHostName`");
160+
log.Warning(e, "Failed to retrieve host name using `DNS.GetHostName`");
161161
try
162162
{
163163
return Environment.MachineName;

src/GitHub.App/Resources.Designer.cs

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/GitHub.App/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,13 @@
285285
<data name="WorkingDirectoryHasUncommittedCHanges" xml:space="preserve">
286286
<value>Cannot checkout as your working directory has uncommitted changes.</value>
287287
</data>
288+
<data name="SyncSubmodules" xml:space="preserve">
289+
<value>Sync {0} submodules</value>
290+
</data>
291+
<data name="CouldntFindGitOnPath" xml:space="preserve">
292+
<value>Couldn't find Git.exe on PATH.
293+
294+
Please install Git for Windows from:
295+
https://git-scm.com/download/win</value>
296+
</data>
288297
</root>

src/GitHub.App/SampleData/PullRequestDetailViewModelDesigner.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ public PullRequestDetailViewModelDesigner()
9494
public ReactiveCommand<Unit> Checkout { get; }
9595
public ReactiveCommand<Unit> Pull { get; }
9696
public ReactiveCommand<Unit> Push { get; }
97+
public ReactiveCommand<Unit> SyncSubmodules { get; }
9798
public ReactiveCommand<object> OpenOnGitHub { get; }
9899
public ReactiveCommand<object> DiffFile { get; }
99100
public ReactiveCommand<object> DiffFileWithWorkingDirectory { get; }

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System.ComponentModel.Composition;
33
using System.IO;
44
using System.Linq;
5+
using System.Diagnostics;
56
using GitHub.Models;
67
using System.Reactive.Linq;
78
using Rothko;
@@ -103,13 +104,44 @@ public IObservable<IReadOnlyList<CommitMessage>> GetMessagesForUniqueCommits(
103104
});
104105
}
105106

107+
public IObservable<int> CountSubmodulesToSync(ILocalRepositoryModel repository)
108+
{
109+
using (var repo = gitService.GetRepository(repository.LocalPath))
110+
{
111+
var count = 0;
112+
foreach (var submodule in repo.Submodules)
113+
{
114+
var status = submodule.RetrieveStatus();
115+
if ((status & SubmoduleStatus.WorkDirAdded) != 0)
116+
{
117+
count++;
118+
}
119+
else if ((status & SubmoduleStatus.WorkDirDeleted) != 0)
120+
{
121+
count++;
122+
}
123+
else if ((status & SubmoduleStatus.WorkDirModified) != 0)
124+
{
125+
count++;
126+
}
127+
else if ((status & SubmoduleStatus.WorkDirUninitialized) != 0)
128+
{
129+
count++;
130+
}
131+
}
132+
133+
return Observable.Return(count);
134+
}
135+
}
136+
106137
public IObservable<bool> IsWorkingDirectoryClean(ILocalRepositoryModel repository)
107138
{
108139
// The `using` appears to resolve this issue:
109140
// https://github.com/github/VisualStudio/issues/1306
110141
using (var repo = gitService.GetRepository(repository.LocalPath))
111142
{
112-
var isClean = !IsFilthy(repo.RetrieveStatus());
143+
var statusOptions = new StatusOptions { ExcludeSubmodules = true };
144+
var isClean = !IsFilthy(repo.RetrieveStatus(statusOptions));
113145
return Observable.Return(isClean);
114146
}
115147
}
@@ -154,6 +186,69 @@ public IObservable<Unit> Push(ILocalRepositoryModel repository)
154186
});
155187
}
156188

189+
public async Task<bool> SyncSubmodules(ILocalRepositoryModel repository, Action<string> progress)
190+
{
191+
var exitCode = await Where("git");
192+
if (exitCode != 0)
193+
{
194+
progress(App.Resources.CouldntFindGitOnPath);
195+
return false;
196+
}
197+
198+
return await SyncSubmodules(repository.LocalPath, progress) == 0;
199+
}
200+
201+
// LibGit2Sharp has limited submodule support so shelling out Git.exe for submodule commands.
202+
async Task<int> SyncSubmodules(string workingDir, Action<string> progress)
203+
{
204+
var cmdArguments = "/C git submodule init & git submodule sync --recursive & git submodule update --recursive";
205+
var startInfo = new ProcessStartInfo("cmd", cmdArguments)
206+
{
207+
WorkingDirectory = workingDir,
208+
UseShellExecute = false,
209+
CreateNoWindow = true,
210+
RedirectStandardOutput = true,
211+
RedirectStandardError = true
212+
};
213+
214+
using (var process = Process.Start(startInfo))
215+
{
216+
await Task.WhenAll(
217+
ReadLinesAsync(process.StandardOutput, progress),
218+
ReadLinesAsync(process.StandardError, progress),
219+
Task.Run(() => process.WaitForExit()));
220+
return process.ExitCode;
221+
}
222+
}
223+
224+
static Task<int> Where(string fileName)
225+
{
226+
return Task.Run(() =>
227+
{
228+
var cmdArguments = "/C WHERE /Q " + fileName;
229+
var startInfo = new ProcessStartInfo("cmd", cmdArguments)
230+
{
231+
UseShellExecute = false,
232+
CreateNoWindow = true
233+
};
234+
235+
using (var process = Process.Start(startInfo))
236+
{
237+
process.WaitForExit();
238+
return process.ExitCode;
239+
}
240+
});
241+
}
242+
243+
static async Task ReadLinesAsync(TextReader reader, Action<string> progress)
244+
{
245+
string line;
246+
while ((line = await reader.ReadLineAsync()) != null)
247+
{
248+
progress(line);
249+
}
250+
}
251+
157252
public IObservable<Unit> Checkout(ILocalRepositoryModel repository, IPullRequestModel pullRequest, string localBranchName)
158253
{
159254
return Observable.Defer(async () =>

src/GitHub.App/Services/TeamExplorerContext.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void Refresh()
6565
{
6666
// Ignore when ActiveRepositories is empty and solution hasn't changed.
6767
// https://github.com/github/VisualStudio/issues/1421
68-
log.Information("Ignoring no ActiveRepository when solution hasn't changed");
68+
log.Debug("Ignoring no ActiveRepository when solution hasn't changed");
6969
}
7070
else
7171
{
@@ -76,22 +76,22 @@ void Refresh()
7676

7777
if (newRepositoryPath != repositoryPath)
7878
{
79-
log.Information("Fire PropertyChanged event for ActiveRepository");
79+
log.Debug("Fire PropertyChanged event for ActiveRepository");
8080
ActiveRepository = repo;
8181
}
8282
else if (newBranchName != branchName)
8383
{
84-
log.Information("Fire StatusChanged event when BranchName changes for ActiveRepository");
84+
log.Debug("Fire StatusChanged event when BranchName changes for ActiveRepository");
8585
StatusChanged?.Invoke(this, EventArgs.Empty);
8686
}
8787
else if (newHeadSha != headSha)
8888
{
89-
log.Information("Fire StatusChanged event when HeadSha changes for ActiveRepository");
89+
log.Debug("Fire StatusChanged event when HeadSha changes for ActiveRepository");
9090
StatusChanged?.Invoke(this, EventArgs.Empty);
9191
}
9292
else if (newTrackedSha != trackedSha)
9393
{
94-
log.Information("Fire StatusChanged event when TrackedSha changes for ActiveRepository");
94+
log.Debug("Fire StatusChanged event when TrackedSha changes for ActiveRepository");
9595
StatusChanged?.Invoke(this, EventArgs.Empty);
9696
}
9797

src/GitHub.App/ViewModels/Dialog/LoginTabViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ void HandleError(Exception ex)
200200

201201
if (ex.IsCriticalException()) return;
202202

203-
log.Information(ex, "Error logging into '{BaseUri}' as '{UsernameOrEmail}'", BaseUri, UsernameOrEmail);
203+
log.Error(ex, "Error logging into '{BaseUri}' as '{UsernameOrEmail}'", BaseUri, UsernameOrEmail);
204204
if (ex is Octokit.ForbiddenException)
205205
{
206206
Error = new UserError(Resources.LoginFailedForbiddenMessage, ex.Message);

src/GitHub.App/ViewModels/GitHubPane/GitHubPaneViewModel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ async Task UpdateContent(ILocalRepositoryModel repository)
379379
var repositoryUrl = repository.CloneUrl.ToRepositoryUrl();
380380
var isDotCom = HostAddress.IsGitHubDotComUri(repositoryUrl);
381381
var client = await apiClientFactory.Create(repository.CloneUrl);
382-
var isEnterprise = isDotCom ? false : client.IsEnterprise();
382+
var isEnterprise = isDotCom ? false : await client.IsEnterprise();
383383

384384
if ((isDotCom || isEnterprise) && await IsValidRepository(client))
385385
{

0 commit comments

Comments
 (0)