Browse Source

GitAddIn: handle errors in git invocation (e.g. if git is not installed)

pull/1/head
Daniel Grunwald 16 years ago
parent
commit
4bf7bee15f
  1. 2
      src/AddIns/VersionControl/GitAddIn/GitAddIn.csproj
  2. 4
      src/AddIns/VersionControl/GitAddIn/Src/Git.cs
  3. 6
      src/AddIns/VersionControl/GitAddIn/Src/GitGuiWrapper.cs
  4. 39
      src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs
  5. 2
      src/Main/Base/Project/Src/Gui/Dialogs/ToolNotFoundDialog.cs

2
src/AddIns/VersionControl/GitAddIn/GitAddIn.csproj

@ -7,7 +7,7 @@
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
<RootNamespace>ICSharpCode.GitAddIn</RootNamespace> <RootNamespace>ICSharpCode.GitAddIn</RootNamespace>
<AssemblyName>GitAddIn</AssemblyName> <AssemblyName>GitAddIn</AssemblyName>
<OutputPath>..\..\..\..\AddIns\AddIns\VersionControl\</OutputPath> <OutputPath>..\..\..\..\AddIns\VersionControl\</OutputPath>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks> <AllowUnsafeBlocks>False</AllowUnsafeBlocks>
<NoStdLib>False</NoStdLib> <NoStdLib>False</NoStdLib>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>

4
src/AddIns/VersionControl/GitAddIn/Src/Git.cs

@ -74,7 +74,7 @@ namespace ICSharpCode.GitAddIn
public static void RunGit(string workingDir, string arguments, Action<int> finished) public static void RunGit(string workingDir, string arguments, Action<int> finished)
{ {
GitMessageView.AppendLine("$ git " + arguments); GitMessageView.AppendLine(workingDir + "> git " + arguments);
ProcessRunner runner = new ProcessRunner(); ProcessRunner runner = new ProcessRunner();
runner.WorkingDirectory = workingDir; runner.WorkingDirectory = workingDir;
runner.LogStandardOutputAndError = false; runner.LogStandardOutputAndError = false;
@ -121,6 +121,6 @@ namespace ICSharpCode.GitAddIn
} }
} }
} }
*/ */
} }
} }

6
src/AddIns/VersionControl/GitAddIn/Src/GitGuiWrapper.cs

@ -8,8 +8,8 @@
using System; using System;
using System.Diagnostics; using System.Diagnostics;
using System.Text; using System.Text;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui;
using Microsoft.Win32; using Microsoft.Win32;
namespace ICSharpCode.GitAddIn namespace ICSharpCode.GitAddIn
@ -48,7 +48,9 @@ namespace ICSharpCode.GitAddIn
{ {
string path = GetPathFromRegistry("ProcPath"); string path = GetPathFromRegistry("ProcPath");
if (path == null) { if (path == null) {
MessageService.ShowError("Could not find TortoiseGit."); using (var dlg = new ToolNotFoundDialog("${res:AddIns.Git.TortoiseGitRequired}", "http://code.google.com/p/tortoisegit/")) {
dlg.ShowDialog(WorkbenchSingleton.MainWin32Window);
}
} else { } else {
try { try {
StringBuilder arguments = new StringBuilder(); StringBuilder arguments = new StringBuilder();

39
src/AddIns/VersionControl/GitAddIn/Src/GitStatusCache.cs

@ -82,11 +82,21 @@ namespace ICSharpCode.GitAddIn
runner.WorkingDirectory = wcRoot; runner.WorkingDirectory = wcRoot;
runner.LogStandardOutputAndError = false; runner.LogStandardOutputAndError = false;
runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) {
if (string.IsNullOrEmpty(e.Line)) if (!string.IsNullOrEmpty(e.Line)) {
return; statusSet.AddEntry(e.Line, GitStatus.OK);
statusSet.AddEntry(e.Line, GitStatus.OK); }
};
string command = "git ls-files";
bool hasErrors = false;
runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) {
if (!hasErrors) {
hasErrors = true;
GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command);
}
GitMessageView.AppendLine(e.Line);
}; };
runner.Start("cmd", "/c git ls-files"); runner.Start("cmd", "/c " + command);
runner.WaitForExit(); runner.WaitForExit();
} }
@ -96,14 +106,23 @@ namespace ICSharpCode.GitAddIn
runner.WorkingDirectory = wcRoot; runner.WorkingDirectory = wcRoot;
runner.LogStandardOutputAndError = false; runner.LogStandardOutputAndError = false;
runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) { runner.OutputLineReceived += delegate(object sender, LineReceivedEventArgs e) {
if (string.IsNullOrEmpty(e.Line)) if (!string.IsNullOrEmpty(e.Line)) {
return; Match m = statusParseRegex.Match(e.Line);
Match m = statusParseRegex.Match(e.Line); if (m.Success) {
if (m.Success) { statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value));
statusSet.AddEntry(m.Groups[2].Value, StatusFromText(m.Groups[1].Value)); }
}
};
string command = "git status -a --untracked-files=no";
bool hasErrors = false;
runner.ErrorLineReceived += delegate(object sender, LineReceivedEventArgs e) {
if (!hasErrors) {
hasErrors = true;
GitMessageView.AppendLine(runner.WorkingDirectory + "> " + command);
} }
GitMessageView.AppendLine(e.Line);
}; };
runner.Start("cmd", "/c git status -a --untracked-files=no"); runner.Start("cmd", "/c " + command);
runner.WaitForExit(); runner.WaitForExit();
} }

2
src/Main/Base/Project/Src/Gui/Dialogs/ToolNotFoundDialog.cs

@ -23,7 +23,7 @@ namespace ICSharpCode.SharpDevelop.Gui
/// <param name="description">The description text</param> /// <param name="description">The description text</param>
/// <param name="linkTarget">The link target (with leading http://)</param> /// <param name="linkTarget">The link target (with leading http://)</param>
/// <param name="icon">32x32 icon to display next to the description. May be null.</param> /// <param name="icon">32x32 icon to display next to the description. May be null.</param>
public ToolNotFoundDialog(string description, string linkTarget, Image icon) public ToolNotFoundDialog(string description, string linkTarget, Image icon = null)
{ {
// The InitializeComponent() call is required for Windows Forms designer support. // The InitializeComponent() call is required for Windows Forms designer support.
InitializeComponent(); InitializeComponent();

Loading…
Cancel
Save