transpile-onto.sh 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. if [ $# -lt 1 ]; then
  4. echo "usage: bash $0 <target> [<base>]" >&2
  5. exit 1
  6. fi
  7. set -x
  8. target="$1"
  9. base="${2-}"
  10. bash scripts/upgradeable/transpile.sh
  11. commit="$(git rev-parse --short HEAD)"
  12. branch="$(git rev-parse --abbrev-ref HEAD)"
  13. git add contracts
  14. # detach from the current branch to avoid making changes to it
  15. git checkout --quiet --detach
  16. # switch to the target branch, creating it if necessary
  17. if git rev-parse -q --verify "$target"; then
  18. # if the branch exists, make it the current HEAD without checking out its contents
  19. git reset --soft "$target"
  20. git checkout "$target"
  21. else
  22. # if the branch doesn't exist, create it as an orphan and check it out
  23. git checkout --orphan "$target"
  24. if [ -n "$base" ] && git rev-parse -q --verify "$base"; then
  25. # if base was specified and it exists, set it as the branch history
  26. git reset --soft "$base"
  27. fi
  28. fi
  29. # commit if there are changes to commit
  30. if ! git diff --quiet --cached; then
  31. git commit -m "Transpile $commit"
  32. fi
  33. git checkout "$branch"