|
2 | 2 | # |
3 | 3 | # Migrate all enterprise repo clones from openedx to edx github org. |
4 | 4 | # |
| 5 | +# If an "origin" remote is used, re-write its URL to utilize the edx repo. If the main |
| 6 | +# branch tracks the "openedx" remote, re-write it to track the "edx" remote. |
5 | 7 | # |
6 | | -set -eu -o pipefail |
7 | 8 |
|
8 | 9 | REPOS=( |
9 | 10 | enterprise-access |
|
33 | 34 | for repo in "${REPOS[@]}"; do |
34 | 35 | echo "Updating $repo ..." |
35 | 36 | if [ ! -d "$DEVSTACK_WORKSPACE/$repo" ]; then |
36 | | - echo "Skipping $repo (not found)" |
| 37 | + echo "Skipping $repo: not found" |
37 | 38 | continue |
38 | 39 | fi |
39 | 40 | pushd "$DEVSTACK_WORKSPACE/$repo" >/dev/null |
40 | | - OLD_ORIGIN=$(git remote get-url origin) |
41 | | - git remote set-url origin $(git remote get-url origin | sed 's/openedx/edx/') |
42 | | - NEW_ORIGIN=$(git remote get-url origin) |
43 | | - echo "Old origin: ${OLD_ORIGIN}" |
44 | | - echo "New origin: ${NEW_ORIGIN}" |
| 41 | + origin_remote_url=$(git remote get-url origin 2>/dev/null) |
| 42 | + if [ -n "${origin_remote_url}" ]; then |
| 43 | + # An "origin" remote has been found! Simply re-write that origin to point to "edx". |
| 44 | + # Use `sed` to avoid complicated conditional logic around SSH vs. HTTPS. |
| 45 | + git remote set-url origin "$(git remote get-url origin | sed 's/openedx/edx/')" |
| 46 | + new_origin_remote_url=$(git remote get-url origin) |
| 47 | + echo "Old origin: ${origin_remote_url}" |
| 48 | + echo "New origin: ${new_origin_remote_url}" |
| 49 | + else |
| 50 | + # "origin" remote does not exist, so assume the main branch has been configured to |
| 51 | + # point to an "openedx" remote, and an "edx" remote exists. |
| 52 | + edx_remote_url=$(git remote get-url edx 2>/dev/null) |
| 53 | + if [ -z "${edx_remote_url}" ]; then |
| 54 | + echo "Skipping $repo: Could not find \"edx\" remote." |
| 55 | + popd >/dev/null |
| 56 | + continue |
| 57 | + fi |
| 58 | + main_branch_id=$(git rev-parse --verify --quiet main) |
| 59 | + if [ -n "${main_branch_id}" ]; then |
| 60 | + branch_to_update=main |
| 61 | + else |
| 62 | + branch_to_update=master |
| 63 | + fi |
| 64 | + main_branch_remote=$(git config branch.${branch_to_update}.remote) |
| 65 | + if [ "${main_branch_remote}" != "edx" ]; then |
| 66 | + git config branch.${branch_to_update}.remote edx |
| 67 | + new_main_branch_remote=$(git config branch.${branch_to_update}.remote) |
| 68 | + echo "Old tracking remote: ${main_branch_remote}" |
| 69 | + echo "New tracking remote: ${new_main_branch_remote}" |
| 70 | + else |
| 71 | + echo "Skipping $repo: ${branch_to_update} branch was already configured to track edx remote." |
| 72 | + popd >/dev/null |
| 73 | + continue |
| 74 | + fi |
| 75 | + fi |
45 | 76 | popd >/dev/null |
46 | 77 | echo |
47 | 78 | done |
|
0 commit comments