在ruby脚本中,如何要求git打开其消息编辑器 [英] In a ruby script, how to ask git to open its message editor
问题描述
我目前正在开发一个命令行红宝石gem,用于自动化 https://gist.github.com/jbenet/ee6c9ac48068889b0912 .您可以在 https://github.com/gsmendoza/git_pretty_accept/tree中找到该gem的WIP代码/git_pretty_accept .宝石会做这样的事情:
I'm currently working on a command-line ruby gem that automates the "rebase + no-ff merging" workflow discussed at https://gist.github.com/jbenet/ee6c9ac48068889b0912. You can find the WIP code for this gem at https://github.com/gsmendoza/git_pretty_accept/tree/git_pretty_accept. The gem would do something like this:
git co master
git pull
git co pull_request
git rebase master
git co master
git merge --edit --no-ff pull_request
git push
git branch -d pull_request
git push origin:pull_request
当我尝试通过ruby运行这些git命令时,git merge --edit --no-ff pull_request
不会像我希望的那样打开git commit消息编辑器.相反,我认为git刚从编辑器收到一条空白合并消息,而ruby继续执行脚本的其余部分.
When I try to run these git commands via ruby, git merge --edit --no-ff pull_request
doesn't open the git commit message editor like I hope it would. Instead, I think git just receives a blank merge message from the editor and ruby continues with the rest of the script.
有什么想法吗?
推荐答案
Just read your code.
`git merge --no-ff --message "#{merge_message}" #{branch}`
在Ruby中,此反引号语法会重定向STDIN和STDOUT.
In Ruby, this backtick syntax redirects the STDIN and STDOUT.
只需尝试以下操作即可:
Simply try this instead:
system("git merge --edit --no-ff #{branch}")
system
函数只是在不触摸STDIN/STDOUT的情况下派生一个进程并等待子进程完成.我测试了并且可以用.
The system
function just forks a process and wait for the subprocess finish, without touching STDIN/STDOUT. I tested and it works.
这篇关于在ruby脚本中,如何要求git打开其消息编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!