From 85e92c7d5974d6a590607510f1262104bef7ea79 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Mon, 17 Nov 2014 08:59:40 -0800 Subject: [PATCH] hooks: make sure hooks directory exists before writing hooks Although unlikely, if the template directory that Git uses to copy the initial hooks from does not exist or is empty then Git will never create a hooks subdirectory in newly initialized .git directories. Since we copy in several hooks that would cause our copies to fail. Instead create the hooks directory if it does not already exist before attempting to write any hooks. --- Girocco/Project.pm | 3 +++ toolbox/update-all-hooks.sh | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Girocco/Project.pm b/Girocco/Project.pm index 37a8422..8920993 100644 --- a/Girocco/Project.pm +++ b/Girocco/Project.pm @@ -315,6 +315,9 @@ sub _hook_path { sub _hook_install { my $self = shift; my ($name) = @_; + my $hooksdir = $self->{path}.'/hooks'; + -d $hooksdir or mkdir $hooksdir or + die "hooks directory does not exist and unable to create it for project " . $self->{name} . ": $!"; open SRC, '<', "$Girocco::Config::basedir/hooks/$name" or die "cannot open hook $name: $!"; open DST, '>', $self->_hook_path($name) or die "cannot open hook $name for writing: $!"; while () { print DST $_; } diff --git a/toolbox/update-all-hooks.sh b/toolbox/update-all-hooks.sh index 20540bd..173b177 100755 --- a/toolbox/update-all-hooks.sh +++ b/toolbox/update-all-hooks.sh @@ -19,7 +19,8 @@ cut -d : -f 1 < "$cfg_chroot/etc/group" | grep -v _repo | \ cat "$hookbin/$hook" > "$projdir/hooks/$hook" updates="$updates $hook" fi - elif [ -d "$projdir/hooks" -a ! -e "$projdir/hooks/$hook" ]; then + elif [ ! -e "$projdir/hooks/$hook" ]; then + [ -d "$projdir/hooks" ] || mkdir "$projdir/hooks" cat "$hookbin/$hook" > "$projdir/hooks/$hook" chmod 0775 "$projdir/hooks/$hook" updates="$updates +$hook" -- 2.11.4.GIT