英文:
How can I send a pull request using hub with the default message (without opening a text editor)?
问题
我正在使用hub
在命令行中发送拉取请求,像这样:
hub pull-request -b upstream:master -h me:feature
当我这样做时,hub
会自动打开我的终端文本编辑器,并显示拉取请求消息,以便我可以编辑它。然而,99.9%的情况下,我对hub
选择的默认消息完全满意,所以我宁愿让hub
使用默认消息而不打开文本编辑器。有没有办法做到这一点?
我知道我可以使用hub pull-request -m "message" ...
来避免使用编辑器,但那实际上会更麻烦,因为我需要重新输入消息。hub
man
页面上的其他选项似乎也不能做到这一点。
英文:
I am using hub
to send a pull request from the command line like so:
hub pull-request -b upstream:master -h me:feature
When I do this, hub
automatically opens up my terminal text editor and displays the pull request message so that I can edit it. However, 9.99 times out of 10 I am completely content with the message that hub
chooses as the default, so I would rather just have hub
use the default message without opening up a text editor. Is there any way to do this?
I know I could use hub pull-request -m "message" ...
, to avoid using an editor, but that would actually be more work because I would need to retype the message. None of the other options on the hub
man
page seem to do this either.
答案1
得分: 1
如果你检查一下commands/pull_request.go#pullRequest()
的实现,似乎无法避免使用编辑器。
提出一个补丁来添加一个新选项到这个命令应该不是很困难,这个选项可以避免以下这些行:
message, err := pullRequestChangesMessage(baseTracking, headTracking, fullBase, fullHead)
utils.Check(err)
editor, err = github.NewEditor("PULLREQ", "pull request", message)
utils.Check(err)
title, body, err = editor.EditTitleAndBody()
utils.Check(err)
目标是直接从message
中推断出title
和body
。
英文:
If you check how commands/pull_request.go#pullRequest()
is implemented, it doesn't seem possible to avoid the editor.
This shouldn't be very difficult to propose a patch adding a new option to this command, which would avoid the lines:
message, err := pullRequestChangesMessage(baseTracking, headTracking, fullBase, fullHead)
utils.Check(err)
editor, err = github.NewEditor("PULLREQ", "pull request", message)
utils.Check(err)
title, body, err = editor.EditTitleAndBody()
utils.Check(err)
The goal would be to directly infer title
and body
from the message
.
答案2
得分: 1
这是不可能的(并且根据hub问题#722中的原因,将来可能也不可能),但是我创建了一个解决方法,以防其他人想要在hub
中使用此功能:
-
创建一个名为
no-edit.sh
的空shell脚本:echo '#!/bin/bash' > no-edit.sh chmod +x no-edit.sh
**注意:**如果你想要,你可以编辑此脚本以输出带有
cat "$1"
的消息。**注意2:**或者,你可以像mislav在
hub
github问题#722中建议的那样,直接使用/usr/bin/true
。 -
创建以下shell脚本,并将其命名为任何你想要的名称(我选择了
hub-no-edit.sh
):#!/bin/bash OLD_GIT_EDITOR=$GIT_EDITOR export GIT_EDITOR=/path/to/no-edit.sh hub $@ export GIT_EDITOR=$OLD_GIT_EDITOR
-
现在将第二个脚本放在你的路径上,你就可以执行
pull-request
而无需编辑消息:hub-no-edit.sh pull-request -b base:master -h me:feature
英文:
This is not possible (and it will likely not be possible in the future for reasons outlined in hub issue #722), but I created a workaround in case anyone else wants this feature in hub
:
-
Create an empty shell script called something like
no-edit.sh
:echo '#!/bin/bash' > no-edit.sh chmod +x no-edit.sh
Note: You can edit this script to output the message with
cat "$1"
if you want.Note 2: Alternatively you could just use
/usr/bin/true
as recommended by mislav onhub
github issue #722. -
Create the following shell script and call it whatever you want (I went with
hub-no-edit.sh
):#!/bin/bash OLD_GIT_EDITOR=$GIT_EDITOR export GIT_EDITOR=/path/to/no-edit.sh hub $@ export GIT_EDITOR=$OLD_GIT_EDITOR
-
Now just put the second script on your path and you can execute a
pull-request
without editing the message:hub-no-edit.sh pull-request -b base:master -h me:feature
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论