mirror of
https://github.com/sourcegit-scm/sourcegit.git
synced 2024-12-22 20:37:19 -08:00
feature: add ${branch_name} option to commit templates (#589)
This commit is contained in:
parent
6dac26d525
commit
a8a7775b83
3 changed files with 8 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue