Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The hook installation in the readme clobbers existing hooks #41

Closed
ashleyblackmore opened this issue Mar 18, 2015 · 5 comments
Closed

Comments

@ashleyblackmore
Copy link

Running the command here clobbers any existing hooks:
curl -s https://raw.githubusercontent.com/IonicaBizau/git-stats/master/scripts/init-git-post-commit | bash

An improvement could be to make a note in the readme, or to modify the bash script to run append-only. Happy to make a PR for either.

@IonicaBizau
Copy link
Owner

Couldn't reproduce it:

ionicabizau@notebook:~$ cat .git-templates/hooks/post-commit 
#!/bin/sh

echo ">>>"

### git-stats hook (begin) ###
# Copy last commit hash to clipboard on commit
commit_hash=$(git rev-parse HEAD)
repo_url=$(git config --get remote.origin.url)
commit_date=$(git log -1 --format=%cd)
commit_data="\"{ \"date\": \"$commit_date\", \"url\": \"$repo_url\", \"hash\": \"$commit_hash\" }\""
git-stats --record "${commit_data}"
### git-stats hook (end) ###

echo ">>> 1"
ionicabizau@notebook:~$ curl -s https://raw.githubusercontent.com/IonicaBizau/git-stats/master/scripts/init-git-post-commit | bash
Setting up git-stats hooks.
Successfully set up git-stats hook at /home/ionicabizau/.git-templates/hooks/post-commit.
ionicabizau@notebook:~$ cat .git-templates/hooks/post-commit 
#!/bin/sh

echo ">>>"

echo ">>> 1"
### git-stats hook (begin) ###
# Copy last commit hash to clipboard on commit
commit_hash=$(git rev-parse HEAD)
repo_url=$(git config --get remote.origin.url)
commit_date=$(git log -1 --format=%cd)
commit_data="\"{ \"date\": \"$commit_date\", \"url\": \"$repo_url\", \"hash\": \"$commit_hash\" }\""
git-stats --record "${commit_data}"
### git-stats hook (end) ###

It's true that echo ">>> 1" went to top, but it was not removed. Can you describe your usecase?

@IonicaBizau
Copy link
Owner

/cc @ashleyblackmore

@ashleyblackmore
Copy link
Author

Sorry, I just got around to double-checking - I was wrong - I was looking in the wrong directory (.git-templates/hooks/, rather than .git/hooks/)

@ashleyblackmore
Copy link
Author

@IonicaBizau on a related note, I like the script, so I've adapted a bit of it for my own hook and credited you in the hook comment header. However, I decided to use sed instead of perl because it is a bit cleaner. I'm on linux (and it is really only a hook for linux users), so maybe sed is a better approach than perl in my case.

Anyway, an idea of what I mean:

sed '/### git-stats hook (begin) ###/,/### git-stats hook (end) ###/d' $post_commit_path > $post_commit_path

My hook is here if you want to look.

Thanks for the great hook, by the way!

@IonicaBizau
Copy link
Owner

@ashleyblackmore Nice! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants