git-project-core-plugins 0.0.30__tar.gz → 0.0.32__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 (38) hide show
  1. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/PKG-INFO +37 -32
  2. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/_version.py +2 -2
  3. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/changelog.rst +36 -1
  4. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/requirements.txt +1 -1
  5. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/__init__.py +11 -11
  6. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/artifact.py +1 -1
  7. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/clone.py +1 -1
  8. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/init.py +1 -1
  9. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/worktree.py +117 -44
  10. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/conftest.py +8 -0
  11. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/test_artifact.py +10 -10
  12. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/test_worktree.py +270 -25
  13. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/.gitignore +0 -0
  14. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/COPYING +0 -0
  15. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/MANIFEST.in +0 -0
  16. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/Makefile +0 -0
  17. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/authors.rst +0 -0
  18. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/commands.rst +0 -0
  19. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/conf.py +0 -0
  20. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/index.rst +0 -0
  21. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/intro.rst +0 -0
  22. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/license.rst +0 -0
  23. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/docs/make.bat +0 -0
  24. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/hatch_build.py +0 -0
  25. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/pyproject.toml +0 -0
  26. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/_commanddocs.py +0 -0
  27. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/branch.py +0 -0
  28. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/common.py +0 -0
  29. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/config.py +0 -0
  30. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/help.py +0 -0
  31. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/src/git_project_core_plugins/run.py +0 -0
  32. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/common.py +0 -0
  33. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/test_branch.py +0 -0
  34. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/test_clone.py +0 -0
  35. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/test_config.py +0 -0
  36. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/test_help.py +0 -0
  37. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/tests/test_init.py +0 -0
  38. {git_project_core_plugins-0.0.30 → git_project_core_plugins-0.0.32}/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.0.30
3
+ Version: 0.0.32
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
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.10
14
14
  Classifier: Programming Language :: Python :: 3.11
15
15
  Classifier: Topic :: Software Development :: Version Control :: Git
16
16
  Requires-Python: >=3.10
17
- Requires-Dist: git-project>=0.0.42
17
+ Requires-Dist: git-project>=0.0.43
18
18
  Requires-Dist: pytest-console-scripts
19
19
  Provides-Extra: test
20
20
  Requires-Dist: git-project; extra == 'test'
@@ -53,11 +53,11 @@ Setup
53
53
 
54
54
  pip install git-project-core-plugins
55
55
 
56
- Worktree environment
57
- ====================
56
+ Umbrella layout
57
+ ===============
58
58
 
59
- A number of commands can have knowledge of a "worktree environment" with a
60
- specific layout::
59
+ A number of commands know about an "umbrella layout", where one directory,
60
+ the umbrella, holds a bare repository and its worktrees::
61
61
 
62
62
  <path>
63
63
  .<name>.git
@@ -69,16 +69,16 @@ specific layout::
69
69
  That is, either a bare clone is done, or an existing clone is converted to a
70
70
  bare clone via ``git <project> init --worktree``. The bare repository is the
71
71
  hidden ``.<name>.git`` child, named for the last component of the remote url,
72
- and ``<path>`` holds it alongside the worktrees. The ``.git`` beside it is a
72
+ and the umbrella ``<path>`` holds it alongside the worktrees. The ``.git`` beside it is a
73
73
  file holding ``gitdir: .<name>.git``, so git works from ``<path>`` too. It is
74
74
  a file, not a directory or a symlink, because a go build run from ``<path>``
75
75
  fails if ``.git`` resolves to a directory there. A repository that is already
76
- bare when ``init --worktree`` runs keeps its name and gets no ``.git`` file,
77
- and its parent directory holds the worktrees. Any conversion will abort if
78
- the worktree is dirty. Typically, an ordinary ``git clone`` is followed
79
- immediately by ``git <project> init --worktree``. A clone already in use, with
80
- its own branches and linked worktrees, is converted with ``git <project>
81
- worktree migrate`` instead, which keeps them all.
76
+ bare when ``init --worktree`` runs must be named ``.git``, and it is renamed
77
+ to the hidden name. Any conversion will abort if the worktree is dirty.
78
+ Typically, an ordinary ``git clone`` is followed immediately by ``git
79
+ <project> init --worktree``. A clone already in use, with its own branches and
80
+ linked worktrees, is converted with ``git <project> worktree migrate``
81
+ instead, which keeps them all.
82
82
 
83
83
  Either route also creates a worktree for the project's main branch, so the
84
84
  layout is usable straight away. The main branch is taken from the repository
@@ -260,7 +260,7 @@ the new repository. With no <path> it clones into the last component of
260
260
  authenticate.
261
261
 
262
262
  Plugins add options to clone. For example, the worktree command adds a
263
- --worktree option to have clone create a ``worktree layout``.
263
+ --worktree option to have clone create an ``umbrella layout``.
264
264
 
265
265
  See also::
266
266
 
@@ -359,7 +359,7 @@ project's ``branch`` to the main branch and its ``remote`` to origin,
359
359
  when they are not set already.
360
360
 
361
361
  Plugins add options to init. For example the worktree command adds a
362
- --worktree option to convert an existing local clone to a ``worktree
362
+ --worktree option to convert an existing local clone to an ``umbrella
363
363
  layout``.
364
364
 
365
365
  See also::
@@ -486,16 +486,19 @@ branch in it. The worktree's name is the last component of <name-or-path>.
486
486
  The branch is named after <name-or-path>: a simple name gives a branch of
487
487
  that name, and a relative path such as ``../user/topic`` gives
488
488
  ``user/topic``, the part after any ``..``. That branch is created at
489
- <committish>, or at HEAD, when it does not exist yet. An existing branch is
490
- checked out as it is, and <committish> is then ignored. With -b <branch>,
491
- the new branch <branch> is created at <committish> or HEAD and checked out
492
- instead.
489
+ <committish>, or at HEAD (the project branch, if there is one, when run
490
+ outside any worktree in the umbrella layout), when it does not exist yet.
491
+ An existing branch is checked out as it is, and <committish> is then
492
+ ignored. With -b <branch>, the new branch <branch> is created at
493
+ <committish> or that same default and checked out instead.
493
494
 
494
495
  A relative path that does not start with ``..`` is placed under the root of
495
496
  the current worktree, or under the current directory in a bare repository.
496
- A path that starts with ``..`` is taken from the current directory. So
497
- ``worktree add ../topic``, run in the main worktree, puts the new worktree
498
- beside it, and ``worktree add topic`` puts it inside.
497
+ In the umbrella layout, such a path is placed in the umbrella, wherever
498
+ the command runs. A path that starts with ``..`` is taken from the current
499
+ directory. So ``worktree add ../topic``, run in the main worktree of a
500
+ plain clone, puts the new worktree beside it, and ``worktree add topic``
501
+ puts it inside.
499
502
 
500
503
  To keep things simple, we'll usually always name worktrees similarly (or
501
504
  identically) to the branches they reference, though it is not strictly
@@ -559,10 +562,10 @@ git-project documentation describes the rule:
559
562
  https://pypi.org/project/git-project/
560
563
 
561
564
  The worktree plugin also adds a --worktree option to the clone and init
