-
Notifications
You must be signed in to change notification settings - Fork 1
Githooks
nare06 edited this page Oct 15, 2015
·
1 revision
Its always a boring thing to create a change log file for the branch in unreleased_changes. Here is a git hook for the same. Just create a file in
.git/hooks/post-checkout
and paste the following content in the same.
#!/bin/sh
# This is a git hook for unreleased changes file creation. Whenever you switch to any branch. If unreleased changes don't have change log file for that branch. This hook will create one for you and copy the sample content to it. Release and master will not have unreleased_changes file
# --- Command line
branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
if [ "$branch" == "release" ]; then
echo "Woohoo.. Seems like new code is going live. :)"
elif [ "$branch" == "master" ]; then
echo "Starting a new feature? Create a branch :)"
elif [ ! -f "$PWD/unreleased_changes/$branch.md" ]; then
echo "UnReleased Changes File not found! Creating One from Sample"
cp "$PWD/unreleased_changes/sample_example.md" "$PWD/unreleased_changes/$branch.md"
fi
Give executable permissions to your hook.
chmod +x .git/hooks/post-checkout
Its always a pain to bundle install or rake db:migrate or rake data:migrate after merging a branch. Its better to automate this thing using git hooks. Here is the git hooks for the same. Just create a file ie:
.git/hooks/post-merge
and paste the following content in the same.
#!/bin/bash
if [ ! -z `git diff --name-only HEAD@{1}..HEAD Gemfile` ]
then
echo -e "\033[0;31m*** Gemfile change detected, running bundle install ***\033[0m"
bundle install
fi
if [ ! -z `git diff --name-only HEAD@{1}..HEAD db/migrate` ]
then
echo -e "\033[0;31m*** Migration changes detected, running rake db:migrate ***\033[0m"
rake db:migrate
fi
if [ ! -z `git diff --name-only HEAD@{1}..HEAD db/data` ]
then
echo -e "\033[0;31m*** Data Migration changes detected, running rake data:migrate ***\033[0m"
rake data:migrate
fi
Give executable permissions to your hook.
chmod +x .git/hooks/post-merge
#!/bin/sh
# Check to see if we are on master branch. Stop accidental commits
if [ $(git symbolic-ref HEAD 2>/dev/null) == "refs/heads/master" ]
then
echo "Cannot commit to master branch"
exit 1
fi
exit 0
Refer this and setup this one https://github.com/mohitjain/githooks