diff --git a/defaults/scripts/resync-installed.sh b/defaults/scripts/resync-installed.sh index 0552ad3a5d..e7dd5c80a2 100755 --- a/defaults/scripts/resync-installed.sh +++ b/defaults/scripts/resync-installed.sh @@ -3231,9 +3231,6 @@ restamp_metadata() { # freezing whatever was recorded at install time. Best-effort: empty when # SOURCE_ROOT isn't a git checkout or has no `origin` configured. remote="$(normalize_source_remote "$(git -C "$SOURCE_ROOT" remote get-url origin 2>/dev/null || true)")" - # #14222: a clone whose origin predates the org transfer names the old - # owner; stamp the forge's canonical name instead (fail-open, GitHub only). - remote="$(canonicalize_source_remote "$remote")" # #10717: requires_daemon (the compatibility contract, #10716) travels with # the files, so it is read from the tree they came from, the same way # scripts/install/loom-source-path.sh reads it at install time. A source @@ -3269,6 +3266,10 @@ restamp_metadata() { && "$prev_version" == "$version" \ && "$prev_commit" =~ ^[0-9a-f]{40}$ ]]; then noop=1 + else + # #14222: resolve a transferred origin only when refreshing the stamp. + # The no-op path preserves loom_source_remote and needs no forge lookup. + remote="$(canonicalize_source_remote "$remote")" fi local stamped_note="${GREEN}re-stamped${NC} install-metadata.json (loom_version=$version, loom_commit=$commit, last_resync=$today)" diff --git a/defaults/scripts/tests/test-resync-installed-stamp.sh b/defaults/scripts/tests/test-resync-installed-stamp.sh index 40f2839e3f..da2dfeca86 100755 --- a/defaults/scripts/tests/test-resync-installed-stamp.sh +++ b/defaults/scripts/tests/test-resync-installed-stamp.sh @@ -442,8 +442,8 @@ if [[ "$REMOTE14" == "https://github.com/NewOrg/loom.git" ]]; then else fail "(#14222) redirected remote stamped '$REMOTE14'" fi -if grep -q "api repos/OldOrg/loom" <<<"$CALLS14"; then - pass "(#14222) the lookup is a REST 'gh api repos//' call" +if [[ "$CALLS14" == "api repos/OldOrg/loom --jq .full_name" ]]; then + pass "(#14222) the real resync makes exactly one canonical remote lookup" else fail "(#14222) unexpected gh calls: $CALLS14" fi @@ -453,6 +453,37 @@ else fail "(#14222) expected one stale-remote warning; out=$OUT14" fi +# Keep the synchronized surface and valid stamp from the real-write control, +# but restore the previously recorded URL while the source origin still redirects. +META14="$WORKDIR/remote-moved/.loom/install-metadata.json" +STALE14="$WORKDIR/remote-moved-stale-metadata.json" +BIN14="$WORKDIR/gh-remote-moved" +sed 's|https://github.com/NewOrg/loom.git|https://github.com/OldOrg/loom.git|' "$META14" > "$STALE14" +cp "$STALE14" "$META14" +: > "$BIN14/gh.calls" +OUT14_NOOP="$(cd "$WORKDIR/remote-moved" && PATH="$BIN14:$PATH" bash "$SCRIPT" 2>&1)" +RC14_NOOP=$? +if [[ "$RC14_NOOP" == 0 ]] && grep -qF 'nothing to re-stamp (#11680)' <<<"$OUT14_NOOP"; then + pass "(#14712) the stale URL fixture takes the no-op stamp path" +else + fail "(#14712) expected a no-op resync (rc=$RC14_NOOP); out=$OUT14_NOOP" +fi +if cmp -s "$STALE14" "$META14"; then + pass "(#14712) a no-op leaves the stale stamp byte-identical" +else + fail "(#14712) a no-op rewrote install-metadata.json" +fi +if [[ ! -s "$BIN14/gh.calls" ]]; then + pass "(#14712) a no-op skips the canonical remote lookup" +else + fail "(#14712) a no-op called gh: $(cat "$BIN14/gh.calls")" +fi +if ! grep -qE 'origin remote is stale|Stamping the canonical URL' <<<"$OUT14_NOOP"; then + pass "(#14712) a no-op does not claim to stamp the canonical remote" +else + fail "(#14712) a no-op claimed to stamp the canonical remote" +fi + run_remote_case remote-same "https://github.com/o/r.git" "o/r" 0 if [[ "$REMOTE14" == "https://github.com/o/r.git" ]] && ! grep -q 'stale' <<<"$OUT14"; then pass "(#14222) an unredirected remote is stamped unchanged, with no warning"