Created
June 24, 2015 21:01
-
-
Save spazm/877133497646fc7716c4 to your computer and use it in GitHub Desktop.
.git/hooks/post-checkout for logging branch changes. Will mine this to see what sort of frecency map would be useful for finding "hot" branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
previous_head_ref=$1 | |
new_head_ref=$2 | |
is_branch_checkout=$3 | |
if [[ "$previous_head_ref" != "$new_head_ref" ]] && [[ "$is_branch_checkout" == 1 ]]; then | |
branch=$(git rev-parse --abbrev-ref HEAD) | |
#if [[ "develop" != "$branch" ]]; then | |
path="$(dirname "$0")/.." | |
logfile="$path/x_branch_log" | |
ts=$(date +%s) | |
echo "$branch|1|$ts" >> $logfile | |
#fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
post-checkout hook provides the raw SHA1 for previous_head and current_head. At first I tried to turn those back into branch names, but that was error-prone (could be the tip of multiple branches). But then realized I could get the branch info from the new branch via rev-parse, since post-checkout runs after the checkout is complete (by definition).
git rev-parse --abbrev-ref HEAD
is the preferred way to get the current branch using git plumbing.