Skip to content

Commit d17005b

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 d17005b

File tree

1 file changed

+36
-7
lines changed

1 file changed

+36
-7
lines changed

migrate-repo-git-to-edx.sh

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Migrate all enterprise repo clones from openedx to edx github org.
44
#
55
#
6-
set -eu -o pipefail
76

87
REPOS=(
98
enterprise-access
@@ -33,15 +32,45 @@ fi
3332
for repo in "${REPOS[@]}"; do
3433
echo "Updating $repo ..."
3534
if [ ! -d "$DEVSTACK_WORKSPACE/$repo" ]; then
36-
echo "Skipping $repo (not found)"
35+
echo "Skipping $repo: not found"
3736
continue
3837
fi
3938
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
4574
popd >/dev/null
4675
echo
4776
done

0 commit comments

Comments
 (0)