Created
January 17, 2013 17:45
-
-
Save zgohr/4557894 to your computer and use it in GitHub Desktop.
Post-checkout git hook to auto-add a commit when new branch is created from ```develop```. Useful because ```reflog``` doesn't stay around forever, and we don't want to hold onto defunct feature branches until we are able to run reports. There is an existing flaw in this code, can you spot it?
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 | |
| from_hash=$1 | |
| to_hash=$2 | |
| checkout_type=$3 | |
| ignored=("develop" "staging" "production") | |
| develop_hash=$(git rev-parse develop) | |
| branch_name=$(git rev-parse --abbrev-ref HEAD) | |
| containsElement () { | |
| local e | |
| for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done | |
| return 1 | |
| } | |
| if [ $checkout_type -ne 1 ] | |
| then | |
| exit 0 ; # Not a branch checkout | |
| fi | |
| if containsElement $branch_name "${ignored[@]}" | |
| then | |
| exit 0 ; # Checked out an ignored branch | |
| fi | |
| if [ $to_hash != $develop_hash ] | |
| then | |
| exit 0 ; # Must checkout branch at same commit as develop | |
| fi | |
| if [ $from_hash != $to_hash ] | |
| then | |
| exit 0 ; # Not checking out a new branch | |
| fi | |
| # Create a commit | |
| git commit --allow-empty -m "Created branch $branch_name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
looks interesting. I don't see a license in the repo, is the scripts free to use?
https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/licensing-a-repository#choosing-the-right-license