transpile-onto.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. start_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. # abort if there are no changes to commit at this point
  30. if git diff --quiet --cached; then
  31. exit
  32. fi
  33. if [[ -v SUBMODULE_REMOTE ]]; then
  34. lib=lib/openzeppelin-contracts
  35. git submodule add -b "${base#origin/}" "$SUBMODULE_REMOTE" "$lib"
  36. git -C "$lib" checkout "$commit"
  37. git add "$lib"
  38. fi
  39. git commit -m "Transpile $commit" --no-verify
  40. # return to original branch
  41. git checkout "$start_branch"