1

I'm trying to set a GitLab merge request from the command line, using the -o merge_request.description="my merge request" option.

However, I wish to supply an entire Markdown file, and if I do this the command complains that newlines are not allowed. I have also tried using sed to replace all newlines with '\n', but these are then taken literally and my merge request is one line containing lots of '\n's.

Is there a way around this?

tsvallender
  • 2,615
  • 6
  • 32
  • 42

1 Answers1

1

Although git push options don't allow for newlines, you can replace newlines with <br> to get a similar effect.

# ref: https://stackoverflow.com/a/1252191/5747944
description="$(sed -e ':a' -e 'N' -e '$!ba' -e 's/\n/<br>/g' description.md)"
git push -o merge_request.description="$description"
sytech
  • 29,298
  • 3
  • 45
  • 86
  • This is potentially a solution if we change our MR templates to HTML but doesn't solve the issue for using markdown which is the preference – tsvallender Mar 30 '22 at 15:44
  • @tsvallender this does work for markdown. HTML markup like `
    ` is allowed to be mixed in with markdown. Though, you will find when editing the description, the `
    ` will be present instead of newlines, which may not be ideal for you. Unfortunately, that's simply a limitation of git push options.
    – sytech Mar 30 '22 at 19:05
  • Yes the tags are allowed within the markdown, but as markdown relies on certain characters - such as # - starting a line, these don't work as they are no longer on a new line. – tsvallender Mar 30 '22 at 20:35
  • 1
    Gotcha, yeah. That won't work with this solution, either. Tables, etc, also won't work if using usual markup. I don't think there's any solution for that given push options don't allow newlines. – sytech Mar 30 '22 at 20:37