Last active
August 25, 2017 11:25
-
-
Save WimObiwan/c5f42c91a6735e9559a482f8cd3466f1 to your computer and use it in GitHub Desktop.
Hooks to automerge (fix) branches
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 | |
# Put in directory .git/hooks | |
branch=$(git rev-parse --abbrev-ref --quiet HEAD) | |
echo "Running automerge for branch $branch" | |
config_automergeto="branch.$branch.automergeto" | |
automergeto=$(git config $config_automergeto) | |
if [ -n "$automergeto" ]; then | |
echo "Auto merge to these branches: $automergeto" | |
for automergeto_branch in $automergeto | |
do | |
echo '*******************************************************************************' | |
echo "** Auto merging from $branch to $automergeto_branch" | |
git checkout $automergeto_branch && git pull --ff-only && git merge $branch | |
if [[ $? != 0 ]]; then | |
echo "** AUTOMERGE from $branch to $automergeto_branch FAILED !!!" | |
git merge --abort | |
fi | |
echo '*******************************************************************************' | |
done | |
git checkout $branch | |
else | |
echo "Automerge disabled (no config value for $config_automergeto)" | |
fi |
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 | |
# Explanation | |
# | |
# 1/ Put the 3 scripts (2 hooks) in .git/hooks of your repository | |
# 2/ Adjust .git/config to set merge targets: | |
# e.g. | |
# | |
# [branch "fix-MyFixBranch"] | |
# remote = origin | |
# merge = refs/heads/fix-MyFixBranch | |
# automergeto = MyReleaseBranch master | |
# | |
# (the last line is needs to be added) | |
# | |
# This also works recusively (when merge target is again configured to merge through to other branches). | |
# Tested with command line & GIT Extensions. |
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 | |
# Put in directory .git/hooks | |
echo 'Begin executing post-commit hook' | |
./.git/hooks/automerge | |
echo 'Done executing post-commit hook' |
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 | |
# Put in directory .git/hooks | |
echo 'Begin executing post-merge hook' | |
./.git/hooks/automerge | |
echo 'Done executing post-merge hook' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment