Bug 17702 - "git push --mirror" sends remotes (contrary to the docs)
Summary: "git push --mirror" sends remotes (contrary to the docs)
Status: CLOSED WONTFIX
Alias: None
Product: Branch 4.1
Classification: Distributions
Component: git-core (show other bugs)
Version: unspecified
Hardware: all Linux
: P2 normal
Assignee: Nobody's working on this, feel free to take it
QA Contact: qa-4.1@altlinux.org
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-10-28 16:45 MSK by Ivan Zakharyaschev
Modified: 2014-11-05 20:41 MSK (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ivan Zakharyaschev 2008-10-28 16:45:09 MSK
git-core-1.5.5.5-alt1

"man git-push" says:

       --mirror
           Instead of naming each ref to push, specifies that all refs under
           $GIT_DIR/refs/heads/ and $GIT_DIR/refs/tags/ be mirrored to the
           remote repository. Newly created local refs will be pushed to the
           remote end, locally updated refs will be force updated on the
           remote end, and deleted refs will be removed from the remote end.

But the actual behavior is different: it sends *all* refs, including remotes. The actual behavior is not convenient: it results--in the mirror repository--in superfluous remote refs duplicating the same repository under the given name.

Demonstration (pay attention to the second turn of "git push", which sends refs/remotes/copy/master):

[ivan@arrakis data]$ mkdir -v ~/test-git-mirror-remotes
mkdir: создан каталог `/home/ivan/test-git-mirror-remotes'
[ivan@arrakis data]$ cd ~/test-git-mirror-remotes
[ivan@arrakis test-git-mirror-remotes]$ git init
Initialized empty Git repository in .git/
[ivan@arrakis test-git-mirror-remotes]$ echo a > a
[ivan@arrakis test-git-mirror-remotes]$ git add a
[ivan@arrakis test-git-mirror-remotes]$ git commit -m 'First.'
Created initial commit 68543c7: First.
 1 files changed, 1 insertions(+), 0 deletions(-)
 create mode 100644 a
[ivan@arrakis test-git-mirror-remotes]$ git tag first 
[ivan@arrakis test-git-mirror-remotes]$ mkdir ../test-git-mirror-remotes2
[ivan@arrakis test-git-mirror-remotes]$ pushd ../test-git-mirror-remotes2
~/test-git-mirror-remotes2 ~/test-git-mirror-remotes
[ivan@arrakis test-git-mirror-remotes2]$ git init
Initialized empty Git repository in .git/
[ivan@arrakis test-git-mirror-remotes2]$ popd
~/test-git-mirror-remotes
[ivan@arrakis test-git-mirror-remotes]$ git remote add copy ../test-git-mirror-remotes2
[ivan@arrakis test-git-mirror-remotes]$ git push copy --mirror --dry-run
To ../test-git-mirror-remotes2
 * [new branch]      master -> master
 * [new tag]         first -> first
[ivan@arrakis test-git-mirror-remotes]$ git push copy --mirror          
Counting objects: 3, done.      
Writing objects: 100% (3/3), 211 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To ../test-git-mirror-remotes2  
 * [new branch]      master -> master
 * [new tag]         first -> first
[ivan@arrakis test-git-mirror-remotes]$ git push copy --mirror --dry-run
To ../test-git-mirror-remotes2  
 * [new branch]      copy/master -> copy/master
[ivan@arrakis test-git-mirror-remotes]$ git-show-ref 
68543c7ae10df48460fcf0ff0fd7d58c1439e04b refs/heads/master
68543c7ae10df48460fcf0ff0fd7d58c1439e04b refs/remotes/copy/master
68543c7ae10df48460fcf0ff0fd7d58c1439e04b refs/tags/first
[ivan@arrakis test-git-mirror-remotes]$ git push copy --mirror          
Total 0 (delta 0), reused 0 (delta 0)
To ../test-git-mirror-remotes2
 * [new branch]      copy/master -> copy/master
[ivan@arrakis test-git-mirror-remotes]$ 

Expected behavior: refs/remotes/* are not sent.

Workaround: do not use "--mirror", use "refs/heads/*:refs/heads/* --tags" instead.
Comment 1 Ivan Zakharyaschev 2008-10-28 17:28:30 MSK
Another workaround: add

        push = refs/heads/*:refs/heads/*
        push = refs/tags/*:refs/tags/*

to the corresponding "remote" section in .git/config, if you want that "push" to that repositary by default acts as "push --mirror" should to (as described in the manpage).
Comment 2 Ivan Zakharyaschev 2008-11-18 02:25:33 MSK
(In reply to comment #0)

> Workaround: do not use "--mirror", use "refs/heads/*:refs/heads/* --tags" instead.
 
Amendment: use "+refs/heads/*:refs/heads/* --tags" instead.
Comment 3 Ivan Zakharyaschev 2008-11-18 02:27:30 MSK
(In reply to comment #0)
> git-core-1.5.5.5-alt1

> But the actual behavior is different: it sends *all* refs, including remotes. 

It's also true for git-core-1.5.6.5-alt2.
Comment 4 Ivan Zakharyaschev 2009-12-17 00:55:08 MSK
A discussion of this issue in the "git" list -- http://osdir.com/ml/git/2009-05/msg00701.html ; Junio Hamano:

"But these other people can say "git fetch $here remotes/origin/master"
 explicitly when fetching from this repository. By mirroring everything
 under refs/ to its --mirror backup repository, these other people can
 substitute $here with its --mirror backup repository and expect it to
 still work. It would be a regression if you stop pushing the refs/remotes
 hierarchy"
Comment 5 Ivan Zakharyaschev 2009-12-17 01:04:35 MSK
(В ответ на комментарий №2)

> > Workaround: do not use "--mirror", use "refs/heads/*:refs/heads/* --tags" instead.
> 
> Amendment: use "+refs/heads/*:refs/heads/* --tags" instead.

But this won't delete locally deleted refs at the remote repo. :(
Comment 6 Michael Shigorin 2014-11-05 20:41:03 MSK
В 4.1/branch исправления не будут вноситься уже технически (заглушена очередь на сборку), поэтому прошу ошибки, актуальные для sisyphus/p7/t7, перевесить на текущие ветки или сизиф.