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;

View file

@ -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);

View file

@ -227,7 +227,7 @@
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CommitMessageTemplate.Content}"/>
<v:CommitMessageTextBox Margin="0,4,0,0" Height="100" Text="{Binding Content, Mode=TwoWay}"/>
<TextBlock Margin="0,2,0,0"
Text="You can use ${files_num}, ${files} and ${files:N} where N is the max number of file paths to output."
Text="You can use ${files_num}, ${branch_name}, ${files} and ${files:N} where N is the max number of file paths to output."
Foreground="{DynamicResource Brush.FG2}"
TextWrapping="Wrap"/>
</StackPanel>