fix(check_main_sync): fetch an explicit --base before resolving it

main() resolved the base before running --fetch, so an explicit base on a
remote that was never fetched failed with "no base ref found" and never
fetched. The fetch is now a local helper and runs first when --base is
given; the default base still resolves first, then fetches.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
GalaxyGamingFRandClaude Opus 5.5 committed 2026-10-15 14:01:15 -07:00
1 parent ce991f1ec2
commit a70dea62e7
2 files changed
+16 -3

No files matched your search

+8 -3
View File
@@ -97,12 +97,17 @@ if __name__ == "__main__":
parser.add_argument("--strict", action="store_true", help="also fail when the branch is behind the base")
args = parser.parse_args()
try:
base = resolve_base(args.repo, args.base)
if args.fetch:
remote, _, branch = base.partition("/")
def fetch(ref):
remote, _, branch = ref.partition("/")
if not branch:
parser.error("--fetch needs a remote-tracking base such as upstream/main")
git(args.repo, "fetch", "--quiet", remote, branch)
if args.fetch and args.base:
fetch(args.base)
base = resolve_base(args.repo, args.base)
if args.fetch and not args.base:
fetch(base)
data = report(args.repo, base, args.head)
except RuntimeError as error:
parser.error(str(error))
+8
View File
@@ -177,6 +177,14 @@ class CheckMainSyncTests(unittest.TestCase):
self.assertEqual(result.returncode, 2)
self.assertIn("no base ref found", result.stderr)
def test_explicit_base_is_fetched_before_it_is_resolved(self):
with tempfile.TemporaryDirectory() as other:
subprocess.run(["git", "clone", "-q", self.directory.name, other], check=True, capture_output=True)
self.repo.git("remote", "add", "upstream", other)
result = subprocess.run([sys.executable, str(TOOL), "--repo", self.directory.name, "--base", "upstream/main", "--fetch"], capture_output=True, text=True)
self.assertEqual(result.returncode, 0, result.stderr)
self.assertIn("merge: clean", result.stdout)
if __name__ == "__main__":
unittest.main()