Add feedback output to git hook init script.

This commit is contained in:
William Boman 2015-02-19 05:54:50 +01:00
parent 0bd6180a0b
commit 84626341be
2 changed files with 15 additions and 5 deletions

View file

@ -11,7 +11,8 @@
},
"author": "Ionică Bizău <bizauionica@gmail.com>",
"contributors": [
"Gnab <as0n@gnab.fr>"
"Gnab <as0n@gnab.fr>",
"William Boman <william@redwill.se>"
],
"license": "MIT",
"devDependencies": {},

View file

@ -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