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 <noreply@anthropic.com>
This commit is contained in:
jaredandClaude Opus 5.5 committed 2026-11-12 14:53:17 -05:00
1 parent cdfe3ed1ef
commit 7783b6e78f
2 files changed
+24 -2

No files matched your search

+10 -2
View File
@@ -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:
+14
View File
@@ -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),