From a8a7775b830e9ebe0e4f626e1896ec70df12761e Mon Sep 17 00:00:00 2001 From: Luis Frey <58328398+FreyLuis@users.noreply.github.com> Date: Tue, 22 Oct 2024 03:44:53 +0200 Subject: [PATCH] feature: add ${branch_name} option to commit templates (#589) --- src/Models/CommitTemplate.cs | 8 ++++++-- src/ViewModels/WorkingCopy.cs | 2 +- src/Views/RepositoryConfigure.axaml | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Models/CommitTemplate.cs b/src/Models/CommitTemplate.cs index 135d8ac9..ba9a4911 100644 --- a/src/Models/CommitTemplate.cs +++ b/src/Models/CommitTemplate.cs @@ -4,6 +4,7 @@ using System.Text; using System.Text.RegularExpressions; using CommunityToolkit.Mvvm.ComponentModel; +using SourceGit.ViewModels; namespace SourceGit.Models { @@ -24,9 +25,12 @@ namespace SourceGit.Models set => SetProperty(ref _content, value); } - public string Apply(List changes) + public string Apply(Repository repo, List changes) { - var content = _content.Replace("${files_num}", $"{changes.Count}"); + var content = _content + .Replace("${files_num}", $"{changes.Count}") + .Replace("${branch_name}", repo.CurrentBranch.Name); + var matches = REG_COMMIT_TEMPLATE_FILES().Matches(content); if (matches.Count == 0) return content; diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 209da812..26b81de6 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1152,7 +1152,7 @@ namespace SourceGit.ViewModels item.Icon = App.CreateMenuIcon("Icons.Code"); item.Click += (_, e) => { - CommitMessage = template.Apply(_staged); + CommitMessage = template.Apply(_repo, _staged); e.Handled = true; }; menu.Items.Add(item); diff --git a/src/Views/RepositoryConfigure.axaml b/src/Views/RepositoryConfigure.axaml index f167b8f0..1a9c3235 100644 --- a/src/Views/RepositoryConfigure.axaml +++ b/src/Views/RepositoryConfigure.axaml @@ -227,7 +227,7 @@