562
- commands. Both set up the ``worktree layout`` described in the package
565
+ commands. Both set up the ``umbrella layout`` described in the package
563
566
  documentation. The bare repository is a hidden child directory named for
564
567
  the last component of the remote url, such as ``.myrepo.git``. The
565
- top-level directory holds it alongside the worktrees.
568
+ umbrella holds it alongside the worktrees.
566
569
 
567
570
  ``clone --worktree`` clones bare, then rewrites the fetch refspec and sets
568
571
  the main branch to track its remote branch, so fetch and pull behave as
@@ -570,23 +573,25 @@ they do in a regular clone. The refs/heads and refs/remotes namespaces
570
573
  remain, and every other local branch is deleted. Add ``--bare`` to skip
571
574
  the refspec rewrite. The clone still gets the ``.git`` file and the main
572
575
  worktree. With no <path>, ``clone --worktree`` uses the current directory
573
- itself as the top-level directory, where a plain clone makes a new one.
576
+ itself as the umbrella, where a plain clone makes a new one.
574
577
 
575
578
  ``init --worktree`` converts an existing clone in place. The workarea must
576
- be clean. The conversion deletes every file in the top-level directory
577
- except the git directory, so preserve anything there that is not part of
578
- the repository. Only the main branch gets a worktree, so a different
579
+ be clean. The conversion deletes every file in the umbrella except the
580
+ git directory, so preserve anything there that is not part of the
581
+ repository. Only the main branch gets a worktree, so a different
579
582
  checked-out branch gets none, though one is easy to add afterward. To
580
583
  convert a clone you work in, with its branches and linked worktrees, use
581
584
  ``worktree migrate`` instead.
582
585
 
583
586
  On a repository that is already bare, ``init --worktree`` deletes nothing.
584
- It refuses to run while a branch other than the main one exists, because it
585
- cannot know which remote each branch should go to.
587
+ The repository must be named ``.git`` and have no linked worktrees, and it
588
+ is renamed to the hidden name. It refuses to run while a branch other than
589
+ the main one exists, because it cannot know which remote each branch
590
+ should go to.
586
591
 
587
592
  ``worktree migrate`` converts a flat clone, one whose ``.git`` is a
588
- directory, to the worktree layout. Every branch, ref, stash and config
589
- value stays. Each linked worktree moves into the top-level directory. The
593
+ directory, to the umbrella layout. Every branch, ref, stash and config
594
+ value stays. Each linked worktree moves into the umbrella. The
590
595
  files of the main worktree, ignored ones too, move into a worktree named
591
596
  for the main branch. Without ``--apply`` it prints each step and changes
592
597
  nothing.
@@ -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.0.30'
22
- __version_tuple__ = version_tuple = (0, 0, 30)
21
+ __version__ = version = '0.0.32'
22
+ __version_tuple__ = version_tuple = (0, 0, 32)
23
23
 
24
24
  __commit_id__ = commit_id = None
@@ -31,6 +31,39 @@ ChangeLog
31
31
  `Unreleased`_
32
32
  -------------
33
33
 
34
+ `0.0.32`_ - 2026-10-07
35
+ ----------------------
36
+ Changed
37
+ .......
38
+ - The docs, help text and error messages call the worktree layout the
39
+ umbrella layout, and its top-level directory the umbrella.
40
+ - ``init --worktree`` on a repository already bare at ``<top>/.git``
41
+ renames it to the hidden name and writes the ``.git`` file, as it does
42
+ for a regular clone. It refuses a bare repository with any other name,
43
+ or one with linked worktrees, which ``worktree migrate`` converts.
44
+
45
+ Fixed
46
+ .....
47
+ - In the umbrella layout, ``worktree add`` with a relative path that does
48
+ not start with ``..``, run inside a worktree, put the new worktree inside
49
+ that one. It now goes in the umbrella.
50
+ - Run from the umbrella with no committish, ``worktree add`` could branch
51
+ from the store's detached HEAD, which can fall behind. It now starts at
52
+ the project branch.
53
+ - ``worktree rm`` of a worktree that git-project did not create, such as
54
+ one made by plain ``git worktree add``, crashed and left a stray
55
+ ``worktreepath`` key in the config. It now fails with a message that
56
+ names the worktree and changes nothing.
57
+
58
+ `0.0.31`_ - 2026-10-07
59
+ ----------------------
60
+ Changed
61
+ .......
62
+ - core-plugins now needs git-project 0.0.43 or later. With it,
63
+ ``worktree rm`` and ``branch prune`` delete the remote branch on a
64
+ remote whose URL names a host alias from ``~/.ssh/config``. The delete
65
+ runs the ``pre-push`` hook.
66
+
34
67
  `0.0.30`_ - 2026-10-07
35
68
  ----------------------
36
69
  Added
@@ -203,7 +236,9 @@ Fixed
203
236
  404. Issues named ``unknown/greened``, a leftover from hatch's project
204
237
  template, and Documentation misspelled the package name.
205
238
 
206
- .. _Unreleased: https://github.com/greened/git-project-core-plugins/compare/v0.0.30...HEAD
239
+ .. _Unreleased: https://github.com/greened/git-project-core-plugins/compare/v0.0.32...HEAD
240
+ .. _0.0.32: https://github.com/greened/git-project-core-plugins/compare/v0.0.31...v0.0.32
241
+ .. _0.0.31: https://github.com/greened/git-project-core-plugins/compare/v0.0.30...v0.0.31
207
242
  .. _0.0.30: https://github.com/greened/git-project-core-plugins/compare/v0.0.29...v0.0.30
208
243
  .. _0.0.29: https://github.com/greened/git-project-core-plugins/compare/v0.0.28...v0.0.29
209
244
  .. _0.0.28: https://github.com/greened/git-project-core-plugins/compare/v0.0.27...v0.0.28
@@ -19,5 +19,5 @@
19
19
  # You should have received a copy of the GNU Affero General Public License along
20
20
  # with git-project. If not, see <https://www.gnu.org/licenses/>.
21
21
 
22
- git-project >= 0.0.42
22
+ git-project >= 0.0.43
23
23
  pytest-console-scripts
@@ -50,11 +50,11 @@ Setup
50
50
 
51
51
  pip install git-project-core-plugins
52
52
 
53
- Worktree environment
54
- ====================
53
+ Umbrella layout
54
+ ===============
55
55
 
56
- A number of commands can have knowledge of a "worktree environment" with a
57
- specific layout::
56
+ A number of commands know about an "umbrella layout", where one directory,
57
+ the umbrella, holds a bare repository and its worktrees::
58
58
 
59
59
  <path>
60
60
  .<name>.git
@@ -66,16 +66,16 @@ specific layout::
66
66
  That is, either a bare clone is done, or an existing clone is converted to a
67
67
  bare clone via ``git <project> init --worktree``. The bare repository is the
68
68
  hidden ``.<name>.git`` child, named for the last component of the remote url,
69
- and ``<path>`` holds it alongside the worktrees. The ``.git`` beside it is a
69
+ and the umbrella ``<path>`` holds it alongside the worktrees. The ``.git`` beside it is a
70
70
  file holding ``gitdir: .<name>.git``, so git works from ``<path>`` too. It is
71
71
  a file, not a directory or a symlink, because a go build run from ``<path>``
72
72
  fails if ``.git`` resolves to a directory there. A repository that is already
