git-project-core-plugins 0.1.2__tar.gz → 0.1.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/PKG-INFO +3 -1
  2. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/_version.py +2 -2
  3. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/changelog.rst +10 -1
  4. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/worktree.py +76 -22
  5. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_worktree.py +209 -0
  6. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/.gitignore +0 -0
  7. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/COPYING +0 -0
  8. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/MANIFEST.in +0 -0
  9. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/changelog.d/README.rst +0 -0
  10. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/changelog.py +0 -0
  11. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/Makefile +0 -0
  12. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/authors.rst +0 -0
  13. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/commands.rst +0 -0
  14. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/conf.py +0 -0
  15. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/contributing.rst +0 -0
  16. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/index.rst +0 -0
  17. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/intro.rst +0 -0
  18. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/license.rst +0 -0
  19. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/docs/make.bat +0 -0
  20. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/hatch_build.py +0 -0
  21. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/pyproject.toml +0 -0
  22. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/requirements.txt +0 -0
  23. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/__init__.py +0 -0
  24. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/_commanddocs.py +0 -0
  25. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/artifact.py +0 -0
  26. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/branch.py +0 -0
  27. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/clone.py +0 -0
  28. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/common.py +0 -0
  29. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/config.py +0 -0
  30. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/help.py +0 -0
  31. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/init.py +0 -0
  32. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/multirepo.py +0 -0
  33. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/src/git_project_core_plugins/run.py +0 -0
  34. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/common.py +0 -0
  35. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/conftest.py +0 -0
  36. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_artifact.py +0 -0
  37. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_branch.py +0 -0
  38. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_changelog.py +0 -0
  39. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_clone.py +0 -0
  40. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_config.py +0 -0
  41. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_help.py +0 -0
  42. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_init.py +0 -0
  43. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_multirepo.py +0 -0
  44. {git_project_core_plugins-0.1.2 → git_project_core_plugins-0.1.3}/tests/test_run.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: git-project-core-plugins
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: The extensible stupid project manager - core functionality
5
5
  Author-email: "David A. Greene" <dag@obbligato.org>
6
6
  License-Expression: AGPL-3.0-or-later
@@ -689,6 +689,8 @@ flags say. Removing a worktree whose branch is unmerged requires ``-f``,
689
689
  unless ``--keep-branch`` means the branch survives anyway. When <name> has
690
690
  no worktree record, as after an ``rm`` that stopped part way, ``worktree
691
691
  rm`` removes each path record that names <name> and changes nothing else.
692
+ When the worktree record of <name> has no path, it removes that record and
693
+ each path record that names <name>, and again changes nothing else.
692
694
 
693
695
  With ``--check``, ``worktree add`` and ``worktree rm`` make the checks
694
696
  they would make before changing anything, report the result and change
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
18
18
  commit_id: str | None
19
19
  __commit_id__: str | None
20
20
 
21
- __version__ = version = '0.1.2'
22
- __version_tuple__ = version_tuple = (0, 1, 2)
21
+ __version__ = version = '0.1.3'
22
+ __version_tuple__ = version_tuple = (0, 1, 3)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -31,6 +31,14 @@ ChangeLog
31
31
  `Unreleased`_
32
32
  -------------
33
33
 
34
+ `0.1.3`_ - 2026-11-17
35
+ ---------------------
36
+ Fixed
37
+ .....
38
+ - ``Worktree.rm`` now leaves a branch alone on every remote when the local branch is gone, since a remote may hold the only copy of its commits. Before, it raised ``NotFoundError`` or deleted the remote copies, depending on the project's other branches.
39
+ - ``worktree rm -f <name>`` now removes a worktree whose branch is gone, and leaves the branch alone on every remote, saying so. Without ``-f`` or ``--keep-branch`` it fails with a one-line error that names the branch. Before, both stopped with a traceback.
40
+ - ``worktree rm <name>`` now removes the worktree record of ``<name>`` when that record has no path, as after an ``rm`` that stopped part way through the record's keys, along with each path record that names ``<name>``. It changes no other config and removes no files or branches. Before, it failed with a ``TypeError`` and left both records in place. With ``--multirepo`` it does so only when the record still names the set, and otherwise stops with an error.
41
+
34
42
  `0.1.2`_ - 2026-10-22
35
43
  ---------------------
36
44
  Changed
@@ -298,7 +306,8 @@ Fixed
298
306
  404. Issues named ``unknown/greened``, a leftover from hatch's project
