Skip to content

Commit

Permalink
fix(assert_clean_master): Output error messages to stderr, not stdout (
Browse files Browse the repository at this point in the history
  • Loading branch information
christopherthielen authored and Yun Zhang committed Mar 28, 2021
1 parent f1f5855 commit 9dd018e
Showing 1 changed file with 28 additions and 25 deletions.
53 changes: 28 additions & 25 deletions app/scripts/modules/assert_clean_master.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ cd "$(dirname "$0")" || exit;
# (a local branch that tracks decks 'master' branch)
CURRENTBRANCH=$(git symbolic-ref --short HEAD)
TRACKING=$(git rev-parse --abbrev-ref --symbolic-full-name "@{u}")
function error() {
echo "$*" >&2
}

if [ $? -ne 0 ] ; then
echo "You must be on 'master' (a branch tracking the upstream Deck 'master' branch)."
echo
echo "The current branch '$CURRENTBRANCH' is not tracking any remote."
error "You must be on 'master' (a branch tracking the upstream Deck 'master' branch)."
error
error "The current branch '$CURRENTBRANCH' is not tracking any remote."
exit 1
fi

Expand All @@ -21,28 +24,28 @@ DECK_HTTPS="https://github.com/spinnaker/deck.git"
DECK_GIT="[email protected]:spinnaker/deck.git"

if [ "x${REMOTE_URL}" != "x${DECK_HTTPS}" ] && [ "x${REMOTE_URL}" != "x${DECK_GIT}" ] ; then
echo "You must be on 'master' (a branch tracking the upstream Deck 'master' branch)."
echo
echo "The current branch '${CURRENTBRANCH}' is tracking '${TRACKING}'."
echo "However, the remote '${REMOTE}' has a URL of '${REMOTE_URL}'."
echo "The tracked remote should be either '${DECK_HTTPS}' or '${DECK_GIT}'."
error "You must be on 'master' (a branch tracking the upstream Deck 'master' branch)."
error
error "The current branch '${CURRENTBRANCH}' is tracking '${TRACKING}'."
error "However, the remote '${REMOTE}' has a URL of '${REMOTE_URL}'."
error "The tracked remote should be either '${DECK_HTTPS}' or '${DECK_GIT}'."
exit 2
fi

if [ "x${BRANCH}" != "xmaster" ] ; then
echo "You must be on 'master' (a branch tracking the upstream Deck 'master' branch)."
echo
echo "The current branch '${CURRENTBRANCH}' is tracking '${TRACKING}'."
error "You must be on 'master' (a branch tracking the upstream Deck 'master' branch)."
error
error "The current branch '${CURRENTBRANCH}' is tracking '${TRACKING}'."
exit 3
fi

# Assert that the local branch is "clean" so we don't publish any uncommitted code
DIRTY_COMMITS=$(git status --porcelain);
if [ "x${DIRTY_COMMITS}" != "x" ] ; then
echo "Your working copy is not clean (you have uncommited changes)."
echo
echo "Please stash these changes before publishing using 'git stash'.";
echo
error "Your working copy is not clean (you have uncommited changes)."
error
error "Please stash these changes before publishing using 'git stash'.";
error
git status --porcelain
exit 4;
fi
Expand All @@ -52,21 +55,21 @@ git fetch "$REMOTE"

STATUS=$(git status -sb --porcelain)
if [[ ${STATUS} =~ [Bb]ehind ]] ; then
echo "Your local branch is behind the upstream branch '${TRACKING}'."
echo
echo "The upstream branch has additional commits that would not be included in the published package."
echo "Run 'git pull' to update your local branch."
echo
error "Your local branch is behind the upstream branch '${TRACKING}'."
error
error "The upstream branch has additional commits that would not be included in the published package."
error "Run 'git pull' to update your local branch."
error
git status -sb
exit 5
fi

if [[ ${STATUS} =~ [Aa]head ]] ; then
echo "Your local branch is ahead of the upstream branch '${TRACKING}'."
echo
echo "Your local branch has additional commits that are not reflected in the upstream branch."
echo "Add your commits to the upstream branch by creating a pull request."
echo
error "Your local branch is ahead of the upstream branch '${TRACKING}'."
error
error "Your local branch has additional commits that are not reflected in the upstream branch."
error "Add your commits to the upstream branch by creating a pull request."
error
git status -sb
exit 6
fi

0 comments on commit 9dd018e

Please sign in to comment.