build: publish and sync script modification

now you can pass a branch to the publish and sync script to sync or publish to another branch  then master
This commit is contained in:
Andreas Stallinger
2015-11-10 10:11:50 +01:00
parent a4c134ebe2
commit 5ef9ef9e7d
4 changed files with 139 additions and 115 deletions
+28 -19
View File
@@ -6,6 +6,15 @@ INFO="\033[33mInfo:\033[00m"
echo -e $INFO "Checking index"
#set branch to commit to
if [[ $# -gt 0 ]]
then
PUBLISH_TO_BRANCH=$1
else
PUBLISH_TO_BRANCH="master"
fi
echo -e $INFO "branch to commit: $PUBLISH_TO_BRANCH"
# check clean index
if [[ -n $(git diff HEAD) ]]
then
@@ -25,44 +34,44 @@ then
exit 1
fi
# check if on master
if [ $BRANCH_NAME == "master" ]
# check if on $PUBLISH_TO_BRANCH
if [ $BRANCH_NAME == $PUBLISH_TO_BRANCH ]
then
echo -e $ABORT "You are on master. Use this script only from a feature branch."
echo -e $ABORT "You are on $PUBLISH_TO_BRANCH. Use this script only from a feature branch."
exit 1
fi
git checkout -q master
git checkout -q $PUBLISH_TO_BRANCH
git remote update &>/dev/null
echo -e $INFO "Checking master"
echo -e $INFO "Checking $PUBLISH_TO_BRANCH"
# check if master is up to date
if [[ -n $(git diff origin/master) ]]
# check if $PUBLISH_TO_BRANCH is up to date
if [[ -n $(git diff origin/$PUBLISH_TO_BRANCH) ]]
then
echo -e $ABORT "Your master is not up-to-date. Run 'git-sync-master.sh' to update master and rebase $BRANCH_NAME."
echo -e $ABORT "Your $PUBLISH_TO_BRANCH is not up-to-date. Run 'git-sync.sh' to update $PUBLISH_TO_BRANCH and rebase $BRANCH_NAME."
git checkout -q $BRANCH_NAME
exit 1
fi
MASTER_HEAD_COMMIT=$(git rev-parse HEAD)
BASE_COMMIT=$(git merge-base $BRANCH_NAME master)
PUBLIC_BRANCH_HEAD_COMMIT=$(git rev-parse HEAD)
BASE_COMMIT=$(git merge-base $BRANCH_NAME $PUBLISH_TO_BRANCH)
git checkout -q $BRANCH_NAME
BRANCH_HEAD_COMMIT=$(git rev-parse HEAD)
# check if feature has commits
if [ $BRANCH_HEAD_COMMIT == $MASTER_HEAD_COMMIT ]
if [ $BRANCH_HEAD_COMMIT == $PUBLIC_BRANCH_HEAD_COMMIT ]
then
echo -e $ABORT "Your feature branch has no commits."
exit 1
fi
# check if feature is not behind master
if [ $BASE_COMMIT != $MASTER_HEAD_COMMIT ]
# check if feature is not behind $PUBLIC_BRANCH_HEAD_COMMIT
if [ $BASE_COMMIT != $PUBLIC_BRANCH_HEAD_COMMIT ]
then
echo -e $ABORT "Your feature branch is behind master. Use 'git rebase master' to update your feature branch."
echo -e $ABORT "Your feature branch is behind $PUBLISH_TO_BRANCH. Use 'git rebase $PUBLISH_TO_BRANCH' to update your feature branch."
exit 1
fi
@@ -87,19 +96,19 @@ then
exit 1
fi
echo -e $INFO "Rebasing on master"
git checkout -q master
echo -e $INFO "Rebasing on $PUBLISH_TO_BRANCH"
git checkout -q $PUBLISH_TO_BRANCH
git rebase -q $PUBLISH_BRANCH_NAME
git branch -q -d $PUBLISH_BRANCH_NAME
echo -e $INFO "Uploading to origin master"
git push origin master
echo -e $INFO "Uploading to origin $PUBLISH_TO_BRANCH"
git push origin $PUBLISH_TO_BRANCH
if [ $? != 0 ]
then
git reset --hard -q HEAD^
git checkout -q $BRANCH_NAME
echo -e $ABORT "Pushing to origin master has failed, there are new remote changes. Run 'git-sync-master.sh' to update master and rebase $BRANCH_NAME."
echo -e $ABORT "Pushing to origin $PUBLISH_TO_BRANCH has failed, there are new remote changes. Run 'git-sync.sh' to update $PUBLISH_TO_BRANCH and rebase $BRANCH_NAME."
exit 1
fi