Skip to content

Fix stale remote URL when cached repo's origin changes#298

Merged
hasaant merged 1 commit into
wayfair-incubator:mainfrom
hasaant:fix/srvlc-2064-stale-remote-url
Mar 27, 2026
Merged

Fix stale remote URL when cached repo's origin changes#298
hasaant merged 1 commit into
wayfair-incubator:mainfrom
hasaant:fix/srvlc-2064-stale-remote-url

Conversation

@hasaant

@hasaant hasaant commented Mar 26, 2026

Copy link
Copy Markdown
Collaborator

Summary

When a GitHub repo is transferred between orgs (e.g. wayfair-stagingwayfair-shared), the locally cached clone retains the old origin URL. Subsequent calls to get_updated_repo() fail with repository not found because fetch/pull still target the stale URL.

This adds a URL comparison in get_updated_repo(): if the cached origin.url doesn't match the caller-provided repo_url, we call set_url() to update it before any fetch operations.

Changes

  • pygitops/operations.py: Compare repo.remotes.origin.url against the passed repo_url and call set_url() when they differ, before fetching or pulling
  • tests/test_operations.py: Added 3 new tests:
    • Unit test: stale URL is updated via set_url
    • Unit test: matching URL does not trigger set_url
    • Integration test: clone, simulate org transfer, verify get_updated_repo updates the URL and pulls new content

Test plan

  • Unit tests verify set_url is called only when URLs differ
  • Integration test simulates a full org transfer scenario end-to-end
  • After merge + release, verify prepare step no longer fails for transferred repos

When a GitHub repo is transferred between orgs (e.g. wayfair-staging to
wayfair-shared), the locally cached clone retains the old origin URL.
Subsequent calls to get_updated_repo() would fail with "repository not
found" because fetch/pull still targets the stale URL.

Compare the cached origin URL against the caller-provided repo_url and
call set_url() to update it before fetching.

Fixes SRVLC-2064
@codecov

codecov Bot commented Mar 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (623e1e7) to head (1b93722).
⚠️ Report is 5 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #298   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            6         7    +1     
  Lines          173       176    +3     
  Branches        20        16    -4     
=========================================
+ Hits           173       176    +3     
Files with missing lines Coverage Δ
pygitops/operations.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jashparekh jashparekh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! This is a clean fix with excellent test coverage. The implementation correctly handles the stale remote URL scenario when repos are transferred between orgs.

@hasaant hasaant merged commit 15180a7 into wayfair-incubator:main Mar 27, 2026
16 checks passed
hasaant pushed a commit to hasaant/pygitops that referenced this pull request Apr 6, 2026
Resolve conflicts:
- setup.cfg: accept deletion (project uses pyproject.toml on main)
- tests/test_operations.py: drop duplicate tests already present from wayfair-incubator#298

Made-with: Cursor
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.

2 participants