Compare commits

...

1 Commits

Author SHA1 Message Date
Daiyan Alamgir a1dee7c657 fix: reject branch names where any path component ends with .lock
E2E UI Tests / setup (push) Has been cancelled
E2E UI Tests / E2E UI Tests (shard ${{ matrix.shard_id }}/${{ matrix.num_shards }}) (push) Has been cancelled
E2E Tests / setup (push) Has been cancelled
E2E Tests / E2E Tests (shard ${{ matrix.shard_id }}/${{ matrix.num_shards }}) (push) Has been cancelled
git check-ref-format forbids .lock on any component of a ref path,
not just the final segment. The previous check only tested
name.endswith(".lock"), so a name like "x.lock/y" slipped through
validation and would fail at git worktree add time with an opaque
error instead of the friendly WorktreeError.

Fix by splitting on "/" and checking every component.

Add "x.lock/y" to the parametrize list in test_validate_branch_name_rejects_bad
to cover this case explicitly.

Signed-off-by: Daiyan Alamgir <daiyan.alamgir@gmail.com>
2026-06-15 06:30:05 -04:00
2 changed files with 15 additions and 3 deletions
+2 -2
View File
@@ -60,8 +60,8 @@ def validate_branch_name(name: str) -> None:
raise WorktreeError(f"branch name must not start or end with '/': {name!r}")
if name.endswith("."):
raise WorktreeError(f"branch name must not end with '.': {name!r}")
if name.endswith(".lock"):
raise WorktreeError(f"branch name must not end with '.lock': {name!r}")
if any(part.endswith(".lock") for part in name.split("/")):
raise WorktreeError(f"branch name path components must not end with '.lock': {name!r}")
if ".." in name:
raise WorktreeError(f"branch name must not contain '..': {name!r}")
if "//" in name:
+13 -1
View File
@@ -317,7 +317,19 @@ def test_remove_worktree_missing_path_fails(git_repo: Path) -> None:
@pytest.mark.parametrize(
"bad",
["", "-leading", "a..b", "a/.hidden", "x.lock", "a b", "a~b", "a:b", "/lead", "trail/"],
[
"",
"-leading",
"a..b",
"a/.hidden",
"x.lock",
"x.lock/y",
"a b",
"a~b",
"a:b",
"/lead",
"trail/",
],
)
def test_validate_branch_name_rejects_bad(bad: str) -> None:
"""Branch names violating git ref-format are rejected before reaching argv."""