#!/bin/bash set -e . /nail/workflow/pushlib.sh usage() { echo "$0 ..." exit 1 } main() { BRANCH_NAMES=${@:1} BRANCH_BASE="origin/master" TARGET="$(git-branch-name)" colorize git fetch origin colorize git reset --hard $BRANCH_BASE merge-branches $TARGET $BRANCH_NAMES separator list-pushplans $TARGET $BRANCH_BASE } merge-branches() { DEPLOY=$1 BRANCH_NAMES=${@:2} for BRANCH_NAME in $BRANCH_NAMES do separator if ! colorize git merge --no-ff --no-commit "origin/$BRANCH_NAME"; then echo -e "${RED}Unable to merge $BRANCH_NAME.${NORMAL}" git diff reset_branch_and_abort $DEPLOY fi git merge --abort colorize git merge --no-ff "origin/$BRANCH_NAME" done } list-pushplans() { TARGET=$1 BASE=$2 echo -e "${PURPLE}Pushplans present in this deploy:${NORMAL}" git diff --name-only "$(git merge-base "$TARGET" "$BASE")..$TARGET" -- pushplans } reset-branch-and-abort() { RESET_TARGET=$1 RESET_SHA="$(git rev-parse "$RESET_TARGET")" separator git reset --hard "$RESET_SHA" make clean separator echo -e "Aborted." exit 1 } main $@