Skip to content

Commit ecd16b9

Browse files
committed
fix: Migration script should also work for repos configured as "forks"
Previously, I had assumed all repos had an "origin" remote. This is a fatal assumption because several enterprise repos had been included in FORKED_REPOS on newer devstacks so they were configured without an "origin" remote. This fixes the migration script to handle the fork repo case---instead of re-writing the "origin" remote, re-point the main branch to track the "edx" remote instead of the "openedx" remote. ENT-11240 (epic: ENT-11239)
1 parent ec1dbf2 commit ecd16b9

File tree

1 file changed

+38
-7
lines changed

1 file changed

+38
-7
lines changed

migrate-repo-git-to-edx.sh

Lines changed: 38 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
#
33
# Migrate all enterprise repo clones from openedx to edx github org.
44
#
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.
57
#
6-
set -eu -o pipefail
78

89
REPOS=(
910
enterprise-access
@@ -33,15 +34,45 @@ fi
3334
for repo in "${REPOS[@]}"; do
3435
echo "Updating $repo ..."
3536
if [ ! -d "$DEVSTACK_WORKSPACE/$repo" ]; then
36-
echo "Skipping $repo (not found)"
37+
echo "Skipping $repo: not found"
3738
continue
3839
fi
3940
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
4576
popd >/dev/null
4677
echo
4778
done

0 commit comments

Comments
 (0)