73
- bare when ``init --worktree`` runs keeps its name and gets no ``.git`` file,
74
- and its parent directory holds the worktrees. Any conversion will abort if
75
- the worktree is dirty. Typically, an ordinary ``git clone`` is followed
76
- immediately by ``git <project> init --worktree``. A clone already in use, with
77
- its own branches and linked worktrees, is converted with ``git <project>
78
- worktree migrate`` instead, which keeps them all.
73
+ bare when ``init --worktree`` runs must be named ``.git``, and it is renamed
74
+ to the hidden name. Any conversion will abort if the worktree is dirty.
75
+ Typically, an ordinary ``git clone`` is followed immediately by ``git
76
+ <project> init --worktree``. A clone already in use, with its own branches and
77
+ linked worktrees, is converted with ``git <project> worktree migrate``
78
+ instead, which keeps them all.
79
79
 
80
80
  Either route also creates a worktree for the project's main branch, so the
81
81
  layout is usable straight away. The main branch is taken from the repository
@@ -54,7 +54,7 @@ def _protected_paths(git):
54
54
  """Return the resolved paths that an artifact removal must not remove or
55
55
  contain: the root, the home directory and, inside a repository, the
56
56
  working copy and the git common dir. Protecting the common dir also
57
- protects a worktree container, which holds it.
57
+ protects an umbrella, which holds it.
58
58
 
59
59
  """
60
60
  protected = [Path("/"), Path.home()]
@@ -66,7 +66,7 @@ class ClonePlugin(Plugin):
66
66
  authenticate.
67
67
 
68
68
  Plugins add options to clone. For example, the worktree command adds a
69
- --worktree option to have clone create a ``worktree layout``.
69
+ --worktree option to have clone create an ``umbrella layout``.
70
70
 
71
71
  See also::
72
72
 
@@ -56,7 +56,7 @@ class InitPlugin(Plugin):
56
56
  when they are not set already.
57
57
 
58
58
  Plugins add options to init. For example the worktree command adds a
59
- --worktree option to convert an existing local clone to a ``worktree
59
+ --worktree option to convert an existing local clone to an ``umbrella
60
60
  layout``.
61
61
 
62
62
  See also::
@@ -48,9 +48,10 @@ from git_project_core_plugins.common import add_plugin_version_argument
48
48
 
49
49
 
50
50
  def normalize_path(git, path):
51
- """Find an appropriate repository-relative path. A relative path that does
52
- not start with '..' is placed under the current directory in a bare
53
- repository, and under the root of the current working copy otherwise. A
51
+ """Find an appropriate repository-relative path. In the umbrella layout, a
52
+ relative path that does not start with '..' is placed in the umbrella.
53
+ Otherwise it is placed under the current directory in a bare
54
+ repository, and under the root of the current working copy in any other. A
54
55
  path that starts with '..' is resolved from the current directory.
55
56
 
56
57
  path: A string path
@@ -59,9 +60,13 @@ def normalize_path(git, path):
59
60
  path = Path(path).expanduser()
60
61
 
61
62
  if not path.is_absolute() and path.parts[0] != "..":
63
+ umbrella = get_umbrella_dir(git)
64
+ if umbrella is not None:
65
+ # Worktrees go beside each other, never inside one.
66
+ path = umbrella / path
62
67
  # In a bare repository, put it under the current directory.
63
68
  # Otherwise put it under the root of the current working copy.
64
- if git.is_bare_repository():
69
+ elif git.is_bare_repository():
65
70
  path = Path.cwd() / path
66
71
  else:
67
72
  path = Path(git.get_working_copy_root()) / path
@@ -91,24 +96,44 @@ def get_hidden_gitdir_name(url: str):
91
96
  return "." + urlname
92
97
 
93
98
 
94
- # Without this the container is not a repository, so anything
99
+ # Without this the umbrella is not a repository, so anything
95
100
  # that stands there and asks git a question gets nothing. It
96
101
  # has to be a file. A symlink or a directory named ".git"
97
102
  # brings back the go problem the hidden name avoids, because
98
103
  # go's VCS search follows a ".git" that resolves to a
99
104
  # directory and then runs "git status" against a bare clone.
100
105
  # Go walks past a ".git" file, while git and pygit2 honour it.
101
- def write_container_gitdir(container: Path, gitdir_name: str):
102
- # Keep the pointer relative so the container still moves.
103
- (container / ".git").write_text(f"gitdir: {gitdir_name}\n")
106
+ def write_umbrella_gitdir(umbrella: Path, gitdir_name: str):
107
+ # Keep the pointer relative so the umbrella still moves.
108
+ (umbrella / ".git").write_text(_umbrella_gitdir_text(gitdir_name))
109
+
110
+
111
+ def _umbrella_gitdir_text(gitdir_name):
112
+ return f"gitdir: {gitdir_name}\n"
113
+
114
+
115
+ def get_umbrella_dir(git):
116
+ """Return the umbrella, which holds the store and its worktrees, or None
117
+ outside the umbrella layout. The umbrella is known by the .git file that write_umbrella_gitdir leaves beside the store.
118
+
119
+ """
120
+ store = Path(git.get_git_common_dir()).resolve()
121
+ gitfile = store.parent / ".git"
122
+ if gitfile.is_file() and gitfile.read_text() == _umbrella_gitdir_text(
123
+ store.name
124
+ ):
125
+ return store.parent
126
+ return None
104
127
 
105
128
 
106
129
  # Determine a path and committish from args.
107
- def get_name_branch_path_and_refname(git, gp, clargs):
130
+ def get_name_branch_path_and_refname(git, project, clargs):
108
131
  """Given a Project and worktree command-line arguments <name-or-path> and
109
132
  <committish>, determine an appropriate worktree name, a branch for the
110
133
  worktree, a path based on the name and refname based on the name. The
111
- path is required. With no <committish>, the refname is HEAD's.
134
+ path is required. With no <committish>, the refname is HEAD's. When
135
+ run from the umbrella, the refname is the project branch's, if there is
136
+ one.
112
137
 
113
138
  """
114
139
  if not getattr(clargs, "path", None):
@@ -137,6 +162,14 @@ def get_name_branch_path_and_refname(git, gp, clargs):
137
162
  # committish itself and let create_branch branch at that commit.
138
163
  ref = git.committish_to_ref(clargs.committish)
139
164
  refname = ref.name if ref is not None else clargs.committish
165
+ elif git.is_bare_repository() and get_umbrella_dir(git) is not None:
166
+ # The store's HEAD can stay detached where the layout was made,
167
+ # behind the project branch.
168
+ main = _find_main_branch(
169
+ git, project.get_section(), ["--git-dir", git.get_git_common_dir()]
170
+ )
171
+ if main is not None:
172
+ refname = git.branch_name_to_refname(main)
140
173
 
141
174
  return name, branch, path, refname
142
175
 
@@ -145,7 +178,7 @@ def get_name_branch_path_and_refname(git, gp, clargs):
145
178
  def command_worktree_add(git, gitproject, project, clargs):
146
179
  """Implement git-project worktree add."""
147
180
  name, newbranch, path, refname = get_name_branch_path_and_refname(
148
- git, gitproject, clargs
181
+ git, project, clargs
149
182
  )
