git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Bug: git push in a --mirror repository deletes all refs
@ 2019-08-21  0:05 Filippo Valsorda
  2019-09-02 18:08 ` [PATCH] push: disallow --all and refspecs when remote.<name>.mirror is set Thomas Gummerer
  0 siblings, 1 reply; 3+ messages in thread
From: Filippo Valsorda @ 2019-08-21  0:05 UTC (permalink / raw)
  To: git

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 git@github.com:FiloSottile/test.git
$ git ls-remote
From git@github.com: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 'git@github.com:FiloSottile/test.git'
$ git version
git version 2.22.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-09-03 18:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-08-21  0:05 Bug: git push in a --mirror repository deletes all refs Filippo Valsorda
2019-09-02 18:08 ` [PATCH] push: disallow --all and refspecs when remote.<name>.mirror is set Thomas Gummerer
2019-09-03 18:29   ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).