git push --atomic-没有失败 [英] git push --atomic - Not failing

查看:78
本文介绍了git push --atomic-没有失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试对 git push 使用相对较新的-atomic 选项,但是它对我没有用,即,它仍然允许一些引用进行更改即使其他人失败了.

I have been trying to use the relatively new --atomic option for git push, but it has not worked for me, i.e., it still lets some refs change even though others failed.

从差异此处看来,也会接受原子标记.虽然这很合理,但似乎默认是使用它.

It seems from the diff here that there needs to be something on the remote server that will accept the atomic flag as well. While this makes sense, it seems that the default is to use it.

我要推送到具有http协议的BitBucket服务器实例.服务器上Git的当前版本是"git version 2.8.1".

I am pushing to a BitBucket server instance with http protocol. The current version of Git on the server is "git version 2.8.1".

我是否需要在服务器上进行配置才能使其正常工作?

Is there something that I need to configure on the server to enable this to work?

下面是可以复制的示例.

Below is an example which can reproduced.

服务器上的配置

$ git --version
git version 2.8.1

$ git config --get-all --show-origin  receive.advertiseatomic
file:/home/bitbucket/.gitconfig 1

在客户端上:

$ git --version
git version 2.8.2.windows.1

$ git push <local-path>/.git HEAD:refs/heads/wwww HEAD:refs/heads/zzz --force-with-lease=zzz --atomic
error: atomic push failed for ref refs/heads/zzz. status: 7

fatal: The remote end hung up unexpectedly
To <local-path>/.git
 ! [rejected]        HEAD -> wwww (atomic push failed)
 ! [rejected]        HEAD -> zzz (stale info)
error: failed to push some refs to '<local-path>/.git'

$ git push origin HEAD:refs/heads/wwww HEAD:refs/heads/zzz --force-with-lease=zzz --atomic
Total 0 (delta 0), reused 0 (delta 0)
remote:
remote:
To http://me@bitbucket-local.com/scm/proj/repo.git
 * [new branch]      HEAD -> wwww
 ! [rejected]        HEAD -> zzz (stale info)
 error: failed to push some refs to 'http://me@bitbucket-local.com/scm/proj/repo.git'

推荐答案

我是Bitbucket Server开发人员之一.抱歉为这个问题提供这么晚的答复,但我只是注意到了.

I'm one of the Bitbucket Server developers. Apologies for such a late response to this question but I only just noticed it.

这似乎就是Git的工作方式.例如,如果您通过HTTPS在GitHub上重新测试git push --atomic ,您将看到相同的行为.

This appears to be just how Git works. If you re-test your git push --atomic with GitHub via HTTPS, for example, you'll see identical behavior.

查看Git源代码 remote-curl.c ,它为 git-remote-http 提供 main git-remote-https ,在调用 git send-pack 发送打包文件时未通过-atomic .(查看发送包装的方式命令行是在此处构建的)因此,当将 git push --atomic 与HTTP(S)远程服务器一起使用时,-atomic 很简单被忽略,推送正常运行.这就是为什么您看到正在创建分支的原因.

Looking at the Git source code, remote-curl.c, which provides main for git-remote-http and git-remote-https, does not pass --atomic when it invokes git send-pack to send a pack file. (See how the send-pack command line is constructed here) So when using git push --atomic with an HTTP(S) remote, the --atomic is simply ignored and the push runs as normal. That's why you see the branch being created.

请注意,这根本不是服务器端的行为.在这种情况下,Bitbucket Server或任何其他托管服务提供商都无法做.如果您使用 GIT_TRACE_PACKET = 1 来跟踪客户端和服务器之间相互发送的内容,则会看到如下所示的对话:

Note that this isn't a server-side behavior at all. There's nothing Bitbucket Server, or any other hosting provider, can do in this situation. If you use GIT_TRACE_PACKET=1 to trace what the client and server send to each other, you'll see a conversation like this:

