【发布时间】:2017-03-21 12:54:55
【问题描述】:
当我将更改连同通常的统计信息一起推送到我们的 Bitbucket 服务器时,服务器会响应以“remote:”开头的几行。其中一行包含一个 URL,用于推送分支的少数差异并创建拉取请求。我目前突出显示 URL 并将其复制/粘贴到浏览器窗口中以创建我的拉取请求,但我希望加快该过程。有没有办法提取 URL 并将其传递给 'clip' 以将其作为 git 别名的一部分保存到剪贴板?
我还考虑过尝试使用当前分支名称和远程 URL 的组合重新创建 URL,但是远程 URL 和拉取请求 URL 之间存在一些差异,因此提取 URL 似乎更容易而不是重新创建它。
Counting objects: 47, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (45/45), done.
Writing objects: 100% (47/47), 12.81 KiB | 0 bytes/s, done.
Total 47 (delta 40), reused 3 (delta 2)
remote:
remote: Create pull request for feature/somefeature:
remote: https://code.ourbitbucketserver.com/projects/myteam/repos/somerepo/compare/commits?sourceBranch=refs/heads/feature/somefeature
remote:
To https://code.ourbitbucketserver.com/scm/myteam/somerepo.git
* [new branch] feature/somefeature -> feature/somefeature
Branch feature/somefeature set up to track remote branch feature/somefeature from origin.
解决方案
bcurrent = "!git rev-parse --abbrev-ref HEAD"
publishold = "!f() { git push -u ${1-origin} $(git bcurrent); }; f"
publishnew = "!f() { git push -u ${1-origin} $(git bcurrent) --progress 2>&1 | awk '/^remote:.*compare/ { system(\"echo \" $2 \" | clip\") } { print }'; }; f"
bcurrent 和 publishold 别名是我开始参考的。
接受的答案使我朝着正确的方向前进。在此过程中,我遇到了一些我想解释的问题。
-
git push通过 stderr 而不是 stdout 输出一些消息(包括 url)。所以我们必须用2>&1重定向stderr。还添加了--progress标志,因此即使它没有连接到控制台,git 也会输出 stderr,因为我们正在将输出通过管道传输到 awk。见git stderr output can't pipe -
clip不接受命令行参数,必须通过管道输入。 - 由于我的 git 别名是一个 shell 函数,我不得不在
system调用中转义双引号。
【问题讨论】:
-
你能发布输出吗?
-
请阅读并遵守stackoverflow.com/help/someone-answers ;-)
标签: git bitbucket git-push pull-request