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

Commit 4997e02

Browse files
committed
Find Git using where and use Resource string
Check that Git.exe can be found and show error from resource string if it can't.
1 parent 6a7c76d commit 4997e02

File tree

3 files changed

+42
-13
lines changed

3 files changed

+42
-13
lines changed

src/GitHub.App/Resources.Designer.cs

Lines changed: 12 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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,10 @@
288288
<data name="SyncSubmodules" xml:space="preserve">
289289
<value>Sync {0} submodules</value>
290290
</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>
291297
</root>

src/GitHub.App/Services/PullRequestService.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -191,23 +191,18 @@ public IObservable<Unit> SyncSubmodules(ILocalRepositoryModel repository)
191191
{
192192
return Observable.Defer(async () =>
193193
{
194+
var exitCode = Where("git");
195+
if (exitCode != 0)
196+
{
197+
var ex = new ApplicationException(App.Resources.CouldntFindGitOnPath);
198+
return Observable.Throw<Unit>(ex);
199+
}
200+
194201
var output = new StringWriter(CultureInfo.InvariantCulture);
195-
var exitCode = await SyncSubmodules(repository.LocalPath, line => output.WriteLine(line));
202+
exitCode = await SyncSubmodules(repository.LocalPath, line => output.WriteLine(line));
196203
if (exitCode != 0)
197204
{
198-
// Replace with friendly message if Git.exe isn't on path.
199-
// If culture isn't English, user will see the local equivalent of:
200-
// "'git' is not recognized as an internal or external command"
201205
var message = output.ToString();
202-
if (exitCode == 1 && message.StartsWith("'git' is not recognized as an internal or external command,", StringComparison.Ordinal))
203-
{
204-
message =
205-
@"Couldn't find Git.exe on PATH.
206-
207-
Please install Git for Windows from:
208-
https://git-scm.com/download/win";
209-
}
210-
211206
var ex = new ApplicationException(message);
212207
return Observable.Throw<Unit>(ex);
213208
}
@@ -239,6 +234,22 @@ await Task.WhenAll(
239234
}
240235
}
241236

237+
static int Where(string fileName)
238+
{
239+
var cmdArguments = "/C WHERE /Q " + fileName;
240+
var startInfo = new ProcessStartInfo("cmd", cmdArguments)
241+
{
242+
UseShellExecute = false,
243+
CreateNoWindow = true
244+
};
245+
246+
using (var process = Process.Start(startInfo))
247+
{
248+
process.WaitForExit();
249+
return process.ExitCode;
250+
}
251+
}
252+
242253
static async Task ReadLinesAsync(TextReader reader, Action<string> progress)
243254
{
244255
string line;

0 commit comments

Comments
 (0)