150
183
 
151
184
  branch = git.refname_to_branch_name(refname)
@@ -175,6 +208,12 @@ def command_worktree_add(git, gitproject, project, clargs):
175
208
  def command_worktree_rm(git, gitproject, project, clargs):
176
209
  """Implement git-project worktree rm."""
177
210
  name = clargs.name
211
+ # Getting a Worktree with no config writes a path entry for it, so check
212
+ # first.
213
+ if not Worktree.exists(
214
+ git, project.get_section(), Worktree.subsection(), name
215
+ ):
216
+ raise GitProjectError(f"git-project has no record of worktree {name}")
178
217
  worktree = Worktree.get(git, project, name)
179
218
 
180
219
  # The merge check protects the branch's commits, so it applies only when we
@@ -1340,7 +1379,7 @@ def _apply(plan, main, git, project):
1340
1379
 
1341
1380
  step = "write_pointer"
1342
1381
  start(step)
1343
- write_container_gitdir(top, store_new.name)
1382
+ write_umbrella_gitdir(top, store_new.name)
1344
1383
  done(step)
1345
1384
 
1346
1385
  # repair finds each admin dir by the name in the worktree's .git
@@ -1470,7 +1509,7 @@ def _apply_bare_at_root(plan, git):
1470
1509
 
1471
1510
  step = "write_pointer"
1472
1511
  start(step)
1473
- write_container_gitdir(plan.top, store_new.name)
1512
+ write_umbrella_gitdir(plan.top, store_new.name)
1474
1513
  done(step)
1475
1514
 
1476
1515
  step = "repair"
@@ -1619,16 +1658,19 @@ class WorktreePlugin(Plugin):
1619
1658
  The branch is named after <name-or-path>: a simple name gives a branch of
1620
1659
  that name, and a relative path such as ``../user/topic`` gives
1621
1660
  ``user/topic``, the part after any ``..``. That branch is created at
1622
- <committish>, or at HEAD, when it does not exist yet. An existing branch is
1623
- checked out as it is, and <committish> is then ignored. With -b <branch>,
1624
- the new branch <branch> is created at <committish> or HEAD and checked out
1625
- instead.
1661
+ <committish>, or at HEAD (the project branch, if there is one, when run
1662
+ outside any worktree in the umbrella layout), when it does not exist yet.
1663
+ An existing branch is checked out as it is, and <committish> is then
1664
+ ignored. With -b <branch>, the new branch <branch> is created at
1665
+ <committish> or that same default and checked out instead.
1626
1666
 
1627
1667
  A relative path that does not start with ``..`` is placed under the root of
1628
1668
  the current worktree, or under the current directory in a bare repository.
1629
- A path that starts with ``..`` is taken from the current directory. So
1630
- ``worktree add ../topic``, run in the main worktree, puts the new worktree
1631
- beside it, and ``worktree add topic`` puts it inside.
1669
+ In the umbrella layout, such a path is placed in the umbrella, wherever
1670
+ the command runs. A path that starts with ``..`` is taken from the current
1671
+ directory. So ``worktree add ../topic``, run in the main worktree of a
1672
+ plain clone, puts the new worktree beside it, and ``worktree add topic``
1673
+ puts it inside.
1632
1674
 
1633
1675
  To keep things simple, we'll usually always name worktrees similarly (or
1634
1676
  identically) to the branches they reference, though it is not strictly
@@ -1692,10 +1734,10 @@ class WorktreePlugin(Plugin):
1692
1734
  https://pypi.org/project/git-project/
1693
1735
 
1694
1736
  The worktree plugin also adds a --worktree option to the clone and init
1695
- commands. Both set up the ``worktree layout`` described in the package
1737
+ commands. Both set up the ``umbrella layout`` described in the package
1696
1738
  documentation. The bare repository is a hidden child directory named for
1697
1739
  the last component of the remote url, such as ``.myrepo.git``. The
1698
- top-level directory holds it alongside the worktrees.
1740
+ umbrella holds it alongside the worktrees.
1699
1741
 
1700
1742
  ``clone --worktree`` clones bare, then rewrites the fetch refspec and sets
1701
1743
  the main branch to track its remote branch, so fetch and pull behave as
@@ -1703,23 +1745,25 @@ class WorktreePlugin(Plugin):
1703
1745
  remain, and every other local branch is deleted. Add ``--bare`` to skip
1704
1746
  the refspec rewrite. The clone still gets the ``.git`` file and the main
1705
1747
  worktree. With no <path>, ``clone --worktree`` uses the current directory
1706
- itself as the top-level directory, where a plain clone makes a new one.
1748
+ itself as the umbrella, where a plain clone makes a new one.
1707
1749
 
1708
1750
  ``init --worktree`` converts an existing clone in place. The workarea must
1709
- be clean. The conversion deletes every file in the top-level directory
1710
- except the git directory, so preserve anything there that is not part of
1711
- the repository. Only the main branch gets a worktree, so a different
1751
+ be clean. The conversion deletes every file in the umbrella except the
1752
+ git directory, so preserve anything there that is not part of the
1753
+ repository. Only the main branch gets a worktree, so a different
1712
1754
  checked-out branch gets none, though one is easy to add afterward. To
1713
1755
  convert a clone you work in, with its branches and linked worktrees, use
1714
1756
  ``worktree migrate`` instead.
1715
1757
 
1716
1758
  On a repository that is already bare, ``init --worktree`` deletes nothing.
1717
- It refuses to run while a branch other than the main one exists, because it
1718
- cannot know which remote each branch should go to.
1759
+ The repository must be named ``.git`` and have no linked worktrees, and it
1760
+ is renamed to the hidden name. It refuses to run while a branch other than
1761
+ the main one exists, because it cannot know which remote each branch
1762
+ should go to.
1719
1763
 
1720
1764
  ``worktree migrate`` converts a flat clone, one whose ``.git`` is a
1721
- directory, to the worktree layout. Every branch, ref, stash and config
1722
- value stays. Each linked worktree moves into the top-level directory. The
1765
+ directory, to the umbrella layout. Every branch, ref, stash and config
1766
+ value stays. Each linked worktree moves into the umbrella. The
1723
1767
  files of the main worktree, ignored ones too, move into a worktree named
1724
1768
  for the main branch. Without ``--apply`` it prints each step and changes
1725
1769
  nothing.
@@ -1930,7 +1974,11 @@ class WorktreePlugin(Plugin):
1930
1974
  "add",
1931
1975
  "worktree-add",
1932
1976
  help="Create a worktree",
1933
- epilog="The path is required. The committish defaults to HEAD.",
1977
+ epilog=(
1978
+ "The path is required. The committish defaults to HEAD, or, "
1979
+ "outside any worktree in the umbrella layout, to the project "
1980
+ "branch if there is one."
1981
+ ),
1934
1982
  )
1935
1983
 
1936
1984
  worktree_add_parser.set_defaults(func=command_worktree_add)
@@ -1978,7 +2026,7 @@ class WorktreePlugin(Plugin):
1978
2026
  worktree_subparser,
1979
2027
  "migrate",
1980
2028
  "worktree-migrate",
1981
- help="Convert a flat clone to the worktree layout",
2029
+ help="Convert a flat clone to the umbrella layout",
1982
2030
  )
