Skip to content

Commit f85f344

Browse files
committed
#33 - Rewrite background git process execution.
1 parent e186875 commit f85f344

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

src/GitExtensions.BundleBackuper/Services/GitUiCommandsBundleService.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ private string FindCommitIdIfPushed(IGitUICommands commands, string head, int he
151151

152152
private string FindCommitId(IGitUICommands commands, string head, int headOffset)
153153
{
154-
string commitId = commands.GitModule.RunGitCmd($"rev-parse {head}~{headOffset}").Trim();
154+
string commitId = RunGitCommand(commands, $"rev-parse {head}~{headOffset}").Trim();
155155
if (!String.IsNullOrWhiteSpace(commitId) && !commitId.Contains(" "))
156156
return commitId;
157157

@@ -164,7 +164,9 @@ private bool IsCommitPushed(IGitUICommands commands, string head, int headOffset
164164
if (String.IsNullOrEmpty(commitId))
165165
return true;
166166

167-
string branches = commands.GitModule.RunGitCmd($"branch -r --contains {commitId}");
167+
168+
169+
string branches = RunGitCommand(commands, $"branch -r --contains {commitId}");
168170
if (String.IsNullOrWhiteSpace(branches))
169171
return false;
170172

@@ -211,5 +213,19 @@ private int BinarySearch(int start, int end, Func<int, int> predicate)
211213
throw Ensure.Exception.NotSupported("BinarySearch predicate must return -1, 0 or 1.");
212214
}
213215
}
216+
217+
private string RunGitCommand(IGitUICommands commands, string arguments)
218+
{
219+
using (IProcess process = commands.GitModule.GitCommandRunner.RunDetached(arguments, redirectOutput: true))
220+
{
221+
process.WaitForExit();
222+
223+
string error = process.StandardError.ReadToEnd();
224+
if (!String.IsNullOrEmpty(error))
225+
return error;
226+
227+
return process.StandardOutput.ReadToEnd();
228+
}
229+
}
214230
}
215231
}

0 commit comments

Comments
 (0)