Added comments

This commit is contained in:
Ionică Bizău 2015-02-19 15:33:29 +02:00
parent dea9adc440
commit 93be56019c

View File

@ -2,17 +2,21 @@
echo "Setting up git-stats hooks."; echo "Setting up git-stats hooks.";
# Create a new global templatedir if there are none
git_templates_dir=$(git config --global --get init.templatedir); git_templates_dir=$(git config --global --get init.templatedir);
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
# Create a new global templatedir if there are none git_templates_dir="${HOME}/.git-templates"
git_templates_dir="${HOME}/.git-templates" git config --global init.templatedir "$git_templates_dir"
git config --global init.templatedir "$git_templates_dir"
fi fi
# Prepare some path variables
git_hooks_dir="${git_templates_dir}/hooks" git_hooks_dir="${git_templates_dir}/hooks"
post_commit_path="${git_hooks_dir}/post-commit" post_commit_path="${git_hooks_dir}/post-commit"
# Create the hook directory
mkdir -p "$git_hooks_dir" mkdir -p "$git_hooks_dir"
# Create the post-commit file content
hook=$(cat <<EOF hook=$(cat <<EOF
### git-stats hook (begin) ### ### git-stats hook (begin) ###
@ -26,15 +30,16 @@ git-stats --record "\$commit_data"
EOF EOF
); );
# Does post-commit file exist?
if [ ! -f "$post_commit_path" ]; then if [ ! -f "$post_commit_path" ]; then
printf "#!/bin/sh\n%s" "$hook" > "$post_commit_path" \ printf "#!/bin/sh\n%s" "$hook" > "$post_commit_path" \
&& chmod +x "$post_commit_path" \ && chmod +x "$post_commit_path" \
&& echo "Successfully set up git-stats hook at ${post_commit_path}." \ && echo "Successfully set up git-stats hook at ${post_commit_path}." \
&& exit 0 && exit 0
else 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}." \ && echo "Successfully set up git-stats hook at ${post_commit_path}." \
&& exit 0 && exit 0
fi fi
echo "Couldn't set up git-stats hook." echo "Couldn't set up git-stats hook."