enhance: supports to use ${BRANCH}/${COMMIT}/${TAG} in Default field of TextBox/PathSelector in custom actions (#1466)

Signed-off-by: leo <longshuang@msn.cn>
This commit is contained in:
leo
2025-06-27 15:58:00 +08:00
parent fbcb3a966e
commit 0729c3044a

View File

@@ -127,12 +127,7 @@ namespace SourceGit.ViewModels
ProgressDescription = "Run custom action ...";
var cmdline = CustomAction.Arguments.Replace("${REPO}", GetWorkdir());
if (Target is Models.Branch b)
cmdline = cmdline.Replace("${BRANCH}", b.FriendlyName);
else if (Target is Models.Commit c)
cmdline = cmdline.Replace("${SHA}", c.SHA);
else if (Target is Models.Tag t)
cmdline = cmdline.Replace("${TAG}", t.Name);
cmdline = PrepareStringByTarget(cmdline);
for (var i = ControlParameters.Count - 1; i >= 0; i--)
{
@@ -165,18 +160,30 @@ namespace SourceGit.ViewModels
switch (ctl.Type)
{
case Models.CustomActionControlType.TextBox:
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, ctl.StringValue));
ControlParameters.Add(new CustomActionControlTextBox(ctl.Label, ctl.Description, PrepareStringByTarget(ctl.StringValue)));
break;
case Models.CustomActionControlType.CheckBox:
ControlParameters.Add(new CustomActionControlCheckBox(ctl.Label, ctl.Description, ctl.StringValue, ctl.BoolValue));
break;
case Models.CustomActionControlType.PathSelector:
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, ctl.StringValue));
ControlParameters.Add(new CustomActionControlPathSelector(ctl.Label, ctl.Description, ctl.BoolValue, PrepareStringByTarget(ctl.StringValue)));
break;
}
}
}
private string PrepareStringByTarget(string org)
{
if (Target is Models.Branch b)
return org.Replace("${BRANCH}", b.FriendlyName);
else if (Target is Models.Commit c)
return org.Replace("${SHA}", c.SHA);
else if (Target is Models.Tag t)
return org.Replace("${TAG}", t.Name);
return org;
}
private string GetWorkdir()
{
return OperatingSystem.IsWindows() ? _repo.FullPath.Replace("/", "\\") : _repo.FullPath;