Skip to content

fix(crs): re-point origin when a CRS entry's source.url changes - #577

Open
ParthMozarkar wants to merge 1 commit into
ossf:mainfrom
ParthMozarkar:fix/crs-source-url-change
Open

ParthMozarkar wants to merge 1 commit into
ossf:mainfrom
ParthMozarkar:fix/crs-source-url-change

Conversation

@ParthMozarkar

Copy link
Copy Markdown

Summary

init_crs_repo() used repo_url only when cloning. The checkout lives at crs_src/<entry name>, keyed by name only, so after changing an entry's source.url (e.g. to a fork) the next prepare fetched and reset against the old origin and built the previous repository, with no warning.

Now, when the checkout exists and its origin differs from source.url:

  • online: git remote set-url origin <url> runs before the fetch, and a warning is printed
  • --offline: fails with an error naming both URLs, since the new repository can't be fetched

URLs that differ only by a trailing / or .git are treated as unchanged. Checkouts with no origin, unchanged URLs, and skip_if_exists keep their previous behavior. The new block sits after the existing task selection, so it doesn't touch the lines #497 changes; I checked that this branch and #497 merge cleanly.

User Impact

  • User-facing change
  • Internal-only change

Changing source.url for an existing CRS entry now takes effect on the next run. docs/config/crs-compose.md explains checkout reuse and URL changes. No config or CLI changes; no migration needed.

Release Note / Changelog

  • I updated CHANGELOG.md ([Unreleased]) for user-facing changes
  • No changelog entry needed (internal-only refactor/test/chore)

Validation

Added oss_crs/tests/unit/test_crs_source_url.py (13 tests; 4 failed before the fix). End-to-end tests use two real local repositories, as in the issue's repro:

  • URL changed: checkout ends up on B's commit with origin = B
  • URL unchanged: new commits are still picked up, no set-url
  • --offline with a changed URL: fails, checkout stays on A
  • scheduled tasks: Git Set Remote URL before Git Fetch only when the URL changed
  • .git / trailing-slash spellings are not treated as a change
  • checkout without origin and skip_if_exists behave as before

The existing test_offline_flag.py tests pass unchanged.

uv run verify: all checks pass (ruff check, ruff format, pyright, unit tests, libCRS unit tests).

Checklist

  • I followed Conventional Commits
  • I updated docs for behavior/config/CLI changes
  • I added/updated tests for behavior changes
  • I considered backward compatibility and migration impact

Closes #559

init_crs_repo() used repo_url only when cloning. The checkout lives at
crs_src/<entry name>, keyed by name only, so after changing an entry's
source.url (for example to a fork) the next prepare fetched and reset
against the old origin and built the previous repository without any
warning.

When the checkout exists and its origin differs from source.url, run
`git remote set-url origin <url>` before fetching and print a warning.
Spellings of the same URL with or without a trailing '/' or '.git' count
as unchanged. With --offline nothing can be fetched, so a mismatched
checkout now fails with an error naming both URLs. Checkouts without an
origin, unchanged URLs and skip_if_exists keep their previous behavior.

Document checkout reuse and URL changes in crs-compose.md.

Closes ossf#559

Signed-off-by: ParthMozarkar <greatparth21@gmail.com>
@ParthMozarkar

Copy link
Copy Markdown
Author

@azchin could you take a look when you have time? This touches init_crs_repo like #497 does, but in separate lines; the two merge cleanly in either order.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Changing a CRS entry's source.url keeps using the previously cloned repository

1 participant