merge-upstream.sh 937 B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. : "${REF:="$(git rev-parse --symbolic-full-name HEAD)"}"
  4. if [[ "$REF" != refs/heads/* ]]; then
  5. echo "$REF is not a branch" >&2
  6. exit 1
  7. elif [[ "$REF" == refs/heads/patches ]]; then
  8. REF=refs/heads/master
  9. fi
  10. set -x
  11. input="${REF#refs/heads/}"
  12. upstream="${input#patched/}"
  13. branch="patched/$upstream"
  14. git checkout "$branch" 2>/dev/null || git checkout -b "$branch" origin/patches --no-track
  15. git fetch 'https://github.com/OpenZeppelin/openzeppelin-contracts.git' master
  16. merge_base="$(git merge-base origin/patches FETCH_HEAD)"
  17. git fetch 'https://github.com/OpenZeppelin/openzeppelin-contracts.git' "$upstream"
  18. # Check that patches is not ahead of the upstream branch we're merging.
  19. if ! git merge-base --is-ancestor "$merge_base" FETCH_HEAD; then
  20. echo "The patches branch is ahead of $upstream" >&2
  21. exit 1
  22. fi
  23. git merge origin/patches FETCH_HEAD -m "Merge upstream $upstream into $branch"