如何干运行 git push 来检查一个人是否对远程有写权限?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25403573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How can one dry run a git push to check whether one has write permissions to a remote?
提问by David
Is there a way to dry run a git push
to know whether the user has permissions to actually create a new remote branch? I'd like to be able to verify that all is good in regards to permissions for a bunch of repos where the user will attempt to create new branches before they are actually created so that I can dry run the full execution before actually doing it.
有没有办法试运行 agit push
以了解用户是否有权实际创建新的远程分支?我希望能够验证在一堆 repos 的权限方面一切正常,用户将在实际创建新分支之前尝试创建新分支,以便我可以在实际执行之前先试运行完整执行。
回答by jub0bs
Shawn Pierce wrotethe following about git push --dry-run
:
肖恩·皮尔斯(Shawn Pierce)写了以下内容git push --dry-run
:
A
--dry-run
doesn't send the commands the client would use from client to server, so the server can't tell the client if it would accept them or not. The entire--dry-run
thing is client side only.
A
--dry-run
不会将客户端将使用的命令从客户端发送到服务器,因此服务器无法告诉客户端它是否会接受它们。整个--dry-run
事情只是客户端。
(my emphasis)
(我的重点)
So, if there is a way to check whether one has write permissions to a remote, git push --dry-run
is definitely not it.
所以,如果有一种方法可以检查一个人是否对远程有写权限,git push --dry-run
肯定不是。
回答by David
Posting as an answer on the test I did where I don't think it works in my scenario. I'm creating a branch form another one without further changes
在我所做的测试中作为答案发布,我认为它在我的场景中不起作用。我正在从另一个分支创建一个分支,而无需进一步更改
git clone ....
git checkout master
git branch -f test master
git push --dry-run origin test
and it passed even though I have zero push permissions on this server/repo combo
即使我对此服务器/存储库组合的推送权限为零,它也通过了
To ssh://<server>/repo
* [new branch] test -> test
Pushing without dry-run hits the error condition I was expecting
在没有空运行的情况下推动达到了我期望的错误条件
git push origin test
Total 0 (delta 0), reused 0 (delta 0)
remote: Processing changes: refs: 1, done
To ssh://<server>/repo
! [remote rejected] test -> test (can not create new references)
error: failed to push some refs to 'ssh://<server>/repo'