git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Bug: git push in a --mirror repository deletes all refs

From
FVFilippo Valsorda <filippo@ml.filippo.io>
Date
Aug 21, 2019, 00:05 UTC
Message-ID
<4d995a0b-0ac4-45a0-9ead-1bc76bd720c7@www.fastmail.com>

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.

Show 6 quoted lines
> 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
Next: Thomas Gummerer
Message 1 of 3 in “Bug: git push in a --mirror repository deletes all refs”
  1. Filippo ValsordaAug 21, 2019
  2. push: disallow --all and refspecs when remote.<name>.mirror is setThomas Gummerer, Sep 2, 2019
  3. Junio C HamanoSep 3, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.