|
#!/bin/bash |
|
repoRoot=$(pwd) |
|
currentBranchName=$(git rev-parse --abbrev-ref HEAD) |
|
|
|
submodule=$(git config --file .gitmodules --get-regexp path | awk '{ print $2 }') |
|
submoduleArr=($(echo "$submodule" | tr ' ' '\n')) |
|
|
|
|
|
show_help() { |
|
echo " |
|
Usage: ./gitflow.sh <subcommand> |
|
Git flow extend cli tool is a tool to support git submodule. You must install git flow first https://github.com/nvie/gitflow. |
|
|
|
Available subcommands are: |
|
init Initialize a new git repo with support for the branching model. |
|
feature Manage your feature branches. |
|
bugfix Manage your bugfix branches. |
|
release Manage your release branches. |
|
hotfix Manage your hotfix branches. |
|
support Manage your support branches. |
|
version Shows version information. |
|
config Manage your git-flow configuration. |
|
log Show log deviating from base branch. |
|
branch Shows submodule branch name. |
|
" |
|
} |
|
|
|
runCommandInSubmodule() { |
|
for i in "${submoduleArr[@]}"; do # access each element of array |
|
# if Directory exists |
|
if [ -d "./$i" ] |
|
then |
|
echoBoldText "In directory $repoRoot/$i and executing command \"$gitCommand\"" |
|
cd $i && $gitCommand && cd $repoRoot |
|
fi |
|
done |
|
} |
|
|
|
echoSuccesText() { |
|
tput setaf 2; echo $1; tput sgr0; |
|
} |
|
|
|
echoBoldText() { |
|
tput bold; echo $1; tput sgr0; |
|
} |
|
|
|
echoErrorText() { |
|
tput setaf 1; echo $1; tput sgr0; |
|
} |
|
|
|
echoUnderlineText() { |
|
tput smul; echo $1; tput rmul; |
|
} |
|
|
|
validateSubmoduleAreSameBranchName() { |
|
if [[ ! $currentBranchName == $(git rev-parse --abbrev-ref HEAD) ]]; then |
|
echoErrorText "$repoRoot branch name does not match $currentBranchName! You may use 'git flow' command to manual finish your branch (if you know what you'r doing)." |
|
fi |
|
|
|
for i in "${submoduleArr[@]}"; do # access each element of array |
|
# if Directory exists |
|
if [ -d "./$i" ] |
|
then |
|
cd $i && if [[ ! $currentBranchName == $(git rev-parse --abbrev-ref HEAD) ]]; then |
|
echoErrorText "$repoRoot/$i branch name does not match $currentBranchName! You may use 'git flow' command to manual finish your branch (if you know what you'r doing)." |
|
exit 1 |
|
fi && cd $repoRoot |
|
fi |
|
done |
|
} |
|
|
|
showSubmoduleBranchName() { |
|
echoUnderlineText "$repoRoot > $(git rev-parse --abbrev-ref HEAD)" |
|
for i in "${submoduleArr[@]}"; do # access each element of array |
|
# if Directory exists |
|
if [ -d "./$i" ] |
|
then |
|
cd $i && echoUnderlineText "$repoRoot/$i > $(git rev-parse --abbrev-ref HEAD)" && cd $repoRoot |
|
fi |
|
done |
|
} |
|
|
|
case $1 in |
|
"init") |
|
git flow init |
|
;; |
|
"feature"|"bugfix"|"release"|"hotfix") |
|
gitCommand="git flow $1 $2 $3" |
|
echoBoldText "In direactory $repoRoot and executing command \"$gitCommand\"" |
|
|
|
if [[ $2 == 'finish' ]]; then |
|
validateSubmoduleAreSameBranchName |
|
fi |
|
|
|
$gitCommand && runCommandInSubmodule $gitCommand && echoSuccesText "All Set! Good to go!" |
|
;; |
|
"branch") |
|
showSubmoduleBranchName |
|
;; |
|
"") |
|
show_help |
|
;; |
|
*) |
|
git flow $1 |
|
;; |
|
esac |