1983
2031
 
1984
2032
  # A dry run must leave the config as it was.
@@ -1992,7 +2040,7 @@ class WorktreePlugin(Plugin):
1992
2040
  help="Make the changes, instead of only printing them",
1993
2041
  )
1994
2042
 
1995
- # add a clone option to create a worktree layout.
2043
+ # add a clone option to create a umbrella layout.
1996
2044
  clone_parser = parser_manager.find_parser("clone")
1997
2045
  if clone_parser:
1998
2046
  clone_parser.add_argument(
@@ -2001,7 +2049,7 @@ class WorktreePlugin(Plugin):
2001
2049
  help="Create a layout convenient for worktree use",
2002
2050
  )
2003
2051
 
2004
- # add an init option to create a worktree layout.
2052
+ # add an init option to create a umbrella layout.
2005
2053
  init_parser = parser_manager.find_parser("init")
2006
2054
  if init_parser:
2007
2055
  init_parser.add_argument(
@@ -2059,7 +2107,7 @@ class WorktreePlugin(Plugin):
2059
2107
  def _setup_main_worktree(
2060
2108
  self, main, p_git, p_gitproject, p_project, path, clargs
2061
2109
  ):
2062
- """Create a main woorktree for a newly-created worktree layout."""
2110
+ """Create a main worktree for a newly-created umbrella layout."""
2063
2111
  # Set up a main worktree.
2064
2112
  main_branch = p_git.refname_to_branch_name(main)
2065
2113
 
@@ -2109,7 +2157,7 @@ class WorktreePlugin(Plugin):
2109
2157
  if not main:
2110
2158
  main = self._choose_main_branch(p_git)
2111
2159
 
2112
- write_container_gitdir(Path(path).parent, Path(path).name)
2160
+ write_umbrella_gitdir(Path(path).parent, Path(path).name)
2113
2161
 
2114
2162
  # Detach HEAD so we can worktree main.
2115
2163
  p_git.detach_head()
@@ -2131,7 +2179,7 @@ class WorktreePlugin(Plugin):
2131
2179
 
2132
2180
  clone_parser.set_defaults(func=worktree_command_clone)
2133
2181
 
2134
- # If an init is done, set up a main worktree layout if told to.
2182
+ # If an init is done, set up an umbrella layout if told to.
2135
2183
  init_parser = parser_manager.find_parser("init")
2136
2184
  if init_parser:
2137
2185
  command_init = init_parser.get_default("func")
@@ -2152,16 +2200,38 @@ class WorktreePlugin(Plugin):
2152
2200
  p_git.get_remote_url(remote)
2153
2201
  except KeyError:
2154
2202
  raise GitProjectError(
2155
- f"Cannot initialize worktree layout, no remote named {remote}"
2203
+ f"Cannot initialize umbrella layout, no remote named {remote}"
2156
2204
  ) from None
2157
2205
 
2206
+ if was_bare:
2207
+ # The parent of a store with any other name is not
2208
+ # its own, and would become the umbrella.
2209
+ gitdir = Path(p_git.get_gitdir())
2210
+ if gitdir.name != ".git":
2211
+ raise GitProjectError(
2212
+ f"Cannot initialize umbrella layout, {gitdir} is not named .git"
2213
+ )
2214
+ # The rename below would strand them.
2215
+ admin = gitdir / "worktrees"
2216
+ if admin.is_dir() and os.listdir(admin):
2217
+ raise GitProjectError(
2218
+ f"Cannot initialize umbrella layout, {gitdir} has linked worktrees, use worktree migrate"
2219
+ )
2220
+ newgitdir = gitdir.parent / get_hidden_gitdir_name(
2221
+ p_git.get_remote_url(remote)
2222
+ )
2223
+ if os.path.lexists(newgitdir):
2224
+ raise GitProjectError(
2225
+ f"Cannot initialize umbrella layout, {newgitdir} already exists"
2226
+ )
2227
+
2158
2228
  main = self._choose_main_branch(p_git)
2159
2229
 
2160
2230
  # If it's not already, convert the current workarea to a bare repository.
2161
2231
  if not p_git.is_bare_repository():
2162
2232
  if not p_git.workarea_is_clean():
2163
2233
  raise GitProjectError(
2164
- "Cannot initialize worktree layout, working copy not clean"
2234
+ "Cannot initialize umbrella layout, working copy not clean"
2165
2235
  )
2166
2236
 
2167
2237
  gitdir = Path(p_git.get_gitdir())
@@ -2170,7 +2240,7 @@ class WorktreePlugin(Plugin):
2170
2240
 
2171
2241
  if gitdir != workarea_root / ".git":
2172
2242
  raise GitProjectError(
2173
- "Not creating worktree layout -- are you in a worktree?"
2243
+ "Not creating umbrella layout -- are you in a worktree?"
2174
2244
  )
2175
2245
 
2176
2246
  # Set bare and detach before removing files so they
@@ -2210,10 +2280,8 @@ class WorktreePlugin(Plugin):
2210
2280
  p_git.validate_config()
2211
2281
 
2212
2282
  # After the reinit, so discovery resolves the clone
2213
- # the same way it did before. The already-bare path
2214
- # below keeps its .git as the clone itself, so only
2215
- # the renamed case gets a pointer.
2216
- write_container_gitdir(workarea_root, newgitdir.name)
2283
+ # the same way it did before.
2284
+ write_umbrella_gitdir(workarea_root, newgitdir.name)
2217
2285
 
2218
2286
  if was_bare:
2219
2287
  workarea_root = Path(p_git.get_gitdir()).parent
@@ -2229,6 +2297,11 @@ class WorktreePlugin(Plugin):
2229
2297
  "Non-main branches detected, please push and/or delete them and try again."
2230
2298
  )
2231
2299
 
2300
+ gitdir.rename(newgitdir)
2301
+ p_git.reinit(newgitdir)
2302
+ p_git.validate_config()
2303
+ write_umbrella_gitdir(workarea_root, newgitdir.name)
2304
+
2232
2305
  newmain = self._rewrite_bare_refspects(p_git)
2233
2306
  assert newmain == main
2234
2307
 
@@ -36,6 +36,14 @@ from git_project_core_plugins.worktree import get_hidden_gitdir_name
36
36
  pytest_plugins = ["git_project.test_support"]
37
37
 
38
38
 
39
+ @pytest.fixture(autouse=True)
40
+ def no_user_git_config(monkeypatch):
41
+ # A remote delete runs git push, which would run the user's global
42
+ # pre-push hook.
43
+ monkeypatch.setenv("GIT_CONFIG_GLOBAL", "/dev/null")
44
+ monkeypatch.setenv("GIT_CONFIG_NOSYSTEM", "1")
45
+
46
+
39
47
  @pytest.fixture(scope="function")
40
48
  def worktree_parser_manager(request, git, gitproject, project, parser_manager):
41
49
  plugin = WorktreePlugin()
@@ -346,9 +346,9 @@ def test_artifact_remove_refuses_protected_paths(tmp_path, monkeypatch):
346
346
 
347
347
  from git_project_core_plugins.artifact import remove_artifact_path
348
348
 
