From 7783b6e78f4e43a6717eea21db903ee8ce619905 Mon Sep 17 00:00:00 2001 From: Jared Knowles Date: Thu, 12 Nov 2026 14:53:17 -0500 Subject: [PATCH] fix: checkout_new works on git 2.39 git before 2.43 reads a revision after --end-of-options in checkout as a pathspec, so every drafting run in node:22 failed with 'Cannot update paths and switch to branch'. Option-like values are refused instead and a trailing -- keeps rev a revision. The suite passes in node:22 (git 2.39.5, Python 3.11.2): 185 tests. Co-Authored-By: Claude Opus 5.5 --- docs_review/git.py | 12 ++++++++++-- tests/test_git.py | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/docs_review/git.py b/docs_review/git.py index f2398c4..0daefd6 100644 --- a/docs_review/git.py +++ b/docs_review/git.py @@ -43,8 +43,16 @@ def run(args: list[str], cwd: Path, extra_env: Mapping[str, str] | None = None) def checkout_new(branch: str, rev: str, cwd: Path) -> None: - """Create or reset branch at rev and switch to it.""" - run(["checkout", "-q", "-B", branch, EOO, rev], cwd) + """Create or reset branch at rev and switch to it. + + git before 2.43 reads a revision after --end-of-options in checkout as a pathspec + ("Cannot update paths and switch to branch"), and node:22 ships 2.39. So an + option-like branch or rev is refused here instead, and the trailing -- keeps rev a + revision.""" + for value in (branch, rev): + if not value or value.startswith("-"): + raise GitError(f"refusing to check out {value!r}") + run(["checkout", "-q", "-B", branch, rev, "--"], cwd) def merge(rev: str, author: tuple[str, str], cwd: Path) -> None: diff --git a/tests/test_git.py b/tests/test_git.py index 6600475..cef3300 100644 --- a/tests/test_git.py +++ b/tests/test_git.py @@ -49,6 +49,20 @@ class TestGit(unittest.TestCase): call() self.assertFalse(out.exists()) + def test_checkout_new_creates_branch_at_rev(self): + git.checkout_new("docs-review/pr-3", "HEAD~1", self.repo) + self.assertEqual(git.run(["rev-parse", "--abbrev-ref", "HEAD"], self.repo).strip(), + "docs-review/pr-3") + self.assertEqual(git.run(["rev-parse", "HEAD"], self.repo).strip(), + git.run(["rev-parse", "main~1"], self.repo).strip()) + + def test_checkout_new_refuses_option_like_values(self): + out = Path(self._tmp.name) / "x" + for branch, rev in (("b", f"--output={out}"), ("-b", "HEAD"), ("b", "")): + with self.assertRaises(git.GitError): + git.checkout_new(branch, rev, self.repo) + self.assertFalse(out.exists()) + def test_merge_base_and_ls_files(self): head = git.run(["rev-parse", "HEAD"], self.repo).strip() self.assertEqual(git.merge_base("HEAD", "HEAD~1", self.repo),