diff --git a/src/ViewModels/WorkingCopy.cs b/src/ViewModels/WorkingCopy.cs index 59de9245..ef57ec2b 100644 --- a/src/ViewModels/WorkingCopy.cs +++ b/src/ViewModels/WorkingCopy.cs @@ -1351,8 +1351,9 @@ namespace SourceGit.ViewModels { var menu = new ContextMenu(); + var gitTemplate = new Commands.Config(_repo.FullPath).Get("commit.template"); var templateCount = _repo.Settings.CommitTemplates.Count; - if (templateCount == 0) + if (templateCount == 0 && string.IsNullOrEmpty(gitTemplate)) { menu.Items.Add(new MenuItem() { @@ -1376,6 +1377,29 @@ namespace SourceGit.ViewModels }; menu.Items.Add(item); } + + if (!string.IsNullOrEmpty(gitTemplate)) + { + var friendlyName = gitTemplate; + if (!OperatingSystem.IsWindows()) + { + var home = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); + var prefixLen = home.EndsWith('/') ? home.Length - 1 : home.Length; + if (gitTemplate.StartsWith(home, StringComparison.Ordinal)) + friendlyName = "~" + gitTemplate.Substring(prefixLen); + } + + var gitTemplateItem = new MenuItem(); + gitTemplateItem.Header = new Views.NameHighlightedTextBlock("WorkingCopy.UseCommitTemplate", friendlyName); + gitTemplateItem.Icon = App.CreateMenuIcon("Icons.Code"); + gitTemplateItem.Click += (_, e) => + { + if (File.Exists(gitTemplate)) + CommitMessage = File.ReadAllText(gitTemplate); + e.Handled = true; + }; + menu.Items.Add(gitTemplateItem); + } } menu.Items.Add(new MenuItem() { Header = "-" });