@@ -296,3 +296,52 @@ STUB
296296 # Should have created an empty commit.
297297 grep -q " GIT: commit --allow-empty" " ${STUB_DIR} /git.log"
298298}
299+
300+ @test " conflict PR body contains real newlines, not literal backslash-n" {
301+ write_git_mock '
302+ if [[ "$1" == "fetch" ]]; then exit 0; fi
303+ if [[ "$1" == "cherry" ]]; then echo "+ abc123"; exit 0; fi
304+ if [[ "$1" == "checkout" ]]; then exit 0; fi
305+ if [[ "$1" == "rev-list" ]]; then echo "abc123def456 parent1"; exit 0; fi
306+ if [[ "$1" == "cherry-pick" ]]; then
307+ if [[ "$2" == "--abort" ]]; then exit 0; fi
308+ exit 1
309+ fi
310+ if [[ "$1" == "commit" ]]; then exit 0; fi
311+ if [[ "$1" == "push" ]]; then exit 0; fi
312+ exit 0
313+ '
314+ # Capture the full --body argument to a file for inspection.
315+ write_gh_mock '
316+ if [[ "$1" == "api" ]]; then echo "7.0.1"; exit 0; fi
317+ if [[ "$1" == "pr" && "$2" == "create" ]]; then
318+ while [[ $# -gt 0 ]]; do
319+ if [[ "$1" == "--body" ]]; then
320+ printf "%s" "$2" > "' " ${STUB_DIR} " ' /pr-body.txt"
321+ break
322+ fi
323+ shift
324+ done
325+ exit 0
326+ fi
327+ exit 0
328+ '
329+
330+ run bash " ${SCRIPT} "
331+ [ " $status " -eq 0 ]
332+
333+ # The body file must exist (gh pr create was called with --body).
334+ [ -f " ${STUB_DIR} /pr-body.txt" ]
335+
336+ local body
337+ body=" $( cat " ${STUB_DIR} /pr-body.txt" ) "
338+
339+ # Must NOT contain literal two-character sequence '\n'.
340+ [[ " $body " != * ' \\n' * ]]
341+ # Each command in the code block must be on its own line.
342+ [[ " $body " == * $' \n git fetch origin\n ' * ]]
343+ [[ " $body " == * $' \n git checkout dev/automation/pr-42-to-7.0.1\n ' * ]]
344+ [[ " $body " == * $' \n git cherry-pick abc123def456\n ' * ]]
345+ [[ " $body " == * $' \n # resolve conflicts\n ' * ]]
346+ [[ " $body " == * $' \n git push origin dev/automation/pr-42-to-7.0.1 --force\n ' * ]]
347+ }
0 commit comments