Skip to content

Commit a8a7775

Browse files
authored
feature: add ${branch_name} option to commit templates (#589)
1 parent 6dac26d commit a8a7775

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

src/Models/CommitTemplate.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Text.RegularExpressions;
55

66
using CommunityToolkit.Mvvm.ComponentModel;
7+
using SourceGit.ViewModels;
78

89
namespace SourceGit.Models
910
{
@@ -24,9 +25,12 @@ public string Content
2425
set => SetProperty(ref _content, value);
2526
}
2627

27-
public string Apply(List<Change> changes)
28+
public string Apply(Repository repo, List<Change> changes)
2829
{
29-
var content = _content.Replace("${files_num}", $"{changes.Count}");
30+
var content = _content
31+
.Replace("${files_num}", $"{changes.Count}")
32+
.Replace("${branch_name}", repo.CurrentBranch.Name);
33+
3034
var matches = REG_COMMIT_TEMPLATE_FILES().Matches(content);
3135
if (matches.Count == 0)
3236
return content;

src/ViewModels/WorkingCopy.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,7 @@ public ContextMenu CreateContextMenuForCommitMessages()
11521152
item.Icon = App.CreateMenuIcon("Icons.Code");
11531153
item.Click += (_, e) =>
11541154
{
1155-
CommitMessage = template.Apply(_staged);
1155+
CommitMessage = template.Apply(_repo, _staged);
11561156
e.Handled = true;
11571157
};
11581158
menu.Items.Add(item);

src/Views/RepositoryConfigure.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@
227227
<TextBlock Margin="0,12,0,0" Text="{DynamicResource Text.Configure.CommitMessageTemplate.Content}"/>
228228
<v:CommitMessageTextBox Margin="0,4,0,0" Height="100" Text="{Binding Content, Mode=TwoWay}"/>
229229
<TextBlock Margin="0,2,0,0"
230-
Text="You can use ${files_num}, ${files} and ${files:N} where N is the max number of file paths to output."
230+
Text="You can use ${files_num}, ${branch_name}, ${files} and ${files:N} where N is the max number of file paths to output."
231231
Foreground="{DynamicResource Brush.FG2}"
232232
TextWrapping="Wrap"/>
233233
</StackPanel>

0 commit comments

Comments
 (0)