feature: add ${branch_name} option to commit templates (#589)

This commit is contained in:
Luis Frey 2024-10-22 03:44:53 +02:00 committed by GitHub
parent 6dac26d525
commit a8a7775b83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 8 additions and 4 deletions

View file

@ -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<Change> changes)
public string Apply(Repository repo, List<Change> 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;