fix(check_upstream_updates): warn when check falls back to a fork's own origin (#265)

On a fork without an 'upstream' remote, the checker silently fell back to 'origin' (the fork itself) and still printed '[OK] All framework files are up to date with upstream!', a false positive: the fork is always up to date with itself, so upstream updates were never reported. This is exactly the setup CONTRIBUTING.md recommends for forks.

Now, when the fallback remote does not point at the ai-job-search template repo, the script warns that the comparison is fork-vs-self and prints the command to add the template as a remote. The final OK line now names the ref it actually compared against.

Tests (new tests/test_check_upstream_updates.py, three scenarios) fail on master and pass with the fix.
This commit is contained in:
Oscar Madera
2026-08-01 22:00:49 +02:00
committed by GitHub
parent 1cdaf9497f
commit 72bbe00529
2 changed files with 138 additions and 1 deletions
+19 -1
View File
@@ -33,10 +33,16 @@ FRAMEWORK_FILES = [
"AGENTS.md",
]
UPSTREAM_REPO_SLUG = "MadsLorentzen/ai-job-search"
def run_git(args: list[str]) -> tuple[int, str, str]:
res = subprocess.run(["git"] + args, cwd=str(ROOT), capture_output=True, text=True)
return res.returncode, res.stdout, res.stderr
def get_remote_url(remote_name: str) -> str:
rc, stdout, _ = run_git(["remote", "get-url", remote_name])
return stdout.strip() if rc == 0 else ""
def get_framework_version_from_text(text: str) -> str | None:
if not text.startswith("---\n"):
return None
@@ -76,6 +82,18 @@ def main() -> int:
print("Error: No git remotes found.")
return 1
# A fork's own 'origin' can never reveal upstream updates: warn so the
# user is not misled by the final '[OK]' line below. (Direct clones of
# the template repo have origin == the upstream repo, so no warning.)
if remote != args.remote and UPSTREAM_REPO_SLUG not in get_remote_url(remote):
print(
f"Warning: Remote '{remote}' does not point to the ai-job-search "
f"template repo ({UPSTREAM_REPO_SLUG}), so this check compares your "
f"fork against itself and will never report upstream updates. "
f"Add the template repo as a remote to track upstream changes, e.g.:\n"
f" git remote add upstream https://github.com/{UPSTREAM_REPO_SLUG}.git"
)
if not args.no_fetch:
print(f"Fetching latest from remote '{remote}'...")
rc, _, stderr = run_git(["fetch", remote])
@@ -143,7 +161,7 @@ def main() -> int:
print("Review these changes to see if they fit your personalized fork!")
return 0
else:
print("[OK] All framework files are up to date with upstream!")
print(f"[OK] All framework files are up to date with {ref}!")
return 0
if __name__ == "__main__":