299
307
  template, and Documentation misspelled the package name.
300
308
 
301
- .. _Unreleased: https://github.com/greened/git-project-core-plugins/compare/v0.1.2...HEAD
309
+ .. _Unreleased: https://github.com/greened/git-project-core-plugins/compare/v0.1.3...HEAD
310
+ .. _0.1.3: https://github.com/greened/git-project-core-plugins/compare/v0.1.2...v0.1.3
302
311
  .. _0.1.2: https://github.com/greened/git-project-core-plugins/compare/v0.1.1...v0.1.2
303
312
  .. _0.1.1: https://github.com/greened/git-project-core-plugins/compare/v0.1.0...v0.1.1
304
313
  .. _0.1.0: https://github.com/greened/git-project-core-plugins/compare/v0.0.33...v0.1.0
@@ -481,10 +481,24 @@ def _plan_worktree_rm(git, project, clargs):
481
481
  # --keep-remote-branch still deletes the local branch, so it still applies.
482
482
  # The record holds the branch name, and a tag of that name would win.
483
483
  refname = git.branch_name_to_refname(worktree.committish)
484
+ if not keep_branch and not git.committish_exists(refname):
485
+ if not clargs.force:
486
+ raise GitProjectError(
487
+ f"Worktree branch {worktree.committish} does not exist, "
488
+ "use -f or --keep-branch to remove the worktree"
489
+ )
490
+ # The remote branch may now hold the only copy of the commits.
491
+ keep_branch = True
492
+ check = getattr(clargs, "check", False)
493
+ kept = "would be kept" if check else "are kept"
494
+ print(
495
+ f"Branch {worktree.committish} no longer exists locally, so any "
496
+ f"copies on remotes {kept}"
497
+ )
484
498
  if (
485
499
  not keep_branch
486
- and not project.branch_is_merged(refname)
487
500
  and not clargs.force
501
+ and not project.branch_is_merged(refname)
488
502
  ):
