enhance: introduce template engine for commit templates #719
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This replaces the regex-based approach to templates with a simple non-failing and forgiving parser.
Now there are 3 types of variables:
${FILES}
(BRANCH
,FILES_COUNT
,FILES
are supported)N
, e.g.${FILES:N}
(currently onlyFILES
is supported)regex
withreplacement
, e.g.${BRANCH/regex/replacement}
. Supports all variables that regular variables support. No newlines allowed insideregex
andreplacement
because that's error prone. Capture groups ($1
,$2
, ...) are supported, as expanding directly usesRegex.Replace(String, String)
.To escape variables within text, use
\
before$
, e.g.\${FILES}
. It is also used to escape/
withinregex
and}
withinreplacement
for regex variables.\
for escaping is only valid in those contexts, otherwise it behaves like a regular character, e.g.C:\a\b
=>C:\a\b
,\\
=>\
.I also changed the spelling of variables to be more recognizable and "standard", but legacy spellings like
files
,branch_name
were kept for compatibility.Adding a variable is trivial, add an entry to
s_variables
for regular ones and/or tos_slicedVariables
for sliced ones.Unknown variables are silently expanded to an empty string, but I propose to add some warning logic for this.
Since there is no testing framework used for SourceGit, I didn't add a test for the template engine, but I tested it externally and it works fine. I also did some manual testing inside SourceGit, but final check is needed.
Close #704