From 85cc31c77134d78d3ff3ca2fd2229d0e5b791530 Mon Sep 17 00:00:00 2001 From: Sitaram Chamarty Date: Fri, 5 Feb 2010 06:49:07 +0530 Subject: [PATCH] install/pm: turn hooks from copies to symlinks --- src/gitolite.pm | 14 +++++++++++++- src/gl-install | 6 ++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/gitolite.pm b/src/gitolite.pm index a6dba92..9f2193f 100644 --- a/src/gitolite.pm +++ b/src/gitolite.pm @@ -78,6 +78,18 @@ sub check_ref { die "$perm $ref $repo $ENV{GL_USER} DENIED by fallthru\n"; } +# ln -sf :-) +sub ln_sf +{ + my($srcdir, $glob, $dstdir) = @_; + for my $hook ( glob("$srcdir/$glob") ) { + $hook =~ s/$srcdir\///; + unlink "$dstdir/$hook"; + symlink "$srcdir/$hook", "$dstdir/$hook" or die "could not symlink $hook\n"; + } +} + + # ---------------------------------------------------------------------------- # where is the rc file hiding? # ---------------------------------------------------------------------------- @@ -124,7 +136,7 @@ sub new_repo wrap_chdir("$repo.git"); system("git --bare init >&2"); # propagate our own, plus any local admin-defined, hooks - system("cp $hooks_dir/* hooks/"); + ln_sf($hooks_dir, "*", "hooks"); chmod 0755, "hooks/update"; } diff --git a/src/gl-install b/src/gl-install index 9494fc6..9159ed5 100755 --- a/src/gl-install +++ b/src/gl-install @@ -71,14 +71,16 @@ chdir("$repo_base_abs") or die "chdir $repo_base_abs failed: $!\n"; for my $repo (`find . -type d -name "*.git"`) { chomp ($repo); # propagate our own, plus any local admin-defined, hooks - system("cp $GL_ADMINDIR/src/hooks/* $repo/hooks/"); + ln_sf("$GL_ADMINDIR/src/hooks", "*", "$repo/hooks"); chmod 0755, "$repo/hooks/update"; } # oh and one of those repos is a bit more special and has an extra hook :) if ( -d "gitolite-admin.git/hooks" ) { print "copying post-update hook to gitolite-admin repo...\n"; - system("cp $GL_ADMINDIR/src/ga-post-update-hook gitolite-admin.git/hooks/post-update"); + unlink "gitolite-admin.git/hooks/post-update"; + symlink "$GL_ADMINDIR/src/ga-post-update-hook", "gitolite-admin.git/hooks/post-update" + or die "could not symlink post-update hook\n"; chmod 0755, "gitolite-admin.git/hooks/post-update"; }