|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# TODO: Write better bash. |
| 4 | +# TODO: Rename this to rebase-all-aosp-forks |
| 5 | + |
| 6 | +set -o errexit -o nounset -o pipefail |
| 7 | +source "$(dirname ${BASH_SOURCE[0]})/../common.sh" |
| 8 | + |
| 9 | +rebase() { |
| 10 | + # See repo-fetch-aosp-tags. |
| 11 | + if git log -1 --oneline --decorate | grep grafted |
| 12 | + then |
| 13 | + echo "success, but requires manual handling as clone-depth is set" |
| 14 | + # Create a file so that repo status alerts on this repository. |
| 15 | + touch "temporary-repo-status-marker" |
| 16 | + exit 0 |
| 17 | + fi |
| 18 | + |
| 19 | + # Allows us to run this script multiple times if something went wrong. |
| 20 | + git rebase --abort &>/dev/null || true |
| 21 | + |
| 22 | + git checkout -q -B "${developer_port_branch}" "${graphene_ref}" |
| 23 | + git_exit=0 |
| 24 | + git rebase -q --onto $aosp_tag $aosp_tag_old &>/dev/null || git_exit=$? |
| 25 | + if [[ "${git_exit}" == 1 ]]; then |
| 26 | + echo "success, but requires manual conflict resolution" |
| 27 | + return 0 |
| 28 | + elif [[ "${git_exit}" != 0 ]]; then |
| 29 | + # If the rebase never begins due to bad tags then git exits with 128. |
| 30 | + echo_red "fail, unexpected error during rebase" |
| 31 | + exit 1 |
| 32 | + fi |
| 33 | + |
| 34 | + if [[ "${REPO_REMOTE}" == "grapheneos" ]]; then |
| 35 | + if ! git push -q -f my-fork $developer_port_branch &>/dev/null |
| 36 | + then |
| 37 | + echo_red "fail, unexpected error during push" |
| 38 | + exit 2 |
| 39 | + fi |
| 40 | + echo "success" |
| 41 | + else |
| 42 | + echo "success, but can't push due to hosted on GitLab" |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +create_developer_port_branch() { |
| 47 | + if ! git checkout -q -B "${developer_port_branch}" "${graphene_ref}" |
| 48 | + then |
| 49 | + # Most likely a repo was introduced during the manifest port and it did not exist for the previous release. A new |
| 50 | + # kernel, for example. |
| 51 | + echo_red "fail, developer port branch target does not exist" |
| 52 | + exit 3 |
| 53 | + fi |
| 54 | + if ! git push -q -f my-fork $developer_port_branch &>/dev/null |
| 55 | + then |
| 56 | + echo_red "fail, unexpected error during push" |
| 57 | + exit 2 |
| 58 | + fi |
| 59 | + echo "success" |
| 60 | +} |
| 61 | + |
| 62 | +# We can't just check if $REPO_REMOTE == "grapheneos" because not all of our repos are AOSP forks. `repo` project groups |
| 63 | +# would allow us to simplify this so that we could just run `repo forall -g aosp-forks`. |
| 64 | +for graphene_repo in "${aosp_forks[@]}"; do |
| 65 | + if [[ "${graphene_repo}" == "${REPO_PROJECT}" ]] ; then |
| 66 | + rebase "${graphene_repo}" |
| 67 | + exit 0 |
| 68 | + fi |
| 69 | +done |
| 70 | + |
| 71 | +# If it's not an aosp_fork but its remote is grapheneos then create a branch such that we can update the grapheneos |
| 72 | +# remote in the platform manifest to point to a branch in our own repository. |
| 73 | +if [[ "${REPO_REMOTE}" == "grapheneos" ]]; then |
| 74 | + create_developer_port_branch |
| 75 | + exit 0 |
| 76 | +fi |
0 commit comments