Created
May 10, 2018 14:54
-
-
Save fffx/303df2aa20d946eecc20070d1fef2d82 to your computer and use it in GitHub Desktop.
git hook
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
#!/usr/bin/env bash | |
#!/bin/bash -xv # puts this line in the beginning for debug | |
# This hook, auto checkout related repo to corresponding branch | |
# Current branch | |
branch=$(git symbolic-ref --short HEAD) | |
# Dependended repos | |
repos=(dependened_repo_a dependened_repo_b) | |
working_dir=$(git rev-parse --show-toplevel) | |
# Check out policy | |
# Determine target branch | |
if [[ $branch =~ ^test ]]; then | |
target_branch="test" | |
elif [[ $branch =~ ^master ]]; then | |
target_branch="master" | |
elif [[ $branch =~ ^hotfix ]]; then | |
target_branch="release" | |
elif [[ $branch =~ ^release ]]; then | |
target_branch="release" | |
#else | |
# taeget_branch="master" | |
fi | |
# Exit if target_branch not set | |
# if you don't have a default target_branch | |
if [ -z ${target_branch+x} ]; then | |
echo 'target branch empty exited' | |
exit 0; | |
fi | |
# Check out each repo to corresponding branch | |
for repo in "${repos[@]}"; do | |
# subshell | |
repo_dir="$working_dir/../$repo" | |
if [ -d $repo_dir ]; then | |
echo "checking out $repo to $target_branch ----------------------------" | |
(cd $repo_dir && git checkout $target_branch) | |
echo "done ------------------------------------------------------------" | |
else | |
echo "$repo_dir not exists, skipped" | |
fi | |
done | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO:
stash save
,stash pop
andgit pull