From 1ad0a17fa0068e5df8d0ccea2100936c583bc11e Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Wed, 4 Feb 2015 21:20:06 +0100 Subject: make manual fetching sane it is in no way said that the remote's HEAD will contain the commit to be checked out - in fact, it's pretty much guaranteed that it won't for anything but the default branch. fetching the whole remote avoids additional roundtrips and makes the --branch feature actually work reasonably. Change-Id: I20de2da848b12aea8c5b2784307fe9860252009b Reviewed-by: Simon Hausmann --- init-repository | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'init-repository') diff --git a/init-repository b/init-repository index b586110b..c6dd29b4 100755 --- a/init-repository +++ b/init-repository @@ -482,14 +482,23 @@ sub git_clone_one_submodule my $orig_cwd = getcwd(); chdir($submodule) or confess "chdir $submodule: $OS_ERROR"; - $self->exe('git', 'config', 'remote.origin.url', $url); if ($mirror) { + # This is only for the user's convenience - we make no use of it. $self->exe('git', 'config', 'remote.mirror.url', $mirror); $self->exe('git', 'config', 'remote.mirror.fetch', '+refs/heads/*:refs/remotes/mirror/*'); } if (!$do_clone && $self->{update}) { - $self->exe('git', 'fetch', ($mirror ? $mirror : $url)); + # If we didn't clone, fetch from the right location. We always update + # the origin remote, so that submodule update --remote works. + $self->exe('git', 'config', 'remote.origin.url', ($mirror ? $mirror : $url)); + $self->exe('git', 'fetch', 'origin'); + } + + if (!($do_clone || $self->{update}) || $mirror) { + # Leave the origin configured to the canonical URL. It's already correct + # if we cloned/fetched without a mirror; otherwise it may be anything. + $self->exe('git', 'config', 'remote.origin.url', $url); } my $template = getcwd()."/../.commit-template"; -- cgit v1.2.3