Skip to content

Commit 6c2be9a

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 6c2be9a

File tree

1 file changed

+39
-7
lines changed

1 file changed

+39
-7
lines changed

migrate-repo-git-to-edx.sh

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
# Migrate all enterprise repo clones from openedx to edx github org.
44
#
55
#
6-
set -eu -o pipefail
6+
7+
# Print trace of commands for easier debugging.
8+
set -x
79

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

0 commit comments

Comments
 (0)