Browse Source

Quote strings passed to git, add handling of empty args

pull/55/head
Ionite 1 year ago
parent
commit
9b2d91ee52
No known key found for this signature in database
  1. 10
      StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs

10
StabilityMatrix.Avalonia/Helpers/UnixPrerequisiteHelper.cs

@ -1,11 +1,13 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using System.Runtime.Versioning; using System.Runtime.Versioning;
using System.Threading.Tasks; using System.Threading.Tasks;
using Avalonia.Controls; using Avalonia.Controls;
using FluentAvalonia.UI.Controls; using FluentAvalonia.UI.Controls;
using NLog; using NLog;
using StabilityMatrix.Core.Exceptions; using StabilityMatrix.Core.Exceptions;
using StabilityMatrix.Core.Extensions;
using StabilityMatrix.Core.Helper; using StabilityMatrix.Core.Helper;
using StabilityMatrix.Core.Models.FileInterfaces; using StabilityMatrix.Core.Models.FileInterfaces;
using StabilityMatrix.Core.Models.Progress; using StabilityMatrix.Core.Models.Progress;
@ -123,12 +125,14 @@ public class UnixPrerequisiteHelper : IPrerequisiteHelper
public async Task RunGit(string? workingDirectory = null, params string[] args) public async Task RunGit(string? workingDirectory = null, params string[] args)
{ {
var command = "git " + string.Join(" ", args); var command = args.Length == 0 ? "git" :
"git " + string.Join(" ", args.Select(ProcessRunner.Quote));
var result = await ProcessRunner.RunBashCommand(command, workingDirectory ?? ""); var result = await ProcessRunner.RunBashCommand(command, workingDirectory ?? "");
if (result.ExitCode != 0) if (result.ExitCode != 0)
{ {
throw new ProcessException($"Git command failed with exit code {result.ExitCode}:\n" + throw new ProcessException($"Git command {command.ToRepr()} failed with exit code" +
$"{result.StandardOutput}\n{result.StandardError}"); $" {result.ExitCode}:\n{result.StandardOutput}\n{result.StandardError}");
} }
} }

Loading…
Cancel
Save