From 6f559437fe95b3a952b63b6672db7d89d0ce86c2 Mon Sep 17 00:00:00 2001 From: godosa Date: Wed, 7 Oct 2026 09:57:12 +0200 Subject: wf start: refuse worktree of another repo; .wf-home not stray Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01JEAjUkQRrCYX5MZhWxdtj2 --- wf.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'wf.py') diff --git a/wf.py b/wf.py index 7b5ae12..dda4914 100755 --- a/wf.py +++ b/wf.py @@ -1231,7 +1231,7 @@ def cmd_merge(args) -> int: bmain = config.git_top(cfg.root) or main # books repo: the private repo of a split project, else main private = [str(Path(x).resolve().relative_to(bmain.resolve())) for x in getattr(args, "private", None) or []] files = [str(f.relative_to(bmain)) for f in (cfg.tasks, cfg.archive)] + private - if git_run(top, "status", "--porcelain", "-uall").stdout.strip(): + if _dirty_outside(top, []): raise Failure("worktree has uncommitted changes: commit them first") had = unmerged_count(top, master) if not branch and not had: @@ -1326,6 +1326,8 @@ def _dirty_outside(top: Path, keep: list[Path]) -> list[str]: for line in git_run(top, "status", "--porcelain", "-uall").stdout.splitlines(): rel = line[3:].split(" -> ")[-1].strip('"').rstrip("/") path = (top / rel).resolve() + if rel == config.WF_HOME: # wf start's pointer in a code worktree, never committed + continue if not any(path == k or k in path.parents for k in keep): stray.append(rel) return stray @@ -1531,6 +1533,12 @@ def cmd_start(args) -> int: git_ok(repo, "worktree", "add", "-q", str(wt), "-b", b, master) how = f"new, branch {b} from {master}" else: + own = git_run(wt, "rev-parse", "--path-format=absolute", "--git-common-dir").stdout.strip() + want = git_run(repo, "rev-parse", "--path-format=absolute", "--git-common-dir").stdout.strip() + if not own or Path(own).resolve() != Path(want).resolve(): + raise Failure(f"{shown} is not a worktree of {repo}" + + (f" (it belongs to {Path(own).resolve().parent})" if own else "") + + f": pass a worktree path of {repo} (e.g. {repo}/.worktrees/)") dirty = git_run(wt, "status", "--porcelain").stdout.rstrip("\n") cur = config.git_branch(Path(git_run(wt, "rev-parse", "--absolute-git-dir").stdout.strip())) if dirty and not args.recovery: -- cgit