From 84626341beec9c2b4407ca87929181b25b7e7a65 Mon Sep 17 00:00:00 2001 From: William Boman Date: Thu, 19 Feb 2015 05:54:50 +0100 Subject: [PATCH 1/4] Add feedback output to git hook init script. --- package.json | 3 ++- scripts/init-git-post-commit | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index eb54986..bb35516 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ }, "author": "Ionică Bizău ", "contributors": [ - "Gnab " + "Gnab ", + "William Boman " ], "license": "MIT", "devDependencies": {}, diff --git a/scripts/init-git-post-commit b/scripts/init-git-post-commit index ebf3d9e..428cd2c 100755 --- a/scripts/init-git-post-commit +++ b/scripts/init-git-post-commit @@ -1,10 +1,12 @@ #!/bin/sh +echo "Setting up git-stats hooks."; + git_templates_dir=$(git config --global --get init.templatedir); if [ $? -ne 0 ]; then # Create a new global templatedir if there are none git_templates_dir="${HOME}/.git-templates" - git config --global init.templatedir "$git_templates_dir" + git config --global init.templatedir "$git_templates_dir" && echo "Set new global git template dir at ${git_templates_dir}" fi git_hooks_dir="${git_templates_dir}/hooks" post_commit_path="${git_hooks_dir}/post-commit" @@ -25,8 +27,15 @@ EOF ); if [ ! -f "$post_commit_path" ]; then - printf "#!/bin/sh\n%s" "$hook" > "$post_commit_path" - chmod +x "$post_commit_path" + printf "#!/bin/sh\n%s" "$hook" > "$post_commit_path" \ + && chmod +x "$post_commit_path" \ + && echo "Successfully set up git-stats hook at ${post_commit_path}." \ + && exit 0 else - printf "\n%s\n" "$hook" >> "$post_commit_path" + printf "\n%s\n" "$hook" >> "$post_commit_path" \ + && echo "Successfully set up git-stats hook at ${post_commit_path}." \ + && exit 0 fi + +echo "Couldn't set up git-stats hook." +exit 1 From 3800e2487063f9e4f53282eaa4f80ada8787e257 Mon Sep 17 00:00:00 2001 From: William Boman Date: Fri, 20 Feb 2015 00:11:36 +0100 Subject: [PATCH 2/4] Don't use backticks. --- scripts/init-git-post-commit | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/init-git-post-commit b/scripts/init-git-post-commit index 428cd2c..a174581 100755 --- a/scripts/init-git-post-commit +++ b/scripts/init-git-post-commit @@ -17,9 +17,9 @@ hook=$(cat < Date: Fri, 20 Feb 2015 00:12:55 +0100 Subject: [PATCH 3/4] Now ensures the user has required binaries before trying to set git hook. --- scripts/init-git-post-commit | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/init-git-post-commit b/scripts/init-git-post-commit index a174581..8345dec 100755 --- a/scripts/init-git-post-commit +++ b/scripts/init-git-post-commit @@ -1,5 +1,13 @@ #!/bin/sh +check_command() { + command -v "$1" > /dev/null 2>&1 || { echo "git-stats hook script requires the \`${1}\` binary in order to run." >&2; exit 1; } +} + +check_command "perl" +check_command "printf" +check_command "git" + echo "Setting up git-stats hooks."; git_templates_dir=$(git config --global --get init.templatedir); From bd763d8fe832771ab225653255e93008d5e78097 Mon Sep 17 00:00:00 2001 From: William Boman Date: Fri, 20 Feb 2015 00:57:46 +0100 Subject: [PATCH 4/4] Remove any previous git-stats code blocks in pre-existing git hook files. --- scripts/init-git-post-commit | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/scripts/init-git-post-commit b/scripts/init-git-post-commit index 8345dec..a21d6c2 100755 --- a/scripts/init-git-post-commit +++ b/scripts/init-git-post-commit @@ -22,14 +22,13 @@ post_commit_path="${git_hooks_dir}/post-commit" mkdir -p "$git_hooks_dir" hook=$(cat <> "$post_commit_path" \ && echo "Successfully set up git-stats hook at ${post_commit_path}." \ && exit 0