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