scatterd-dotfiles/bin/git-merge-branch
Geoff Harcourt 0786549686 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.
2017-12-18 22:51:13 -05:00

14 lines
237 B
Bash
Executable file

#!/bin/sh
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}"