349
- container = tmp_path / "container"
350
- common_dir = container / ".proj.git"
351
- workdir = container / "main"
349
+ umbrella = tmp_path / "umbrella"
350
+ common_dir = umbrella / ".proj.git"
351
+ workdir = umbrella / "main"
352
352
  home = tmp_path / "home"
353
353
  for d in (common_dir, workdir / "build", home / "cache"):
354
354
  d.mkdir(parents=True)
@@ -356,18 +356,18 @@ def test_artifact_remove_refuses_protected_paths(tmp_path, monkeypatch):
356
356
  git = _GuardGit(workdir, common_dir)
357
357
 
358
358
  # Each of these is a protected path or contains one.
359
- for path in (workdir, container, common_dir, home, tmp_path):
359
+ for path in (workdir, umbrella, common_dir, home, tmp_path):
360
360
  with pytest.raises(GitProjectError, match="Refusing to remove"):
361
361
  remove_artifact_path(str(path), git)
362
362
  assert path.exists()
363
363
 
364
364
  # A glob that matches a protected path is refused too, and removes
365
365
  # nothing, not even the matches that sort before the protected one.
366
- (container / "aaa").mkdir()
366
+ (umbrella / "aaa").mkdir()
367
367
  with pytest.raises(GitProjectError, match="Refusing to remove"):
368
- remove_artifact_path(f"{container}/*", git)
368
+ remove_artifact_path(f"{umbrella}/*", git)
369
369
  assert workdir.exists()
370
- assert (container / "aaa").exists()
370
+ assert (umbrella / "aaa").exists()
371
371
 
372
372
  # Inside a protected path is fine.
373
373
  remove_artifact_path(str(workdir / "build"), git)
@@ -383,10 +383,10 @@ def test_artifact_remove_resolves_relative_common_dir(tmp_path, monkeypatch):
383
383
 
384
384
  # Plain git worktree add writes a relative commondir, which git reads
385
385
  # relative to the worktree's own gitdir.
386
- container = tmp_path / "container"
387
- common_dir = container / ".proj.git"
386
+ umbrella = tmp_path / "umbrella"
387
+ common_dir = umbrella / ".proj.git"
388
388
  gitdir = common_dir / "worktrees" / "main"
389
- workdir = container / "main"
389
+ workdir = umbrella / "main"
390
390
  elsewhere = tmp_path / "elsewhere"
391
391
  for d in (gitdir, workdir, elsewhere):
392
392
  d.mkdir(parents=True)
@@ -37,9 +37,14 @@ import common
37
37
  import git_project
38
38
  import pygit2
39
39
  import pytest
40
+ from git_project.test_support.common import create_commit
40
41
 
41
42
  from git_project_core_plugins import Worktree, WorktreePlugin
42
- from git_project_core_plugins.worktree import _status_paths
43
+ from git_project_core_plugins.worktree import (
44
+ _status_paths,
45
+ get_hidden_gitdir_name,
46
+ get_umbrella_dir,
47
+ )
43
48
 
44
49
 
