mirror of
https://github.com/IonicaBizau/git-stats.git
synced 2025-01-03 10:22:11 +01:00
Remove any previous git-stats code blocks in pre-existing git hook files.
This commit is contained in:
parent
2ca918fd2f
commit
bd763d8fe8
1 changed files with 3 additions and 2 deletions
|
@ -22,14 +22,13 @@ post_commit_path="${git_hooks_dir}/post-commit"
|
||||||
mkdir -p "$git_hooks_dir"
|
mkdir -p "$git_hooks_dir"
|
||||||
|
|
||||||
hook=$(cat <<EOF
|
hook=$(cat <<EOF
|
||||||
|
|
||||||
### git-stats hook (begin) ###
|
### git-stats hook (begin) ###
|
||||||
# Copy last commit hash to clipboard on commit
|
# Copy last commit hash to clipboard on commit
|
||||||
commit_hash=\$(git rev-parse HEAD)
|
commit_hash=\$(git rev-parse HEAD)
|
||||||
repo_url=\$(git config --get remote.origin.url)
|
repo_url=\$(git config --get remote.origin.url)
|
||||||
commit_date=\$(git log -1 --format=%cd)
|
commit_date=\$(git log -1 --format=%cd)
|
||||||
commit_data="\"{ \"date\": \"\$commit_date\", \"url\": \"\$repo_url\", \"hash\": \"\$commit_hash\" }\""
|
commit_data="\"{ \"date\": \"\$commit_date\", \"url\": \"\$repo_url\", \"hash\": \"\$commit_hash\" }\""
|
||||||
git-stats --record "\$commit_data"
|
git-stats --record "\${commit_data}"
|
||||||
### git-stats hook (end) ###
|
### git-stats hook (end) ###
|
||||||
EOF
|
EOF
|
||||||
);
|
);
|
||||||
|
@ -40,6 +39,8 @@ if [ ! -f "$post_commit_path" ]; then
|
||||||
&& 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
|
||||||
|
# Remove any previous git-stats hook code blocks
|
||||||
|
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"
|
||||||
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
|
||||||
|
|
Loading…
Reference in a new issue