From 0786549686a63f7d808581d559821ec30277ed21 Mon Sep 17 00:00:00 2001 From: Geoff Harcourt Date: Mon, 18 Dec 2017 22:51:13 -0500 Subject: [PATCH] merge-branch: exit 1 if origin and local differ This change prevents chained commands from continuing execution if the `git merge` is operation would be unsuccessful such as a common operation when a feature branch is ready to be merged and pushed: ``` git merge-branch && git push origin ``` If the origin/master and the local master have any difference, we return status 1 and stop execution rather then emit a false success. h/t: @croaky Fix #563. --- bin/git-merge-branch | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/bin/git-merge-branch b/bin/git-merge-branch index ee3915f..01cd228 100755 --- a/bin/git-merge-branch +++ b/bin/git-merge-branch @@ -2,5 +2,13 @@ set -e +git fetch origin +line_count=$(git diff origin/master..master | wc -l) + +if [ $line_count -gt 0 ]; then + printf "failed: master is not up to date with origin/master\n" + exit 1 +fi + git checkout master git merge "@{-1}"