22:16:06.562939 pkt-line.c:46           packet:          git< #
service=git-receive-pack
22:16:06.562990 pkt-line.c:46           packet:          git< 0000
22:16:06.562994 pkt-line.c:46           packet:          git<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319
refs/heads/branch-1\0report-status delete-refs side-band-64k quiet
atomic ofs-delta agent=git/github-g4f6c801f9475
22:16:06.563013 pkt-line.c:46           packet:          git<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319 refs/heads/branch-2
22:16:06.563016 pkt-line.c:46           packet:          git<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319 refs/heads/branch-3
22:16:06.563019 pkt-line.c:46           packet:          git<
fe86a3eae65e18787040499c17a567096159b9ce refs/heads/master
22:16:06.563024 pkt-line.c:46           packet:          git< 0000
22:16:06.563329 pkt-line.c:46           packet:          git>
HEAD:refs/heads/branch-4
22:16:06.563346 pkt-line.c:46           packet:          git> 0000
22:16:06.563357 run-command.c:347       trace: run_command:
'send-pack' '--stateless-rpc' '--helper-status' '--thin' '--progress'
'https://github.com/bturner/atomic-pushes.git/' '--stdin'
22:16:06.563765 exec_cmd.c:129          trace: exec: 'git' 'send-pack'
'--stateless-rpc' '--helper-status' '--thin' '--progress'
'https://github.com/bturner/atomic-pushes.git/' '--stdin'
22:16:06.564691 git.c:348               trace: built-in: git
'send-pack' '--stateless-rpc' '--helper-status' '--thin' '--progress'
'https://github.com/bturner/atomic-pushes.git/' '--stdin'
22:16:06.564788 pkt-line.c:46           packet:          git<
HEAD:refs/heads/branch-4
22:16:06.564793 pkt-line.c:46           packet:          git< 0000
22:16:06.564797 pkt-line.c:46           packet:          git<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319
refs/heads/branch-1\0report-status delete-refs side-band-64k quiet
atomic ofs-delta agent=git/github-g4f6c801f9475
22:16:06.564805 pkt-line.c:46           packet:          git<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319 refs/heads/branch-2
22:16:06.564826 pkt-line.c:46           packet:          git<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319 refs/heads/branch-3
22:16:06.564830 pkt-line.c:46           packet:          git<
fe86a3eae65e18787040499c17a567096159b9ce refs/heads/master
22:16:06.564834 pkt-line.c:46           packet:          git< 0000
22:16:06.564970 pkt-line.c:46           packet:          git>
0000000000000000000000000000000000000000
6925c65344e87c65e5cd2b56d392cd06ef96ca71 refs/heads/branch-4\0
report-status side-band-64k agent=git/2.4.0
22:16:06.564989 pkt-line.c:46           packet:          git> 0000
22:16:06.565027 pkt-line.c:46           packet:          git<
00960000000000000000000000000000000000000000
6925c65344e87c65e5cd2b56d392cd06ef96ca71 refs/heads/branch-4\0
report-status side-band-64k agent=git/2.4.00000

在此输出中,我运行了 git push --atomic https://github.com/... non-fast-forward:refs/heads/master non-fast-forward:refs/heads/branch-4 .请注意,运行 git send-pack 时,没有设置-atomic 选项(但 git send-pack 中的原子处理发送-pack.c 永远不会触发.

In this output, I've run git push --atomic https://github.com/... non-fast-forward:refs/heads/master non-fast-forward:refs/heads/branch-4. Notice that when git send-pack is run, there's no --atomic option set (but git send-pack does support it being set). That means the atomic handling in send-pack.c is never triggered.

您可以从随后的对话"中看到这一点."git<"行是 server 对客户端说的内容,因此您可以看到ref广告已发送."git>"行是 client 对服务器说的话.注意,有一个"git>"行发送"refs/heads/branch-4",但是没有类似的行用于"refs/heads/master". client 甚至根本不会尝试将主"更新发送到服务器,因为使用服务器的ref广告,它已经知道是非快速的,向前,并且由于未使用-force ,因此该更新将失败.

You can see that in action from the "conversation" that follows. "git<" lines are things the server said to the client, so you can see the ref advertisement is sent. "git>" lines are things the client said to the server. Notice that there's a "git>" line sending "refs/heads/branch-4", but there is no similar line for "refs/heads/master". The client never even tries to send the "master" update to the server at all, because, using the server's ref advertisement, it already knows that update is non-fast-forward and, since --force wasn't used, that that update is going to fail.

SSH的有线协议输出更加简单:

SSH's wire protocol output is even more simple:

22:56:08.609608 pkt-line.c:46           packet:         push<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319
refs/heads/branch-1\0report-status delete-refs side-band-64k quiet
atomic ofs-delta agent=git/github-g4f6c801f9475
22:56:08.609774 pkt-line.c:46           packet:         push<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319 refs/heads/branch-2
22:56:08.609798 pkt-line.c:46           packet:         push<
1b9c21b7aeb6ad03957cc8a023b2406d3ccee319 refs/heads/branch-3
22:56:08.609801 pkt-line.c:46           packet:         push<
6925c65344e87c65e5cd2b56d392cd06ef96ca71 refs/heads/branch-4
22:56:08.609825 pkt-line.c:46           packet:         push<
fe86a3eae65e18787040499c17a567096159b9ce refs/heads/master
22:56:08.609831 pkt-line.c:46           packet:         push< 0000

类似于HTTPS,"push<"行是服务器对客户端说的内容.如您所见,服务器发送参考广告,然后客户端简单地中止-它从不向服务器写入单个数据包.

Similar to HTTPS, "push<" lines are what the server said to the client. As you can see, the server sends a ref advertisement, and then the client simply aborts--it never writes a single packet to the server.

因此,在这两种情况下,服务器都完全不会处理-atomic .这并不是说不可能不可能,但是对于这些简单的示例, client 可以检测到至少一个更新肯定会失败,-atomic 完全在本地处理(或未处理).

So in neither of these cases was the --atomic handled by the server at all. That's not to say it never can be, but for these simple examples, where the client can detect at least one update is sure to fail, --atomic is handled (or not handled) entirely locally.

这篇关于git push --atomic-没有失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