From 0481e076f3cb4010894324cac71e947c6637805a Mon Sep 17 00:00:00 2001 From: Herbert Valerio Riedel Date: Sat, 28 Sep 2013 10:15:21 +0200 Subject: Teach sync-all how to rewrite submodule repo urls This applies attachment:sync-all-submodules-locally.diff from #8369 Authored-by: Nathaniel Filardo Signed-off-by: Herbert Valerio Riedel --- sync-all | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'sync-all') diff --git a/sync-all b/sync-all index 1124524141..2789667e8b 100755 --- a/sync-all +++ b/sync-all @@ -176,6 +176,7 @@ sub getrepo { my $repo_base; my $checked_out_tree; + my $repo_local = 0; if ($repo =~ /^...*:/) { # HTTP or SSH @@ -206,6 +207,7 @@ sub getrepo { } elsif ($repo =~ /^\/|\.\.\/|.:(\/|\\)/) { # Local filesystem, either absolute (C:/ or /) or relative (../) path + $repo_local = 1; $repo_base = $repo; if (-f "$repo/HEAD") { # assume a local mirror: @@ -223,7 +225,7 @@ sub getrepo { die "Couldn't work out repo"; } - return $repo_base, $checked_out_tree; + return $repo_base, $checked_out_tree, $repo_local; } sub gitall { @@ -244,7 +246,7 @@ sub gitall { my $doing; my $start_repo; - my ($repo_base, $checked_out_tree) = getrepo(); + my ($repo_base, $checked_out_tree, $repo_local) = getrepo(); my $is_github_repo = $repo_base =~ m/(git@|git:\/\/|https:\/\/)github.com/; @@ -561,6 +563,22 @@ sub gitall { unlink "resume"; } +sub gitInitSubmodules { + &git(".", "submodule", "init", @_); + + my ($repo_base, $checked_out_tree, $repo_local) = getrepo(); + # if we came from a local repository, grab our submodules from their + # checkouts over there, if they exist. + if ($repo_local) { + my $gitConfig = &tryReadFile(".git/config"); + foreach $_ (split /^/, $gitConfig) { + if ($_ =~ /^\[submodule "(.*)"\]$/ and -e "$repo_base/$1/.git") { + &git(".", "config", "submodule.$1.url", "$repo_base/$1"); + } + } + } +} + sub checkCurrentBranchIsMaster { my $branch = `git symbolic-ref HEAD`; $branch =~ s/refs\/heads\///; @@ -892,18 +910,19 @@ sub main { my @submodule_args = grep(/^-q/,@_); if ($command eq "get") { - &git(".", "submodule", "init", @submodule_args); + &gitInitSubmodules(@submodule_args); } + if ($command eq "pull") { my $gitConfig = &tryReadFile(".git/config"); if ($gitConfig !~ /submodule/) { - &git(".", "submodule", "init", @submodule_args); + &gitInitSubmodules(@submodule_args); } } if ($command eq "get" or $command eq "pull") { my $gitConfig = &tryReadFile(".git/config"); if ($gitConfig !~ /submodule/) { - &git(".", "submodule", "init", @submodule_args); + &gitInitSubmodules(@submodule_args); } &git(".", "submodule", "update", @submodule_args); } -- cgit v1.2.1