如何在命令行中编写一个多行的合并请求描述
我正在通过命令行创建一个MR(合并请求)的脚本。
我将通过Python的 subprocess来运行,因为这是最终实现时的做法。
1 description = [
2 "This is the first line of the description.",
3 "The description has multiple lines.",
4 "Each line is an element in this list."
5 ]
6
7 git_MR_options = [
8 '-o merge_request.create',
9 # ... other options
10 '-o merge_request.description="' + '\n'.join(description) + '"'
11 ]
12
13 subprocess.run(
14 ["git", "push", * git_MR_options],
15 check=True, text=True, capture_output=True
16 )
然而,出于某种原因,git不喜欢我的多行描述,
我得到如下错误:
fatal: push options must not have new line characters
显然,-o merge_request.description 不能包含 \n 来分隔新行。
(我尝试把第 10 行中的 \n 替换为空格,结果生效了,但我明确不想让描述只有一行)
有什么方法可以解决这个问题吗?
Git版本安装在我的系统上:2.39.5
解决方案
虽然 \n 不被允许,但 <br> 是可以的。
因此,问题中的第 10 行看起来会是这样的:
merge_request.description=' + '<br>'.join(git_MR_description)
此外,描述开头和结尾的引号也不是必需的。
站内所有文章版权归属LeftHeroAI导航站,无授权禁止任何主体转载、抄袭、复制内容,亦不得私自架设镜像站点。一经侵权,本站将通过法律途径追责。