rebase-bump-commit 886 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/bin/bash
  2. #
  3. # Move the "bump to <version>" commit to the HEAD of the branch
  4. #
  5. . "$(dirname "${BASH_SOURCE[0]}")/utils.sh"
  6. function usage() {
  7. >&2 cat << EOM
  8. Move the "bump to <version>" commit to the HEAD of the branch
  9. This script requires that 'git config branch.${BRANCH}.release' is set to the
  10. release version for the release branch.
  11. EOM
  12. exit 1
  13. }
  14. BRANCH="$(git rev-parse --abbrev-ref HEAD)"
  15. VERSION="$(git config "branch.${BRANCH}.release")" || usage
  16. COMMIT_MSG="Bump $VERSION"
  17. sha="$(git log --grep "$COMMIT_MSG\$" --format="%H")"
  18. if [ -z "$sha" ]; then
  19. >&2 echo "No commit with message \"$COMMIT_MSG\""
  20. exit 2
  21. fi
  22. if [[ "$sha" == "$(git rev-parse HEAD)" ]]; then
  23. >&2 echo "Bump commit already at HEAD"
  24. exit 0
  25. fi
  26. commits=$(git log --format="%H" "$sha..HEAD" | wc -l | xargs echo)
  27. git rebase --onto $sha~1 HEAD~$commits $BRANCH
  28. git cherry-pick $sha