Skip to content

Commit

Permalink
feat(install): Add install script and move hooks
Browse files Browse the repository at this point in the history
Move hooks to a directory only containing executable hooks.  Install
script verifies the project to symlink hooks to.

Closes: #1
  • Loading branch information
Derek Michael Frank committed Jul 17, 2016
1 parent a0a2f35 commit 2417c70
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
File renamed without changes.
File renamed without changes.
48 changes: 48 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/bin/sh

cd "$(dirname $0)"

githooks="$PWD"
# Ignore githook repository.
project="$(dirname "$githooks")"
found=false
while [ "$found" = false ] && [ "$project" != '/' ]; do
# Can only connect to root of a git project.
if stat "$project/.git" >/dev/null 2>&1; then
echo "Link githooks to project '$(basename $project)'?"
select ans in 'yes' 'no' 'cancel'; do
case $ans in
yes )
found=true
break;;
no )
project="$(dirname "$project")"
break;;
cancel )
echo 'Canceled!'
exit 1
break;;
* )
echo 'Please select the number of your answer.'
echo
break;;
esac
done
else
project="$(dirname "$project")"
fi
done

if [ "$project" = '/' ]; then
echo 'No more projects to try!'
exit 1
fi

cd "$project/.git/hooks"
for hook in $githooks/hooks/* ; do
# Create relative symlinks.
hook="${hook/$project/../..}"
if [ -x "$hook" ]; then
ln -s "$hook" "$(basename "$hook")"
fi
done

0 comments on commit 2417c70

Please sign in to comment.