Skip to content

Commit e04aaa6

Browse files
committed
Fix stale CI submodule remotes
1 parent 5d143ec commit e04aaa6

2 files changed

Lines changed: 44 additions & 1 deletion

File tree

scripts/devops/init-submodules.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,23 @@ for name in ai docs; do
207207

208208
# Set the URL directly in .git/config to override .gitmodules
209209
run git config "submodule.${name}.url" "${url}"
210+
211+
if [[ -d "${path}/.git" ]]; then
212+
run git -C "${path}" remote set-url origin "${url}" 2>/dev/null || true
213+
elif [[ -f "${path}/.git" ]]; then
214+
gitdir="$(sed 's/gitdir: //' "${path}/.git")"
215+
if [[ "${gitdir}" != /* ]]; then
216+
gitdir="$(cd "${path}" && cd "${gitdir}" && pwd)"
217+
fi
218+
if [[ -d "${gitdir}" ]]; then
219+
run git -C "${path}" remote set-url origin "${url}" 2>/dev/null || true
220+
fi
221+
fi
222+
223+
modules_config="${PROJECT_ROOT}/.git/modules/${name}/config"
224+
if [[ -f "${modules_config}" ]]; then
225+
run git -C ".git/modules/${name}" config remote.origin.url "${url}" 2>/dev/null || true
226+
fi
210227
done
211228

212229
# 3. Update (fetch and checkout)

tests/deployment/test_init_submodules.sh

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ cleanup() {
2626
trap cleanup EXIT
2727

2828
setup_fake_git() {
29-
mkdir -p "${TEST_DIR}/bin" "${TEST_DIR}/repo"
29+
mkdir -p "${TEST_DIR}/bin" "${TEST_DIR}/repo/.git/modules/ai" "${TEST_DIR}/repo/.git/modules/docs"
3030
cat > "${TEST_DIR}/repo/.gitmodules" <<'EOF'
3131
[submodule "ai"]
3232
path = ai
@@ -187,6 +187,31 @@ test_submodule_update_retries_without_depth_when_shallow_fetch_fails() {
187187
assert_contains "submodule update --recursive --force" "${TEST_DIR}/git.log"
188188
}
189189

190+
test_existing_submodule_metadata_is_synchronized() {
191+
print_header "Existing submodule metadata is updated to the selected remote"
192+
TESTS_RUN=$((TESTS_RUN + 1))
193+
rm -rf "${TEST_DIR}"
194+
TEST_DIR="$(mktemp -d /tmp/init-submodules-test-XXXXXX)"
195+
setup_fake_git
196+
197+
mkdir -p "${TEST_DIR}/repo/ai" "${TEST_DIR}/repo/docs"
198+
printf 'gitdir: ../.git/modules/ai\n' > "${TEST_DIR}/repo/ai/.git"
199+
printf 'gitdir: ../.git/modules/docs\n' > "${TEST_DIR}/repo/docs/.git"
200+
: > "${TEST_DIR}/repo/.git/modules/ai/config"
201+
: > "${TEST_DIR}/repo/.git/modules/docs/config"
202+
203+
PATH="${TEST_DIR}/bin:${PATH}" \
204+
PROJECT_ROOT="${TEST_DIR}/repo" \
205+
TF_BUILD="True" \
206+
SYSTEM_ACCESSTOKEN="test-token" \
207+
GITHUB_PAT="github-token" \
208+
MOCK_GIT_FAIL_REMOTE_PATTERN="dev.azure.com/handtransfer/pixelated/_git/" \
209+
bash "${TARGET_SCRIPT}"
210+
211+
assert_contains "-C ai remote set-url origin https://github.com/daggerstuff/ai.git" "${TEST_DIR}/git.log"
212+
assert_contains "-C .git/modules/ai config remote.origin.url https://github.com/daggerstuff/ai.git" "${TEST_DIR}/git.log"
213+
}
214+
190215
test_non_azure_submodule_update_has_no_extraheader() {
191216
print_header "Non-Azure submodule update does not inject Azure auth"
192217
TESTS_RUN=$((TESTS_RUN + 1))
@@ -210,6 +235,7 @@ main() {
210235
test_azure_falls_back_to_github_when_mirror_is_unavailable
211236
test_azure_falls_back_to_github_without_github_probe
212237
test_submodule_update_retries_without_depth_when_shallow_fetch_fails
238+
test_existing_submodule_metadata_is_synchronized
213239
test_non_azure_submodule_update_has_no_extraheader
214240

215241
echo "Tests run: ${TESTS_RUN}"

0 commit comments

Comments
 (0)