Repository navigation
Preserve checkout paths during merge cleanup #1687
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8c05177
486f9a0
5ee1b37
09b9974
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3281,9 +3281,9 @@ def test_merged_bare_primary_cleans_only_clean_linked_worktree( | |
| if state == "dirty": | ||
| (linked / "README.md").write_text("uncommitted work\n") | ||
| original, cwds = cli._git, [] # #439: no cleanup git in a primary checkout | ||
| monkeypatch.setattr(cli, "_git", lambda cwd, *args: cwds.append(Path(cwd).resolve()) or ( | ||
| monkeypatch.setattr(cli, "_git", lambda cwd, *args, **kwargs: cwds.append(Path(cwd).resolve()) or ( | ||
| f"worktree {repo}\0" if state == "wrong_primary" and args == ("worktree", "list", "--porcelain", "-z") | ||
| else original(cwd, *args))) | ||
| else original(cwd, *args, **kwargs))) | ||
|
|
||
| code, out, err = run(capsys, "merge") | ||
| assert {primary.resolve(), repo.resolve()}.isdisjoint(cwds) | ||
|
|
@@ -3869,21 +3869,21 @@ def test_review_and_ready_refuse_closed_pr(wt: Path, gh: FakeGh, capsys) -> None | |
|
|
||
| @pytest.mark.parametrize("changed", [False, True]) | ||
| def test_merge_of_externally_merged_pr_verifies_sha_and_cleans_up( | ||
| wt: Path, repo: Path, gh: FakeGh, capsys, changed | ||
| wt: Path, repo: Path, gh: FakeGh, capsys, changed, monkeypatch | ||
| ) -> None: | ||
| arm_pr(gh, head_of(wt), state="MERGED", isDraft=False) | ||
| gh.append(f"api repos/{REPO}/pulls/7", merge_json(state='MERGED', head='f' * 40 if changed else head_of(wt), sha='e' * 40)) | ||
| gh.respond("api -X", "") | ||
| collision, wt = wt, wt.with_name(wt.name + " ") | ||
| git(repo, "worktree", "move", str(collision), str(wt)) | ||
| git(repo, "worktree", "add", "-qb", "lz/other", str(collision), "lz/t1") | ||
| monkeypatch.chdir(wt) | ||
| for branch, number in (("lz/t1", 7), ("lz/other", 8)): | ||
| arm_pr(gh, head_of(wt), branch=branch, number=number, state="MERGED", isDraft=False) | ||
| gh.append(f"api repos/{REPO}/pulls/{number}", merge_json(state='MERGED', head='f' * 40 if changed else head_of(wt), sha='e' * 40)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion: Rewritten test drops checks that no merge or deletion is attempted The old test asserted that no |
||
| code, out, err = run(capsys, "merge") | ||
| assert (code, collision.exists(), wt.exists()) == (int(changed), True, changed) | ||
| if changed: | ||
| assert code == 1 and "head changed" in err and wt.exists() | ||
| assert all(c["argv"][:2] != ["api", "-X"] for c in gh.calls) | ||
| return | ||
| assert (code, err) == (0, "") | ||
| assert out.splitlines()[-1] == "e" * 40 | ||
| assert f"PR #7 was already merged as {'e' * 12}" in out and "e" * 40 in out | ||
| assert not wt.exists() | ||
| assert all(c["argv"][:2] != ["pr", "merge"] for c in gh.calls) | ||
| assert "head changed" in err | ||
| else: | ||
| assert not err and f"PR #7 was already merged as {'e' * 12}" in out and out.endswith("e" * 40 + "\n") | ||
|
|
||
|
|
||
| def test_merge_queued_prints_and_keeps_worktree(wt: Path, gh: FakeGh, capsys, head) -> None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion:
cli._git(paths=True)copies the existing whitespace-preserving mode inworktree._gitworktree._git(..., preserve_whitespace=True)already decodes with the filesystem encoding and surrogateescape, and removes only the final newline. The newpaths=Trueflag incli._gitrepeats that decoding. It then makes each caller strip the newline itself:_topleveland the--git-common-dircall both use.removesuffix("\n"). This leaves two policies to keep in sync, and a future caller that forgetsremovesuffixgets a path ending in a newline. Smallest fix: makepaths=Truereturndone.stdout.removesuffix("\n"), the same aspreserve_whitespace, and drop the per-callerremovesuffix. The-zporcelain call isn't affected because it splits on NUL. Or route these calls through the shared worktree helper.