From e65cb5049578f24d4cc033e5c63722afa645c733 Mon Sep 17 00:00:00 2001 From: leo Date: Mon, 10 Mar 2025 17:48:02 +0800 Subject: [PATCH] fix: use `\` as path delim on Windows when executing custom actions (#1077) Signed-off-by: leo --- src/ViewModels/ExecuteCustomAction.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/ViewModels/ExecuteCustomAction.cs b/src/ViewModels/ExecuteCustomAction.cs index 8e34379f..16a6410c 100644 --- a/src/ViewModels/ExecuteCustomAction.cs +++ b/src/ViewModels/ExecuteCustomAction.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; namespace SourceGit.ViewModels { @@ -13,7 +14,7 @@ namespace SourceGit.ViewModels public ExecuteCustomAction(Repository repo, Models.CustomAction action) { _repo = repo; - _args = action.Arguments.Replace("${REPO}", _repo.FullPath); + _args = action.Arguments.Replace("${REPO}", GetWorkdir()); CustomAction = action; View = new Views.ExecuteCustomAction() { DataContext = this }; } @@ -21,7 +22,7 @@ namespace SourceGit.ViewModels public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Branch branch) { _repo = repo; - _args = action.Arguments.Replace("${REPO}", _repo.FullPath).Replace("${BRANCH}", branch.FriendlyName); + _args = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${BRANCH}", branch.FriendlyName); CustomAction = action; View = new Views.ExecuteCustomAction() { DataContext = this }; } @@ -29,7 +30,7 @@ namespace SourceGit.ViewModels public ExecuteCustomAction(Repository repo, Models.CustomAction action, Models.Commit commit) { _repo = repo; - _args = action.Arguments.Replace("${REPO}", _repo.FullPath).Replace("${SHA}", commit.SHA); + _args = action.Arguments.Replace("${REPO}", GetWorkdir()).Replace("${SHA}", commit.SHA); CustomAction = action; View = new Views.ExecuteCustomAction() { DataContext = this }; } @@ -51,6 +52,11 @@ namespace SourceGit.ViewModels }); } + private string GetWorkdir() + { + return OperatingSystem.IsWindows() ? _repo.FullPath.Replace("/", "\\") : _repo.FullPath; + } + private readonly Repository _repo = null; private string _args = string.Empty; }