45
50
  def test_worktree_add_arguments(
@@ -196,14 +201,14 @@ def test_worktree_scope(
196
201
  assert project.builddir == "/path/to/test"
197
202
 
198
203
 
199
- def check_container_gitdir(container, hidden):
200
- """Assert the container points at the hidden clone with a .git file.
204
+ def check_umbrella_gitdir(umbrella, hidden):
205
+ """Assert the umbrella points at the hidden clone with a .git file.
201
206
 
202
207
  It has to be a file. A directory or a symlink named .git is what
203
- breaks a go build run from the container, which is the whole reason
208
+ breaks a go build run from the umbrella, which is the whole reason
204
209
  the clone is hidden in the first place.
205
210
  """
206
- gitfile = Path(container) / ".git"
211
+ gitfile = Path(umbrella) / ".git"
207
212
  assert gitfile.is_file()
208
213
  assert gitfile.read_text() == f"gitdir: {hidden}\n"
209
214
 
@@ -218,7 +223,7 @@ def test_worktree_clone(git_project_runner, remote_repository):
218
223
  assert os.path.exists(repo_path)
219
224
  assert os.path.exists("master")
220
225
 
221
- check_container_gitdir(Path.cwd(), repo_path.name)
226
+ check_umbrella_gitdir(Path.cwd(), repo_path.name)
222
227
 
223
228
 
224
229
  def test_worktree_clone_bare(git_project_runner, remote_repository):
@@ -231,7 +236,7 @@ def test_worktree_clone_bare(git_project_runner, remote_repository):
231
236
  assert os.path.exists(repo_path)
232
237
  assert os.path.exists("master")
233
238
 
234
- check_container_gitdir(Path.cwd(), repo_path.name)
239
+ check_umbrella_gitdir(Path.cwd(), repo_path.name)
235
240
 
236
241
 
237
242
  def test_worktree_clone_path(git_project_runner, remote_repository):
@@ -245,27 +250,27 @@ def test_worktree_clone_path(git_project_runner, remote_repository):
245
250
  assert os.path.exists(str(repo_path / hidden))
246
251
  assert os.path.exists(repo_path / "master")
247
252
 
248
- check_container_gitdir(repo_path, hidden)
253
+ check_umbrella_gitdir(repo_path, hidden)
249
254
 
250
255
 
251
- def test_worktree_clone_container_is_discoverable(
256
+ def test_worktree_clone_umbrella_is_discoverable(
252
257
  git_project_runner, remote_repository
253
258
  ):
254
- """Standing in the container has to answer, since that is the point."""
259
+ """Standing in the umbrella has to answer, since that is the point."""
255
260
  git_project_runner.run(
256
261
  ".*", "", "clone", "--worktree", remote_repository.path
257
262
  )
258
263
 
259
264
  hidden = f".{Path(remote_repository.path).name}.git"
260
- container = Path.cwd()
265
+ umbrella = Path.cwd()
261
266
 
262
267
  # pygit2 reaches the clone through the pointer file.
263
- found = pygit2.discover_repository(str(container))
268
+ found = pygit2.discover_repository(str(umbrella))
264
269
  assert found is not None
265
- assert Path(found).resolve() == (container / hidden).resolve()
270
+ assert Path(found).resolve() == (umbrella / hidden).resolve()
266
271
 
267
272
  # So does git-project's own view, which is what consumers use.
268
- os.chdir(container)
273
+ os.chdir(umbrella)
269
274
  git = git_project.Git()
270
275
  assert git.has_repo()
271
276
  assert git.is_bare_repository()
@@ -300,7 +305,97 @@ def test_worktree_init(git, git_project_runner, tmp_path_factory):
300
305
  assert not os.path.exists(workarea / "MergedRemote.txt")
301
306
  assert os.path.exists(workarea / "master")
302
307
 
303
- check_container_gitdir(workarea, hidden)
308
+ check_umbrella_gitdir(workarea, hidden)
309
+
310
+
311
+ def _bare_clone(git, path):
312
+ """Bare-clone the fixture to path, keeping only master, since init
313
+ refuses a bare repository with other branches.
314
+
315
+ """
316
+ url = "file://" + git.get_gitdir()
317
+ clone = git_project.Git()
318
+ clone.clone(url, path=str(path), bare=True)
319
+ repo = pygit2.Repository(str(path))
320
+ for name in list(repo.branches.local):
321
+ if name != "master":
322
+ repo.branches.delete(name)
323
+ return url
324
+
325
+
326
+ def test_worktree_init_bare(git, git_project_runner, tmp_path_factory):
327
+ top = tmp_path_factory.mktemp("bare-top")
328
+ url = _bare_clone(git, top / ".git")
329
+
330
+ os.chdir(top)
331
+ git_project_runner.chdir(top)
332
+
333
+ git_project_runner.run(".*", "", "init", "--worktree")
334
+
335
+ hidden = get_hidden_gitdir_name(url)
336
+
337
+ assert (top / hidden).is_dir()
338
+ assert os.path.exists(top / "master")
339
+
340
+ check_umbrella_gitdir(top, hidden)
341
+
342
+ common = subprocess.run(
343
+ ["git", "rev-parse", "--path-format=absolute", "--git-common-dir"],
344
+ cwd=top / "master",
345
+ capture_output=True,
346
+ text=True,
347
+ check=True,
348
+ ).stdout.strip()
349
+ assert Path(common) == top / hidden
350
+
351
+
352
+ def test_worktree_init_bare_not_dot_git(
353
+ git, git_project_runner, tmp_path_factory
354
+ ):
355
+ top = tmp_path_factory.mktemp("bare-top")
356
+ store = top / "repo.git"
357
+ _bare_clone(git, store)
358
+
359
+ os.chdir(store)
360
+ git_project_runner.chdir(store)
361
+ git_project_runner.expect_fail = True
362
+
363
+ git_project_runner.run(
364
+ "git-project: Cannot initialize umbrella layout, .*repo.git is not "
365
+ "named .git",
366
+ "",
367
+ "init",
368
+ "--worktree",
369
+ )
370
+
371
+ assert sorted(os.listdir(top)) == ["repo.git"]
372
+
373
+
374
+ def test_worktree_init_bare_linked_worktree(
375
+ git, git_project_runner, tmp_path_factory
376
+ ):
377
+ top = tmp_path_factory.mktemp("bare-top")
378
+ _bare_clone(git, top / ".git")
379
+ subprocess.run(
380
+ ["git", "worktree", "add", "-q", "--detach", str(top / "linked")],
381
+ cwd=top,
382
+ check=True,
383
+ )
384
+
385
+ os.chdir(top)
386
+ git_project_runner.chdir(top)
387
+ git_project_runner.expect_fail = True
388
+
389
+ git_project_runner.run(
390
+ "git-project: Cannot initialize umbrella layout, .* has linked "
391
+ "worktrees, use worktree migrate",
392
+ "",
393
+ "init",
394
+ "--worktree",
395
+ )
396
+
397
+ assert (top / ".git").is_dir()
398
+ assert sorted(os.listdir(top)) == [".git", "linked"]
304
399
 
305
400
 
306
401
  def test_worktree_init_nonclean(git, git_project_runner):
@@ -324,7 +419,7 @@ def test_worktree_init_nonclean(git, git_project_runner):
324
419
  git_project_runner.expect_fail = True
325
420
 
326
421
  git_project_runner.run(
327
- "git-project: Cannot initialize worktree layout, working copy not clean",
422
+ "git-project: Cannot initialize umbrella layout, working copy not clean",
328
423
  "",
329
424
  "init",
330
425
  "--worktree",
@@ -341,7 +436,7 @@ def test_worktree_init_no_remote(git, git_project_runner):
341
436
  git_project_runner.expect_fail = True
342
437
 
343
438
  git_project_runner.run(
344
- "git-project: Cannot initialize worktree layout, no remote named origin",
439
+ "git-project: Cannot initialize umbrella layout, no remote named origin",
345
440
  "",
346
441
  "init",
347
442
  "--worktree",
@@ -379,7 +474,7 @@ def test_worktree_init_main(git, git_project_runner, tmp_path_factory):
379
474
  git_project_runner.run(".*", "", "init", "--worktree")
380
475
 
381
476
  assert os.path.exists(workarea / f".{Path(clone_url).parent.name}.git")
382
- check_container_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
477
+ check_umbrella_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
383
478
  assert not os.path.exists(workarea / "MergedRemote.txt")
384
479
  assert os.path.exists(workarea / "main")
385
480
 
@@ -410,7 +505,7 @@ def test_worktree_init_main_master(git, git_project_runner, tmp_path_factory):
410
505
  git_project_runner.run(".*", "", "init", "--worktree")
411
506
 
412
507
  assert os.path.exists(workarea / f".{Path(clone_url).parent.name}.git")
413
- check_container_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
508
+ check_umbrella_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
414
509
  assert not os.path.exists(workarea / "MergedRemote.txt")
415
510
  # Prefer main over master.
416
511
  assert not os.path.exists(workarea / "master")
@@ -445,7 +540,7 @@ def test_worktree_init_nomain(git, git_project_runner, tmp_path_factory):
445
540
  git_project_runner.run(".*", "", "init", "--worktree")
446
541
 
447
542
  assert os.path.exists(workarea / f".{Path(clone_url).parent.name}.git")
448
- check_container_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
543
+ check_umbrella_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
449
544
  assert not os.path.exists(workarea / "MergedRemote.txt")
450
545
  assert not os.path.exists(workarea / "master")
451
546
  assert os.path.exists(workarea / "newmain")
@@ -484,7 +579,7 @@ def test_worktree_init_nomain_multi(git, git_project_runner, tmp_path_factory):
484
579
  )
485
580
 
486
581
  assert os.path.exists(workarea / f".{Path(clone_url).parent.name}.git")
487
- check_container_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
582
+ check_umbrella_gitdir(workarea, f".{Path(clone_url).parent.name}.git")
488
583
  assert not os.path.exists(workarea / "MergedRemote.txt")
489
584
  assert not os.path.exists(workarea / "master")
490
585
  assert os.path.exists(workarea / "newmain")
@@ -529,6 +624,113 @@ def test_worktree_add_subdir(git, git_project_runner, tmp_path_factory):
529
624
  assert git.get_current_branch() == "user/test2"
530
625
 
531
626
 
627
+ def _umbrella(runner, remote_repository):
628
+ runner.run(".*", "", "clone", "--worktree", remote_repository.path)
629
+ top = Path.cwd().resolve()
630
+ return SimpleNamespace(
631
+ top=top,
632
+ store=top / f".{Path(remote_repository.path).name}.git",
633
+ master=top / "master",
634
+ )
635
+
636
+
637
+ @pytest.mark.parametrize("cwd", ["", "master"])
638
+ def test_worktree_add_umbrella_relative_path(
639
+ git_project_runner, remote_repository, cwd
640
+ ):
641
+ u = _umbrella(git_project_runner, remote_repository)
642
+ git_project_runner.chdir(u.top / cwd)
643
+
644
+ git_project_runner.run(".*", "", "worktree", "add", "topic")
645
+
646
+ assert (u.top / "topic").is_dir()
647
+ assert not (u.master / "topic").exists()
648
+
649
+
650
+ def test_worktree_add_umbrella_starts_at_project_branch(
651
+ git_project_runner, remote_repository
652
+ ):
653
+ u = _umbrella(git_project_runner, remote_repository)
654
+ repo = pygit2.Repository(str(u.store))
655
+ assert repo.head_is_detached
656
+ old = repo.head.target
657
+ new = create_commit(repo, "refs/heads/master", [old], "Newer")
658
+
659
+ git_project_runner.run(".*", "", "worktree", "add", "topic")
660
+
661
+ assert repo.references["refs/heads/topic"].target == new
662
+
663
+
664
+ def test_worktree_add_umbrella_starts_at_configured_branch(
665
+ git_project_runner, remote_repository
666
+ ):
667
+ # A project branch other than master, so the default branch fallback
668
+ # cannot pass this test.
669
+ u = _umbrella(git_project_runner, remote_repository)
670
+ repo = pygit2.Repository(str(u.store))
671
+ pushed = repo.references["refs/remotes/origin/pushed"].target
672
+ assert pushed != repo.references["refs/heads/master"].target
673
+ store = str(u.store)
674
+ _out("--git-dir", store, "branch", "pushed", "origin/pushed")
675
+ _out(
676
+ "--git-dir",
677
+ store,
678
+ "config",
679
+ "--replace-all",
680
+ "project.branch",
681
+ "pushed",
682
+ )
683
+
684
+ git_project_runner.run(".*", "", "worktree", "add", "topic")
685
+
686
+ assert repo.references["refs/heads/topic"].target == pushed
687
+
688
+
689
+ def test_worktree_add_umbrella_absolute_path(
690
+ git_project_runner, remote_repository, tmp_path_factory
691
+ ):
692
+ u = _umbrella(git_project_runner, remote_repository)
693
+ target = tmp_path_factory.mktemp("elsewhere").resolve() / "topic"
694
+ git_project_runner.chdir(u.master)
695
+
696
+ git_project_runner.run(".*", "", "worktree", "add", str(target))
697
+
698
+ assert target.is_dir()
699
+ assert not (u.top / "topic").exists()
700
+ assert not (u.master / "topic").exists()
701
+
702
+
703
+ def test_worktree_add_umbrella_committish_wins(
704
+ git_project_runner, remote_repository
705
+ ):
706
+ u = _umbrella(git_project_runner, remote_repository)
707
+ repo = pygit2.Repository(str(u.store))
708
+ pushed = repo.references["refs/remotes/origin/pushed"].target
709
+ assert pushed != repo.references["refs/heads/master"].target
710
+
711
+ git_project_runner.run(
712
+ ".*", "", "worktree", "add", "topic", "origin/pushed"
713
+ )
714
+
715
+ assert repo.references["refs/heads/topic"].target == pushed
716
+
717
+
718
+ @pytest.mark.parametrize("cwd", ["", "master"])
719
+ def test_get_umbrella_dir(git_project_runner, remote_repository, cwd):
720
+ u = _umbrella(git_project_runner, remote_repository)
721
+ os.chdir(u.top / cwd)
722
+
723
+ assert get_umbrella_dir(git_project.Git()) == u.top
724
+
725
+
726
+ def test_get_umbrella_dir_outside_layout(git):
727
+ assert get_umbrella_dir(git) is None
728
+
729
+
730
+ def test_get_umbrella_dir_bare_outside_layout(bare_git):
731
+ assert get_umbrella_dir(bare_git) is None
732
+
733
+
532
734
  def test_worktree_rm(git, git_project_runner, tmp_path_factory):
533
735
  workarea = git.get_working_copy_root()
534
736
 
@@ -564,6 +766,49 @@ def test_worktree_rm(git, git_project_runner, tmp_path_factory):
564
766
  assert not git.committish_exists("user/test_rm")
565
767
 
566
768
 
769
+ def test_worktree_rm_unrecorded(git, git_project_runner, tmp_path_factory):
770
+ # A worktree made by plain git has no git-project config. rm must refuse
771
+ # it by name and must not write config for it.
772
+ workarea = git.get_working_copy_root()
773
+ path = workarea.parent / "user" / "test_rm_unrecorded"
774
+
775
+ subprocess.run(
776
+ [
777
+ "git",
778
+ "worktree",
779
+ "add",
780
+ "-q",
781
+ "-b",
782
+ "test_rm_unrecorded",
783
+ str(path),
784
+ ],
785
+ cwd=workarea,
786
+ check=True,
787
+ )
788
+
789
+ os.chdir(workarea)
790
+ git_project_runner.chdir(workarea)
791
+ git_project_runner.expect_fail = True
792
+
793
+ git_project_runner.run(
794
+ "git-project has no record of worktree test_rm_unrecorded",
795
+ "",
796
+ "worktree",
797
+ "rm",
798
+ "test_rm_unrecorded",
799
+ )
800
+
801
+ assert path.exists()
802
+ config = subprocess.run(
803
+ ["git", "config", "--list"],
804
+ cwd=workarea,
805
+ capture_output=True,
806
+ text=True,
807
+ check=True,
808
+ ).stdout
809
+ assert "test_rm_unrecorded" not in config
810
+
811
+
567
812
  def test_worktree_rm_unset_builddir(git, git_project_runner, tmp_path_factory):
568
813
  workarea = git.get_working_copy_root()
569
814
  os.chdir(workarea)
@@ -1321,7 +1566,7 @@ def test_worktree_migrate_apply(flat_clone, script_runner):
1321
1566
  result.stdout
1322
1567
  )
1323
1568
  assert builddir not in result.stdout
1324
- check_container_gitdir(top, fc.store.name)
1569
+ check_umbrella_gitdir(top, fc.store.name)
1325
1570
  store = str(fc.store)
1326
1571
  assert _out("--git-dir", store, "config", "--bool", "core.bare") == (
1327
1572
  "true\n"
@@ -1630,7 +1875,7 @@ def test_worktree_migrate_post_hook_fails(
1630
1875
  assert output.index(f"Migrated {fc.top}.") < output.index(message)
1631
1876
  assert shlex.join(command) not in output
1632
1877
  # The migration stands.
1633
- check_container_gitdir(fc.top, fc.store.name)
1878
+ check_umbrella_gitdir(fc.top, fc.store.name)
1634
1879
  manifest = json.loads((fc.store / "git-project-migrate.json").read_text())
1635
1880
  assert manifest["complete"] is True
1636
1881
  assert manifest["post"]["status"].startswith(error)
@@ -2059,7 +2304,7 @@ def _fail_write_pointer(monkeypatch, module):
2059
2304
  def failing_write(*args):
2060
2305
  raise OSError("injected write_pointer failure")
2061
2306
 
2062
- monkeypatch.setattr(module, "write_container_gitdir", failing_write)
2307
+ monkeypatch.setattr(module, "write_umbrella_gitdir", failing_write)
2063
2308
 
2064
2309
 
2065
2310
  def _fail_journal(step):
@@ -2341,7 +2586,7 @@ def test_worktree_migrate_bare_at_root_apply(
2341
2586
  result = _migrate(script_runner, top / cwd, "--apply")
2342
2587
 
2343
2588
  assert result.success, result.stdout + result.stderr
2344
- check_container_gitdir(top, fc.store.name)
2589
+ check_umbrella_gitdir(top, fc.store.name)
2345
2590
  store = str(fc.store)
2346
2591
  assert _out("--git-dir", store, "config", "--bool", "core.bare") == (
2347
2592
  "true\n"