From 9443890d60388f27f04b5a87013ca76f9afcc225 Mon Sep 17 00:00:00 2001 From: Ilia Kirianovskii Date: Thu, 12 May 2016 10:04:57 +0300 Subject: Fix git_install_hooks for relative gitdir Previously we expected gitdir to be always absolute. This patch fixes git_install_hooks in case of relative gitdir. Change-Id: Ia0883af18229703aaa22c62fd2181ed56d9f2fce Reviewed-by: Oswald Buddenhagen --- init-repository | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'init-repository') diff --git a/init-repository b/init-repository index 2580b0f6..954237d0 100755 --- a/init-repository +++ b/init-repository @@ -155,9 +155,10 @@ EOF } use Carp qw( confess ); +use Cwd qw( getcwd abs_path ); use English qw( -no_match_vars ); +use File::Spec::Functions qw ( rel2abs ); use Getopt::Long qw( GetOptions ); -use Cwd qw( getcwd abs_path ); my $script_path = abs_path($0); $script_path =~ s,[/\\][^/\\]+$,,; @@ -558,24 +559,25 @@ sub git_install_hooks my @configresult = qx(git config --list --local); foreach my $line (@configresult) { next if ($line !~ /submodule\.([^.=]+)\.url=/); - my $module = $1.'/.git'; - if (!-d $module) { - open GITD, $module or die "Cannot open $module: $!\n"; + my $module = $1; + my $module_gitdir = $module.'/.git'; + if (!-d $module_gitdir) { + open GITD, $module_gitdir or die "Cannot open $module: $!\n"; my $gd = ; close GITD; chomp($gd); - $gd =~ s/^gitdir: // or die "Malformed .git file $module\n"; - $module = $gd; # We expect it to be always absolute. - if (open COMD, $module.'/commondir') { + $gd =~ s/^gitdir: // or die "Malformed .git file $module_gitdir\n"; + $module_gitdir = rel2abs($gd, $module); + if (open COMD, $module_gitdir.'/commondir') { my $cd = ; chomp($cd); - $module .= '/'.$cd; - $module = abs_path($module); + $module_gitdir .= '/'.$cd; + $module_gitdir = abs_path($module_gitdir); close COMD; } } - $self->ensure_link($hooks.'/gerrit_commit_msg_hook', $module.'/hooks/commit-msg'); - $self->ensure_link($hooks.'/git_post_commit_hook', $module.'/hooks/post-commit'); + $self->ensure_link($hooks.'/gerrit_commit_msg_hook', $module_gitdir.'/hooks/commit-msg'); + $self->ensure_link($hooks.'/git_post_commit_hook', $module_gitdir.'/hooks/post-commit'); } } -- cgit v1.2.3