Skip to content

Remove CR newlines when generating merge commit message from template

What does this MR do and why?

In my recently merged MR (!64437 (merged)) I've added support for merge commit message template, and it had this newline removal feature for empty variables:

Whenever a variable that is the only word in line is empty (it's possible only for description and issues variables) we are removing it along with all newline characters that precede it.

When testing it today I've noticed one issue: it does not work properly when template has windows-style newlines (CRLF). It looks like ruby regex matches $ to end of line only when using LF type new lines. It doesn't match CRLF, causing it to not remove the whitelines.

I think we shouldn't allow CR in commit messages anyway, so now I simply remove them when rendering message.

Screenshots or screen recordings

Before (for default template but saved with CRLF line endings):

image

After:

image

How to set up and validate locally

  1. Go to project settings, set default merge commit template to:
Squashed branch '%{source_branch}' into '%{target_branch}'

%{title}

%{issues}

See merge request %{reference}
  1. Make sure that, for MR with no issues mentioned in description, there's only 2 new lines after MR title in merge commit message textarea instead of 4.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Piotr Stankowski

Merge request reports

Loading