Skip to content

Git <1.9 unable to fetch #9

@dergachev

Description

@dergachev

From #1 reported by @spydmobile

To reproduce note that git 1.7 and 1.8 fail in these steps:

docker run -ti ubuntu:precise bash

apt-get update; apt-get install vim git


git --version
#    git version 1.7.9.5

mkdir /git; cd /git
git init --bare vagrant-vbox-snapshot
git --git-dir vagrant-vbox-snapshot/  remote add --tags --mirror=fetch origin https://github.com/dergachev/vagrant-vbox-snapshot.git
git --git-dir vagrant-vbox-snapshot/ remote -v
#      origin   https://github.com/dergachev/vagrant-vbox-snapshot.git (fetch)
#      origin   https://github.com/dergachev/vagrant-vbox-snapshot.git (push)

git  --git-dir vagrant-vbox-snapshot/ fetch --all  --verbose
#    Fetching origin
#    POST git-upload-pack (374 bytes)
#    remote: Counting objects: 206, done.
#    remote: Compressing objects: 100% (94/94), done.
#    Receiving objects: 100% (206/206), 32.67 KiB, done.
#    remote: Total 206 (delta 113), reused 203 (delta 112)
#    Resolving deltas: 100% (113/113), done.
#    From https://github.com/dergachev/vagrant-vbox-snapshot
#     * [new tag]         v0.0.2     -> v0.0.2
#     * [new tag]         v0.0.3     -> v0.0.3
#     * [new tag]         v0.0.4     -> v0.0.4
#     * [new tag]         v0.0.5     -> v0.0.5
#     * [new tag]         v0.0.6     -> v0.0.6
#     * [new tag]         v0.0.7     -> v0.0.7

#NB: if there were no tags, then this would have simply said "Fetching origin" and done nothing.

git --git-dir vagrant-vbox-snapshot/ log
#    fatal: bad default revision 'HEAD'

In git 1.9 the git log succeeds.

The problem was in this line:

git --git-dir vagrant-vbox-snapshot/  remote add --tags --mirror=fetch origin git@bitbucket.org:alexdergachev/test.git

That --tags adds tagopt = --tags field to git.config.remote.origin, which causes git to append --tags to git fetch --all, causing only tags (if they exist) to be fetched, thus superseding the --all flag behaviour to fetch all branches and tags (which is what we want). Interestingly git 1.7 and 1.8 have this problem, while 1.9 (which I'm running) seems to give --all precedence.

Potentially relevant: http://git.661346.n2.nabble.com/unclear-documentation-of-git-fetch-tags-option-and-tagopt-config-td7572964.html

Because in our plugin we always use git fetch --all, it seems we can safely drop the --tags from the remote add line, and things should work.

So simply dropping --tags fixes the problem:

rm -Rf vagrant-vbox-snapshot/
git init --bare vagrant-vbox-snapshot
git --git-dir vagrant-vbox-snapshot/  remote add --mirror=fetch origin https://github.com/dergachev/vagrant-vbox-snapshot.git

git  --git-dir vagrant-vbox-snapshot/ fetch --all  --verbose
#     * [new branch]      master     -> master
#     * [new branch]      no-vagrant-dependency -> no-vagrant-dependency
#     * [new branch]      refs/pull/14/head -> refs/pull/14/head
#     * [new branch]      refs/pull/14/merge -> refs/pull/14/merge
#     * [new branch]      refs/pull/18/head -> refs/pull/18/head
#     * [new branch]      refs/pull/22/head -> refs/pull/22/head
#     * [new branch]      refs/pull/23/head -> refs/pull/23/head
#     * [new branch]      refs/pull/6/head -> refs/pull/6/head
#     * [new branch]      refs/pull/6/merge -> refs/pull/6/merge
#     * [new tag]         v0.0.2     -> v0.0.2
#     * [new tag]         v0.0.3     -> v0.0.3
#     * [new tag]         v0.0.4     -> v0.0.4
#     * [new tag]         v0.0.5     -> v0.0.5
#     * [new tag]         v0.0.6     -> v0.0.6
#     * [new tag]         v0.0.7     -> v0.0.7

git --git-dir vagrant-vbox-snapshot/ log
#    SUCCESS

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions