Skip to content

Commit e28b75b

Browse files
committed
enhance: include stdout in error popup when git process (in Exec mode, we do not need to parse its output) exit with non-zero code
Signed-off-by: leo <[email protected]>
1 parent 3377886 commit e28b75b

File tree

1 file changed

+26
-29
lines changed

1 file changed

+26
-29
lines changed

src/Commands/Command.cs

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -36,39 +36,14 @@ public enum EditorType
3636

3737
public bool Exec()
3838
{
39+
Log?.AppendLine($"$ git {Args}\n");
40+
3941
var start = CreateGitStartInfo();
4042
var errs = new List<string>();
4143
var proc = new Process() { StartInfo = start };
4244

43-
Log?.AppendLine($"$ git {Args}\n");
44-
45-
proc.OutputDataReceived += (_, e) =>
46-
{
47-
if (e.Data is { } line)
48-
Log?.AppendLine(line);
49-
};
50-
51-
proc.ErrorDataReceived += (_, e) =>
52-
{
53-
var line = e.Data ?? string.Empty;
54-
Log?.AppendLine(line);
55-
56-
// Lines to hide in error message.
57-
if (line.Length > 0)
58-
{
59-
if (line.StartsWith("remote: Enumerating objects:", StringComparison.Ordinal) ||
60-
line.StartsWith("remote: Counting objects:", StringComparison.Ordinal) ||
61-
line.StartsWith("remote: Compressing objects:", StringComparison.Ordinal) ||
62-
line.StartsWith("Filtering content:", StringComparison.Ordinal) ||
63-
line.StartsWith("hint:", StringComparison.Ordinal))
64-
return;
65-
66-
if (REG_PROGRESS().IsMatch(line))
67-
return;
68-
}
69-
70-
errs.Add(line);
71-
};
45+
proc.OutputDataReceived += (_, e) => HandleOutput(e.Data, errs);
46+
proc.ErrorDataReceived += (_, e) => HandleOutput(e.Data, errs);
7247

7348
var dummy = null as Process;
7449
var dummyProcLock = new object();
@@ -217,6 +192,28 @@ private ProcessStartInfo CreateGitStartInfo()
217192
return start;
218193
}
219194

195+
private void HandleOutput(string line, List<string> errs)
196+
{
197+
line = line ?? string.Empty;
198+
Log?.AppendLine(line);
199+
200+
// Lines to hide in error message.
201+
if (line.Length > 0)
202+
{
203+
if (line.StartsWith("remote: Enumerating objects:", StringComparison.Ordinal) ||
204+
line.StartsWith("remote: Counting objects:", StringComparison.Ordinal) ||
205+
line.StartsWith("remote: Compressing objects:", StringComparison.Ordinal) ||
206+
line.StartsWith("Filtering content:", StringComparison.Ordinal) ||
207+
line.StartsWith("hint:", StringComparison.Ordinal))
208+
return;
209+
210+
if (REG_PROGRESS().IsMatch(line))
211+
return;
212+
}
213+
214+
errs.Add(line);
215+
}
216+
220217
[GeneratedRegex(@"\d+%")]
221218
private static partial Regex REG_PROGRESS();
222219
}

0 commit comments

Comments
 (0)