489
503
  raise GitProjectError(
490
504
  f"Worktree branch {worktree.committish} is not merged, use -f to force"
@@ -505,32 +519,66 @@ def _plan_worktree_rm(git, project, clargs):
505
519
  def command_worktree_rm(git, gitproject, project, clargs):
506
520
  """Implement git-project worktree rm."""
507
521
  name = clargs.name
522
+ multirepo = getattr(clargs, "multirepo", None)
523
+ check = getattr(clargs, "check", False)
524
+ record = None
525
+ orphans = []
508
526
  # A path record can outlive its worktree record, as when an rm stops
509
527
  # between its two section removals. Remove such a record, config only.
510
528
  # With --multirepo, refuse, since the record that names the set is gone.
511
- if getattr(clargs, "multirepo", None) is None and not Worktree.exists(
529
+ if not Worktree.exists(
512
530
  git, project.get_section(), Worktree.subsection(), name
513
531
  ):
514
- orphans = _path_sections_naming(git, project, name)
515
- if orphans:
516
- check = getattr(clargs, "check", False)
517
- for section, path in orphans:
518
- if check:
519
- print(
520
- f"Would remove the orphan path record {section}, "
521
- f"and keep the worktree directory {path}"
522
- )
523
- else:
524
- _rm_config_section(git, section)
525
- print(
526
- f"Removed the orphan path record {section}, and "
527
- f"kept the worktree directory {path}"
528
- )
529
- return
532
+ if multirepo is None:
533
+ orphans = _path_sections_naming(git, project, name)
534
+ else:
535
+ worktree = Worktree.get(git, project, name)
536
+ project.pop_scope()
537
+ # An rm that stops partway through the worktree record's keys can
538
+ # leave a record with no path. Such a record cannot vouch for a
539
+ # directory, so remove the config only. With --multirepo, the
540
+ # record must still name the set, as for any other rm.
541
+ if not _record_values(git, worktree, "path"):
542
+ if multirepo is not None and _record_values(
543
+ git, worktree, "multirepo"
544
+ ) != [multirepo]:
545
+ raise GitProjectError(
546
+ f"The record of worktree {name} has no path and does "
547
+ f"not name multirepo set {multirepo}. Run worktree rm "
548
+ f"{name} in this repository, outside multirepo, to "
549
+ f"remove it"
550
+ )
551
+ record = worktree.get_section()
552
+ orphans = _path_sections_naming(git, project, name)
553
+ if record is not None or orphans:
554
+ if record is not None:
555
+ if check:
556
+ print(
557
+ f"Would remove the worktree record {record}, which has "
558
+ f"no path"
559
+ )
560
+ else:
561
+ _rm_config_section(git, record)
562
+ print(
563
+ f"Removed the worktree record {record}, which had no path"
564
+ )
565
+ for section, path in orphans:
566
+ if check:
567
+ print(
568
+ f"Would remove the orphan path record {section}, "
569
+ f"and keep the worktree directory {path}"
570
+ )
571
+ else:
572
+ _rm_config_section(git, section)
573
+ print(
574
+ f"Removed the orphan path record {section}, and "
575
+ f"kept the worktree directory {path}"
576
+ )
577
+ return
530
578
 
531
579
  keep_branch = _plan_worktree_rm(git, project, clargs)
532
580
 
533
- if getattr(clargs, "check", False):
581
+ if check:
534
582
  print(f"Would remove worktree {name}")
535
583
  return
536
584
 
@@ -714,12 +762,16 @@ class Worktree(ScopedConfigObject):
714
762
 
715
763
  project = Project.get(self._git, self._project_section)
716
764
 
717
- if not keep_branch:
765
+ # With the local branch gone, the remote branch may hold the only copy
766
+ # of the commits.
767
+ if not keep_branch and self._git.committish_exists(
768
+ self._git.branch_name_to_refname(committish)
769
+ ):
718
770
  for branch in project.iterbranches():
719
771
  if branch not in self._git.iterbranches():
720
772
  continue
721
- branch_name = self._git.committish_to_refname(branch)
722
- committish_name = self._git.committish_to_refname(committish)
773
+ branch_name = self._git.branch_name_to_refname(branch)
774
+ committish_name = self._git.branch_name_to_refname(committish)
723
775
  if branch_name == committish_name:
724
776
  break
725
777
  else:
@@ -2028,6 +2080,8 @@ class WorktreePlugin(Plugin):
2028
2080
  unless ``--keep-branch`` means the branch survives anyway. When <name> has
2029
2081
  no worktree record, as after an ``rm`` that stopped part way, ``worktree
2030
2082
  rm`` removes each path record that names <name> and changes nothing else.
2083
+ When the worktree record of <name> has no path, it removes that record and
2084
+ each path record that names <name>, and again changes nothing else.
2031
2085
 
2032
2086
  With ``--check``, ``worktree add`` and ``worktree rm`` make the checks
2033
2087
  they would make before changing anything, report the result and change
@@ -3330,6 +3330,30 @@ def test_worktree_rm_multirepo_deletes_a_branch_it_created(
3330
3330
  assert not (workarea / "wt-d").exists()
3331
3331
 
3332
3332
 
3333
+ def test_worktree_rm_keeps_the_remote_branch_when_local_is_gone(
3334
+ git, gitproject, project, monkeypatch
3335
+ ):
3336
+ # This test pushes, so it reaches a pre-push hook. Ignore the user's git
3337
+ # configuration to keep it hermetic.
3338
+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", "/dev/null")
3339
+ monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
3340
+
3341
+ _add(git, gitproject, project, "../wt-p")
3342
+ git_project.capture_command("git push origin wt-p:refs/heads/wt-p")
3343
+ assert git.remote_branch_exists("wt-p", "origin")
3344
+ # Deleted by hand, as a user might outside git-project.
3345
+ repo = pygit2.Repository(git.get_git_common_dir())
3346
+ repo.references.delete("refs/heads/wt-p")
3347
+
3348
+ # Worktree.rm directly, since the rm command stops before this case.
3349
+ worktree = Worktree.get(git, project, "wt-p")
3350
+ project.pop_scope()
3351
+ worktree.rm()
3352
+
3353
+ assert _record(git, "wt-p") == {}
3354
+ assert git.remote_branch_exists("wt-p", "origin")
3355
+
3356
+
3333
3357
  def _path_records(git):
3334
3358
  """Return each path record on disk, as path -> worktree name."""
3335
3359
  config = pygit2.Config(str(Path(git.get_git_common_dir()) / "config"))
@@ -3476,6 +3500,104 @@ def test_worktree_rm_skips_a_multivalued_path_record(git, gitproject, project):
3476
3500
  assert _repo_state(git) == before
3477
3501
 
3478
3502
 
3503
+ def test_worktree_rm_removes_a_record_with_no_path(
3504
+ git, gitproject, project, capsys
3505
+ ):
3506
+ workarea = _base()
3507
+ _add(git, gitproject, project, "../wt-keep")
3508
+ _add(git, gitproject, project, "../wt-p")
3509
+ path = str(workarea / "wt-p")
3510
+ # As an rm that stopped part way through the worktree record's keys.
3511
+ git.config.rm_items("project.worktree.wt-p", "path")
3512
+ assert "committish" in _record(git, "wt-p")
3513
+ repo = pygit2.Repository(git.get_git_common_dir())
3514
+ refs = sorted(repo.references)
3515
+ worktrees = sorted(repo.list_worktrees())
3516
+
3517
+ command_worktree_rm(git, gitproject, project, _rm_clargs("wt-p"))
3518
+
3519
+ out = capsys.readouterr().out
3520
+ assert "Removed the worktree record project.worktree.wt-p" in out
3521
+ assert f"Removed the orphan path record project.worktreepath.{path}" in out
3522
+ assert _record(git, "wt-p") == {}
3523
+ assert _path_records(git) == {str(workarea / "wt-keep"): "wt-keep"}
3524
+ # Config only, so the directory, the branch and git's worktree stay.
3525
+ assert (workarea / "wt-p").is_dir()
3526
+ repo = pygit2.Repository(git.get_git_common_dir())
3527
+ assert sorted(repo.references) == refs
3528
+ assert sorted(repo.list_worktrees()) == worktrees
3529
+
3530
+ with pytest.raises(git_project.GitProjectError) as error:
3531
+ command_worktree_rm(git, gitproject, project, _rm_clargs("wt-p"))
3532
+ assert "git-project has no record of worktree wt-p" in error.value.message
3533
+
3534
+
3535
+ def test_worktree_rm_check_keeps_a_record_with_no_path(
3536
+ git, gitproject, project, capsys
3537
+ ):
3538
+ _add(git, gitproject, project, "../wt-p")
3539
+ git.config.rm_items("project.worktree.wt-p", "path")
3540
+ before = _repo_state(git)
3541
+
3542
+ command_worktree_rm(
3543
+ git, gitproject, project, _rm_clargs("wt-p", check=True)
3544
+ )
3545
+
3546
+ assert (
3547
+ "Would remove the worktree record project.worktree.wt-p"
3548
+ in capsys.readouterr().out
3549
+ )
3550
+ assert _repo_state(git) == before
3551
+
3552
+
3553
+ def test_worktree_rm_multirepo_removes_a_record_with_no_path(
3554
+ git, gitproject, project, capsys
3555
+ ):
3556
+ workarea = _base()
3557
+ _add(git, gitproject, project, "../wt-p", multirepo="tools")
3558
+ git.config.rm_items("project.worktree.wt-p", "path")
3559
+ repo = pygit2.Repository(git.get_git_common_dir())
3560
+ refs = sorted(repo.references)
3561
+
3562
+ command_worktree_rm(
3563
+ git, gitproject, project, _rm_clargs("wt-p", multirepo="tools")
3564
+ )
3565
+
3566
+ assert (
3567
+ "Removed the worktree record project.worktree.wt-p"
3568
+ in capsys.readouterr().out
3569
+ )
3570
+ assert _record(git, "wt-p") == {}
3571
+ assert _path_records(git) == {}
3572
+ assert (workarea / "wt-p").is_dir()
3573
+ repo = pygit2.Repository(git.get_git_common_dir())
3574
+ assert sorted(repo.references) == refs
3575
+
3576
+
3577
+ @pytest.mark.parametrize("multirepo", [None, "other"])
3578
+ def test_worktree_rm_multirepo_refuses_a_record_with_no_path(
3579
+ git, gitproject, project, multirepo
3580
+ ):
3581
+ _add(git, gitproject, project, "../wt-p", multirepo="tools")
3582
+ git.config.rm_items("project.worktree.wt-p", "path")
3583
+ if multirepo is None:
3584
+ git.config.rm_items("project.worktree.wt-p", "multirepo")
3585
+ else:
3586
+ git.config.set_item("project.worktree.wt-p", "multirepo", multirepo)
3587
+ before = _repo_state(git)
3588
+
3589
+ with pytest.raises(git_project.GitProjectError) as error:
3590
+ command_worktree_rm(
3591
+ git, gitproject, project, _rm_clargs("wt-p", multirepo="tools")
3592
+ )
3593
+
3594
+ assert (
3595
+ "has no path and does not name multirepo set tools"
3596
+ in error.value.message
3597
+ )
3598
+ assert _repo_state(git) == before
3599
+
3600
+
3479
3601
  def test_worktree_rm_removes_both_records(git, gitproject, project):
3480
3602
  workarea = _base()
3481
3603
  _add(git, gitproject, project, "../wt-a")
@@ -3534,6 +3656,93 @@ def test_worktree_rm_check_changes_nothing(git, gitproject, project):
3534
3656
  assert _repo_state(git) == before
3535
3657
 
3536
3658
 
3659
+ def _drop_branch(git, name):
3660
+ """Delete a branch ref by hand, as a user might outside git-project."""
3661
+ repo = pygit2.Repository(git.get_git_common_dir())
3662
+ repo.references.delete(f"refs/heads/{name}")
3663
+
3664
+
3665
+ def test_worktree_rm_force_removes_a_worktree_whose_branch_is_gone(
3666
+ git, gitproject, project
3667
+ ):
3668
+ workarea = _base()
3669
+ _add(git, gitproject, project, "../wt-g")
3670
+ _drop_branch(git, "wt-g")
3671
+
3672
+ command_worktree_rm(
3673
+ git, gitproject, project, _rm_clargs("wt-g", force=True)
3674
+ )
3675
+
3676
+ assert _record(git, "wt-g") == {}
3677
+ assert _path_records(git) == {}
3678
+ assert not (workarea / "wt-g").exists()
3679
+ repo = pygit2.Repository(git.get_git_common_dir())
3680
+ assert "wt-g" not in repo.list_worktrees()
3681
+
3682
+
3683
+ def test_worktree_rm_force_keeps_the_remote_branch_when_local_is_gone(
3684
+ git, gitproject, project, monkeypatch, capsys
3685
+ ):
3686
+ # This test pushes, so it reaches a pre-push hook. Ignore the user's git
3687
+ # configuration to keep it hermetic.
3688
+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", "/dev/null")
3689
+ monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
3690
+
3691
+ _add(git, gitproject, project, "../wt-p")
3692
+ # The remote copy may now hold the only copy of the commits.
3693
+ git_project.capture_command("git push origin wt-p:refs/heads/wt-p")
3694
+ assert git.remote_branch_exists("wt-p", "origin")
3695
+ _drop_branch(git, "wt-p")
3696
+ capsys.readouterr()
3697
+
3698
+ command_worktree_rm(
3699
+ git, gitproject, project, _rm_clargs("wt-p", force=True)
3700
+ )
3701
+
3702
+ assert (
3703
+ "Branch wt-p no longer exists locally, so any copies on remotes are "
3704
+ "kept" in capsys.readouterr().out
3705
+ )
3706
+ assert _record(git, "wt-p") == {}
3707
+ assert git.remote_branch_exists("wt-p", "origin")
3708
+
3709
+
3710
+ def test_worktree_rm_check_force_says_remote_copies_would_be_kept(
3711
+ git, gitproject, project, capsys
3712
+ ):
3713
+ _add(git, gitproject, project, "../wt-c")
3714
+ _drop_branch(git, "wt-c")
3715
+ before = _repo_state(git)
3716
+ capsys.readouterr()
3717
+
3718
+ command_worktree_rm(
3719
+ git, gitproject, project, _rm_clargs("wt-c", force=True, check=True)
3720
+ )
3721
+
3722
+ assert (
3723
+ "Branch wt-c no longer exists locally, so any copies on remotes "
3724
+ "would be kept" in capsys.readouterr().out
3725
+ )
3726
+ assert _repo_state(git) == before
3727
+
3728
+
3729
+ def test_worktree_rm_refuses_a_worktree_whose_branch_is_gone(
3730
+ git, gitproject, project
3731
+ ):
3732
+ _add(git, gitproject, project, "../wt-g")
3733
+ _drop_branch(git, "wt-g")
3734
+ before = _repo_state(git)
3735
+
3736
+ with pytest.raises(
3737
+ git_project.GitProjectError,
3738
+ match="Worktree branch wt-g does not exist, "
3739
+ "use -f or --keep-branch to remove the worktree",
3740
+ ):
3741
+ command_worktree_rm(git, gitproject, project, _rm_clargs("wt-g"))
3742
+
3743
+ assert _repo_state(git) == before
3744
+
3745
+
3537
3746
  def test_worktree_menu_hints(git, git_project_runner, script_runner):
3538
3747
  workarea = git.get_working_copy_root()
3539
3748
  os.chdir(workarea)