Skip to content

Commit bd763d8

Browse files
committed
Remove any previous git-stats code blocks in pre-existing git hook files.
1 parent 2ca918f commit bd763d8

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

scripts/init-git-post-commit

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ post_commit_path="${git_hooks_dir}/post-commit"
2222
mkdir -p "$git_hooks_dir"
2323

2424
hook=$(cat <<EOF
25-
2625
### git-stats hook (begin) ###
2726
# Copy last commit hash to clipboard on commit
2827
commit_hash=\$(git rev-parse HEAD)
2928
repo_url=\$(git config --get remote.origin.url)
3029
commit_date=\$(git log -1 --format=%cd)
3130
commit_data="\"{ \"date\": \"\$commit_date\", \"url\": \"\$repo_url\", \"hash\": \"\$commit_hash\" }\""
32-
git-stats --record "\$commit_data"
31+
git-stats --record "\${commit_data}"
3332
### git-stats hook (end) ###
3433
EOF
3534
);
@@ -40,6 +39,8 @@ if [ ! -f "$post_commit_path" ]; then
4039
&& echo "Successfully set up git-stats hook at ${post_commit_path}." \
4140
&& exit 0
4241
else
42+
# Remove any previous git-stats hook code blocks
43+
perl -i -0pe 's/(([ \t]*# Copy last commit hash to clipboard on commit\s*(\n.*){5}\s*git-stats --record "\$commit_data"\s*)|([ \t]*### git-stats hook \(begin\) ###\s*(\n.*){7}\s*### git-stats hook \(end\) ###\s*))//g' "$post_commit_path"
4344
printf "\n%s\n" "$hook" >> "$post_commit_path" \
4445
&& echo "Successfully set up git-stats hook at ${post_commit_path}." \
4546
&& exit 0

0 commit comments

Comments
 (0)