When used in a repository cloned with --mirror, git push with refs on
the command line deletes all unmentioned refs.

This was investigated by @saleemrash1d on Twitter. I'm reporting
their findings here and a reproduction below.

> seems to be a regression.
> TRANSPORT_PUSH_MIRROR is set by remote->mirror
> (https://github.com/git/git/blob/5fa0f5238b0/builtin/push.c#L410)
> AFTER the check for refspecs provided on the command-line
> (https://github.com/git/git/blob/5fa0f5238/builtin/push.c#L615).
> introduced by 800a4ab399e954b8970897076b327bf1cf18c0ac.

> it's mirroring only the refspecs you provided on the command-line to
> the server. i.e. all local refs that aren't stated on the command-line
> will still be deleted

> this unexpected behaviour is why --mirror isn't allowed to be used
> when refspecs are specified on the command-line. but the above commit
> moves the sanity check so it doesn't catch the implied --mirror when
> remote.<remote>.mirror is set (i.e. cloned with --mirror)

https://twitter.com/saleemrash1d/status/1163963105849876481

$ git clone --mirror [email protected]:FiloSottile/test.git
$ git ls-remote
>From [email protected]:FiloSottile/test.git
2aa1cacf9b1a6b1227c7c13367ec38637ef3d9a3        HEAD
2aa1cacf9b1a6b1227c7c13367ec38637ef3d9a3        refs/heads/master
773069ef7f893e7fcb3271e6ba80eeafbfb98694        refs/heads/patch-1
2aa1cacf9b1a6b1227c7c13367ec38637ef3d9a3        refs/tags/v0.0.0
$ git show-ref
2aa1cacf9b1a6b1227c7c13367ec38637ef3d9a3 refs/heads/master
773069ef7f893e7fcb3271e6ba80eeafbfb98694 refs/heads/patch-1
2aa1cacf9b1a6b1227c7c13367ec38637ef3d9a3 refs/tags/v0.0.0
$ git push -d origin patch-1
To github.com:FiloSottile/test.git
 - [deleted]         patch-1
 - [deleted]         v0.0.0
 ! [remote rejected] master (refusing to delete the current branch: 
refs/heads/master)
error: failed to push some refs to '[email protected]:FiloSottile/test.git'
$ git version
git version 2.22.0

Reply via email to