tsvallender
tsvallender

Reputation: 2974

How to supply a text file with newlines as input to git push options

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?

Upvotes: 1

Views: 799

Answers (1)

sytech
sytech

Reputation: 40891

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"

Upvotes: 1

Related Questions