Created
March 16, 2019 20:27
-
-
Save maxijonson/a1470f10d0af78effcf74842780b095b to your computer and use it in GitHub Desktop.
git post-commit hook to work with Heroku, Github and sensitive files
This file contains 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 | |
# After each commit on master (Heroku), it will switch to the Github branch and cherry-pick that commit into it. Then, switch back to master. | |
# This makes the committing flow seamless so all you have to do is push (which is safer done manually than with a hook) | |
# IMPORTANT: ANY changes in sensitive files should be commited alone (without public changes) or the sensitive files will be cherry picked in the public branch | |
# To skip this cherry-picking procedure (when you add a sensitive commit), start the commit message with "NCP" e.g.: "NCP Add some secret stuff" | |
ERR='\e[31m' | |
SUCCESS='\e[32m' | |
WARN='\e[33m' | |
space="\n\n\n" | |
branch=`git branch | grep \* | cut -d ' ' -f2` | |
heroku="master" # private branch | |
github="Github" # public branch | |
if [ "$branch" = $heroku ] | |
then | |
echo -e $space | |
message=`git log -1 --pretty=%B` | |
if [[ $message = NCP* ]]; then | |
echo -e "${WARN}NOT cherry-picking (commit message starts with 'NCP') $space" | |
exit 0; | |
fi | |
echo -e "${WARN}Executing post-commit script (cherry-pick)..." | |
commitID=`git rev-parse HEAD` | |
if git checkout $github; then | |
if git cherry-pick $commitID; then | |
echo -e "${SUCCESS}Cherry picked $commitID into $github branch $space" | |
if ! git checkout $heroku; then | |
echo -e "${ERR}Couldn't checout to $heroku $space" | |
exit 1 | |
fi | |
else | |
echo -e "${ERR}Failed to cherry pick $commitID into $github branch. Do it manually $space" | |
exit 1 | |
fi | |
else | |
echo -e "${ERR}Couldn't checkout to $github $space" | |
exit 1 | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment