diff options
author | Oswald Buddenhagen <oswald.buddenhagen@digia.com> | 2014-02-10 21:30:52 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-28 14:17:21 +0100 |
commit | 93726970012dd59ca66aa65f4a78c5401215db2b (patch) | |
tree | 74942dcfeefded8753f0b62dc7c6e9c9233c755c | |
parent | ed6175da93a16e2733c2dcc266761ba91f225ada (diff) |
automatically install hooks
Change-Id: I2fabc610dd69730cfdac45046d4bbc6f53822fc4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
-rwxr-xr-x | init-repository | 44 |
1 files changed, 43 insertions, 1 deletions
diff --git a/init-repository b/init-repository index 20b53d42..ed99139e 100755 --- a/init-repository +++ b/init-repository @@ -70,6 +70,12 @@ B<Global options:> Force initialization (even if the submodules are already checked out). +=item --force-hooks + +Force initialization of hooks (even if there are already hooks in checked out +submodules). + + =item --quiet, -q Be quiet. Will exit cleanly if the repository is already initialized. @@ -311,6 +317,7 @@ sub parse_arguments 'codereview-username' => "", 'detach-alternates' => 0 , 'force' => 0 , + 'force-hooks' => 0 , 'ignore-submodules' => 0 , 'mirror-url' => "", 'protocol' => "", @@ -323,7 +330,8 @@ sub parse_arguments 'alternates=s' => \$self->{qw{ alternates }}, 'codereview-username=s' => \$self->{qw{ codereview-username }}, 'copy-objects' => \$self->{qw{ detach-alternates }}, - 'force' => \$self->{qw{ force }}, + 'force|f' => \$self->{qw{ force }}, + 'force-hooks' => \$self->{qw{ force-hooks }}, 'ignore-submodules' => \$self->{qw{ ignore-submodules }}, 'mirror=s' => \$self->{qw{ mirror-url }}, 'quiet' => \$self->{qw{ quiet }}, @@ -575,6 +583,38 @@ sub git_clone_one_submodule return; } +sub ensure_link +{ + my ($self, $src, $tgt) = @_; + return if (!$self->{'force-hooks'} and -f $tgt); + unlink($tgt); # In case we have a dead symlink or pre-existing hook + print "Aliasing $src\n as $tgt ...\n" if (!$self->{quiet}); + return if eval { symlink($src, $tgt) }; + # Windows doesn't do (proper) symlinks. As the post_commit script needs + # them to locate itself, we write a forwarding script instead. + open SCRIPT, ">".$tgt or die "Cannot create forwarding script $tgt: $!\n"; + print SCRIPT "#!/bin/sh\nexec `dirname \$0`/$src \"\$\@\"\n"; + close SCRIPT; +} + +sub git_install_hooks +{ + my ($self) = @_; + + return if (!-d 'qtrepotools/git-hooks'); + + chomp(my @modules = `git submodule foreach :`); + push @modules, ""; + for my $module (@modules) { + $module =~ s,^Entering \'([^\']+)\'$,$1/,; + my $rel = $module; + $rel =~ s,[^/]+,..,g; + $rel .= "../../qtrepotools/git-hooks/"; + $self->ensure_link($rel.'gerrit_commit_msg_hook', $module.'.git/hooks/commit-msg'); + $self->ensure_link($rel.'git_post_commit_hook', $module.'.git/hooks/post-commit'); + } +} + sub run { my ($self) = @_; @@ -596,6 +636,8 @@ sub run $self->git_add_remotes('qt5'); + $self->git_install_hooks; + return; } |