Merge/squash commit templates: avoid breaking Git trailers
What does this MR do and why?
Solves #349622 (closed)
In the Merge/Squash commit message templates we are removing variables with empty values along with the blank lines before it. It was made to allow recreating default merge commit template:
Merge branch '%{source_branch}' into '%{target_branch}'
%{title}
%{issues}
See merge request %{reference}
and if the issues are empty, we would remove the preceding new lines:
Merge branch '%{source_branch}' into '%{target_branch}'
%{title}
See merge request %{reference}
However, recently we've added variables that form Git trailers by themselves - in !76042 (merged) we've added %{co_authored_by}
, and in !75639 (merged) we've added %{approved_by}
.
This blank line removal can also remove the blank line that is required to form valid Git trailers:
%{title}
%{co_authored_by}
MR: %{url}
Merged-By: %{merged_by}
and if the %{co_authored_by}
is empty it becomes:
%{title}
MR: %{url}
Merged-By: %{merged_by}
This MR fixes it, so that instead it becomes:
%{title}
MR: %{url}
Merged-By: %{merged_by}
This change simply removes the preceding blank line only if the variable is also followed by a blank line. So we can still recreate the default templates, but we no longer remove blank lines that can break formatting of a message.
How to set up and validate locally
Follow http://localhost:3005/ee/user/project/merge_requests/commit_templates.html to fill in merge/squash templates. I've used the following template to validate it:
%{title}
%{co_authored_by}
MR: %{url}
Merged-By: %{merged_by}
without any co-authors in a MR.
And also the default one:
Merge branch '%{source_branch}' into '%{target_branch}'
%{title}
%{issues}
See merge request %{reference}
to make sure there's no regression.
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.