summaryrefslogtreecommitdiffstats
path: root/init-repository
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@digia.com>2014-11-10 18:08:58 +0100
committerJani Heikkinen <jani.heikkinen@theqtcompany.com>2014-11-12 10:48:37 +0100
commitd5946d420f14ade23362a67188d80a5c95f66c0a (patch)
treed777765a9d6ba4eb47966f8f504c24d564c409e7 /init-repository
parente8053418e43127327f6df892ae774a1707a9ae97 (diff)
teach init-repository about branches
specifically, add the --branch option and the necessary keys to .gitmodules. Change-Id: I09e2df6bd012629f76a35238d66697637bdffe44 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'init-repository')
-rwxr-xr-xinit-repository33
1 files changed, 29 insertions, 4 deletions
diff --git a/init-repository b/init-repository
index 6a2d2f74..3fdfa83f 100755
--- a/init-repository
+++ b/init-repository
@@ -105,6 +105,12 @@ Module names may be prefixed with a dash to exclude them from a bigger set.
Skip the `git submodule update' command.
+=item --branch
+
+Instead of checking out specific SHA1s, check out the submodule branches that
+correspond with the current supermodule commit.
+By default, this option will cause local commits in the submodules to be rebased.
+With --no-update, the branches will be checked out, but their heads will not move.
=item --ignore-submodules
@@ -233,6 +239,7 @@ sub parse_arguments
%{$self} = (%{$self},
'alternates' => "",
+ 'branch' => 0,
'codereview-username' => "",
'detach-alternates' => 0 ,
'force' => 0 ,
@@ -246,6 +253,7 @@ sub parse_arguments
GetOptionsFromArray(\@args,
'alternates=s' => \$self->{qw{ alternates }},
+ 'branch' => \$self->{qw{ branch }},
'codereview-username=s' => \$self->{qw{ codereview-username }},
'copy-objects' => \$self->{qw{ detach-alternates }},
'force|f' => \$self->{qw{ force }},
@@ -313,9 +321,10 @@ sub git_submodule_init
sub git_clone_all_submodules
{
- my ($self, $my_repo_base, @subset) = @_;
+ my ($self, $my_repo_base, $co_branch, @subset) = @_;
my %subdirs = ();
+ my %subbranches = ();
my %subbases = ();
my %subinits = ();
my @submodconfig = qx(git config -l -f .gitmodules);
@@ -324,6 +333,8 @@ sub git_clone_all_submodules
next if ($line !~ /^submodule\.([^.=]+)\.([^.=]+)=(.*)$/);
if ($2 eq "path") {
$subdirs{$1} = $3;
+ } elsif ($2 eq "branch") {
+ $subbranches{$1} = $3;
} elsif ($2 eq "url") {
my ($mod, $base) = ($1, $3);
next if ($base !~ /^\.\.\//);
@@ -376,16 +387,30 @@ sub git_clone_all_submodules
}
if ($self->{update}) {
- $self->exe('git', 'submodule', 'update');
+ $self->exe('git', 'submodule', 'update', ($co_branch ? ('--remote', '--rebase') : ()));
foreach my $module (@modules) {
if (-f $module.'/.gitmodules') {
my $orig_cwd = getcwd();
chdir($module) or confess "chdir $module: $OS_ERROR";
- $self->git_clone_all_submodules($subbases{$module}, "all");
+ $self->git_clone_all_submodules($subbases{$module}, 0, "all");
chdir("$orig_cwd") or confess "chdir $orig_cwd: $OS_ERROR";
}
}
+ } elsif ($co_branch) {
+ foreach my $module (@modules) {
+ my $branch = $subbranches{$module};
+ die("No branch defined for submodule $module.\n") if (!defined($branch));
+ my $orig_cwd = getcwd();
+ chdir($module) or confess "chdir $module: $OS_ERROR";
+ my $br = qx(git rev-parse -q --verify $branch);
+ if (!$br) {
+ $self->exe('git', 'checkout', '-b', $branch, "origin/$branch");
+ } else {
+ $self->exe('git', 'checkout', $branch);
+ }
+ chdir("$orig_cwd") or confess "chdir $orig_cwd: $OS_ERROR";
+ }
}
return;
@@ -532,7 +557,7 @@ sub run
$url =~ s,qt/qt5$,,;
$self->{'base-url'} = $url;
- $self->git_clone_all_submodules('qt/qt5', @{$self->{'module-subset'}});
+ $self->git_clone_all_submodules('qt/qt5', $self->{branch}, @{$self->{'module-subset'}});
$self->git_add_remotes('qt/qt5');