git-project 0.0.41__tar.gz → 0.0.42__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.
- {git_project-0.0.41 → git_project-0.0.42}/PKG-INFO +24 -20
- {git_project-0.0.41 → git_project-0.0.42}/_version.py +2 -2
- {git_project-0.0.41 → git_project-0.0.42}/docs/changelog.rst +28 -1
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/main.py +10 -2
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/plugin.py +12 -1
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/project.py +34 -8
- git_project-0.0.42/tests/test_main.py +125 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_project.py +51 -0
- git_project-0.0.41/tests/test_main.py +0 -61
- {git_project-0.0.41 → git_project-0.0.42}/.gitignore +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/CONTRIBUTORS +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/COPYING +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/MANIFEST.in +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/Makefile +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/api.rst +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/authors.rst +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/conf.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/contributing.rst +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/index.rst +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/intro.rst +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/license.rst +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/make.bat +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/docs/plugins.rst +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/pyproject.toml +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/requirements.txt +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/__init__.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/commandline.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/configobj.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/exception.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/git.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/gitproject.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/parsermanager.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/pluginmanager.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/py.typed +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/runnable.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/scopedobj.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/shell.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/substitutable.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/test_support/__init__.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/src/git_project/test_support/common.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/conftest.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_confobj.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_git.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_gitproject.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_parsermanager.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_runnable.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_scopedobj.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_shell.py +0 -0
- {git_project-0.0.41 → git_project-0.0.42}/tests/test_substitutable.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: git-project
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.42
|
|
4
4
|
Summary: The extensible stupid project manager
|
|
5
5
|
Author-email: "David A. Greene" <dag@obbligato.org>
|
|
6
6
|
License-Expression: AGPL-3.0-or-later
|
|
@@ -214,30 +214,34 @@ Authors
|
|
|
214
214
|
.. _David Greene: https://github.com/greened
|
|
215
215
|
|
|
216
216
|
|
|
217
|
-
`0.0.
|
|
217
|
+
`0.0.42`_ - 2026-10-06
|
|
218
218
|
----------------------
|
|
219
|
-
|
|
219
|
+
Added
|
|
220
|
+
.....
|
|
221
|
+
- A command can set ``write_project_defaults=False`` on its parser, so that
|
|
222
|
+
git-project does not write the project's default ``branch`` and
|
|
223
|
+
``remote`` to the config. A dry run can then leave the config as it was.
|
|
224
|
+
- ``Project.get`` takes ``set_defaults``, True by default. With False, it
|
|
225
|
+
does not write the defaults.
|
|
226
|
+
|
|
227
|
+
Changed
|
|
220
228
|
.......
|
|
221
|
-
-
|
|
222
|
-
|
|
223
|
-
|
|
229
|
+
- git-project writes the project defaults after the command line is
|
|
230
|
+
parsed, not when it builds the project. So ``-h``, ``--version``,
|
|
231
|
+
``--menu`` and a command-line error no longer write them. The plugin
|
|
232
|
+
hooks ``add_class_hooks``, ``add_arguments`` and ``modify_arguments``
|
|
233
|
+
can see a project without its default branch and remote.
|
|
224
234
|
|
|
225
235
|
Fixed
|
|
226
236
|
.....
|
|
227
|
-
- ``
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
Before, any expression in braces ran, so a value from an included config
|
|
236
|
-
file could run code. Now only ``{name}`` is replaced, and an expression
|
|
237
|
-
such as ``{x.replace(...)}`` stays as written. A value may now contain
|
|
238
|
-
``'``, and a backslash in a value stays as written.
|
|
239
|
-
|
|
240
|
-
.. _Unreleased: https://github.com/greened/git-project/compare/v0.0.41...HEAD
|
|
237
|
+
- ``branch prune``, ``worktree rm`` and ``Project.prune_branch`` stopped
|
|
238
|
+
and kept the local branch when a remote could not be reached, such as
|
|
239
|
+
one whose URL names a host alias from ``~/.ssh/config``, which libgit2
|
|
240
|
+
does not read, or when a remote refused the delete. They now warn about
|
|
241
|
+
that remote on stderr and delete the local branch.
|
|
242
|
+
|
|
243
|
+
.. _Unreleased: https://github.com/greened/git-project/compare/v0.0.42...HEAD
|
|
244
|
+
.. _0.0.42: https://github.com/greened/git-project/compare/v0.0.41...v0.0.42
|
|
241
245
|
.. _0.0.41: https://github.com/greened/git-project/compare/v0.0.40...v0.0.41
|
|
242
246
|
.. _0.0.40: https://github.com/greened/git-project/compare/v0.0.39...v0.0.40
|
|
243
247
|
.. _0.0.39: https://github.com/greened/git-project/compare/v0.0.38...v0.0.39
|
|
@@ -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.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 0,
|
|
21
|
+
__version__ = version = '0.0.42'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 0, 42)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -31,6 +31,32 @@ ChangeLog
|
|
|
31
31
|
`Unreleased`_
|
|
32
32
|
-------------
|
|
33
33
|
|
|
34
|
+
`0.0.42`_ - 2026-10-06
|
|
35
|
+
----------------------
|
|
36
|
+
Added
|
|
37
|
+
.....
|
|
38
|
+
- A command can set ``write_project_defaults=False`` on its parser, so that
|
|
39
|
+
git-project does not write the project's default ``branch`` and
|
|
40
|
+
``remote`` to the config. A dry run can then leave the config as it was.
|
|
41
|
+
- ``Project.get`` takes ``set_defaults``, True by default. With False, it
|
|
42
|
+
does not write the defaults.
|
|
43
|
+
|
|
44
|
+
Changed
|
|
45
|
+
.......
|
|
46
|
+
- git-project writes the project defaults after the command line is
|
|
47
|
+
parsed, not when it builds the project. So ``-h``, ``--version``,
|
|
48
|
+
``--menu`` and a command-line error no longer write them. The plugin
|
|
49
|
+
hooks ``add_class_hooks``, ``add_arguments`` and ``modify_arguments``
|
|
50
|
+
can see a project without its default branch and remote.
|
|
51
|
+
|
|
52
|
+
Fixed
|
|
53
|
+
.....
|
|
54
|
+
- ``branch prune``, ``worktree rm`` and ``Project.prune_branch`` stopped
|
|
55
|
+
and kept the local branch when a remote could not be reached, such as
|
|
56
|
+
one whose URL names a host alias from ``~/.ssh/config``, which libgit2
|
|
57
|
+
does not read, or when a remote refused the delete. They now warn about
|
|
58
|
+
that remote on stderr and delete the local branch.
|
|
59
|
+
|
|
34
60
|
`0.0.41`_ - 2026-10-06
|
|
35
61
|
----------------------
|
|
36
62
|
Removed
|
|
@@ -177,7 +203,8 @@ Fixed
|
|
|
177
203
|
``git_project``. No declared environment supplied Sphinx either, so a
|
|
178
204
|
``docs`` environment with Sphinx is now declared.
|
|
179
205
|
|
|
180
|
-
.. _Unreleased: https://github.com/greened/git-project/compare/v0.0.
|
|
206
|
+
.. _Unreleased: https://github.com/greened/git-project/compare/v0.0.42...HEAD
|
|
207
|
+
.. _0.0.42: https://github.com/greened/git-project/compare/v0.0.41...v0.0.42
|
|
181
208
|
.. _0.0.41: https://github.com/greened/git-project/compare/v0.0.40...v0.0.41
|
|
182
209
|
.. _0.0.40: https://github.com/greened/git-project/compare/v0.0.39...v0.0.40
|
|
183
210
|
.. _0.0.39: https://github.com/greened/git-project/compare/v0.0.38...v0.0.39
|
|
@@ -30,12 +30,15 @@ does the work, in this order:
|
|
|
30
30
|
file for repeated entries.
|
|
31
31
|
#. Take the active project's name from the program name, with any ``git-``
|
|
32
32
|
prefix removed.
|
|
33
|
-
#. Build the active Project.
|
|
33
|
+
#. Build the active Project, without its defaults.
|
|
34
34
|
#. Load the plugins and call each one's ``add_class_hooks``, which receives
|
|
35
35
|
the project.
|
|
36
36
|
#. Build the GitProject, now that the class hooks are in place.
|
|
37
37
|
#. Parse the command line. Every plugin's ``add_arguments`` runs, then every
|
|
38
38
|
plugin's ``modify_arguments``. See git_project.commandline.
|
|
39
|
+
#. Write the project's missing defaults, branch and remote, unless the
|
|
40
|
+
chosen command set ``write_project_defaults`` to False. See
|
|
41
|
+
Project.set_defaults.
|
|
39
42
|
#. Call each plugin's ``initialize``.
|
|
40
43
|
#. Call the chosen command's ``func(git, gitproject, project, clargs)``.
|
|
41
44
|
#. Check the config file again, and return what ``func`` returned.
|
|
@@ -70,7 +73,8 @@ def main_impl(args=None):
|
|
|
70
73
|
|
|
71
74
|
plugin_manager = git_project.PluginManager()
|
|
72
75
|
|
|
73
|
-
|
|
76
|
+
# Only the parsed command knows whether it may write the config.
|
|
77
|
+
project = git_project.Project.get(git, project_name, set_defaults=False)
|
|
74
78
|
|
|
75
79
|
plugin_manager.load_plugins(git, project)
|
|
76
80
|
|
|
@@ -81,6 +85,10 @@ def main_impl(args=None):
|
|
|
81
85
|
git, gp, project, plugin_manager, args
|
|
82
86
|
)
|
|
83
87
|
|
|
88
|
+
# Before initialize, which may read them.
|
|
89
|
+
if getattr(clargs, "write_project_defaults", True):
|
|
90
|
+
project.set_defaults()
|
|
91
|
+
|
|
84
92
|
plugin_manager.initialize_plugins(git, gp, project)
|
|
85
93
|
|
|
86
94
|
rc = clargs.func(git, gp, project, clargs)
|
|
@@ -81,7 +81,9 @@ plugin before the next hook:
|
|
|
81
81
|
this hook.
|
|
82
82
|
#. ``add_arguments``. Add commands and options.
|
|
83
83
|
#. ``modify_arguments``. Change what other plugins added.
|
|
84
|
-
#. The command line is parsed
|
|
84
|
+
#. The command line is parsed, and the project's missing defaults are
|
|
85
|
+
written unless the command opts out (see Commands). Until then, a
|
|
86
|
+
project read can miss its default branch and remote.
|
|
85
87
|
#. ``initialize``. Set up state, such as pushing a scope.
|
|
86
88
|
#. The chosen command's function runs.
|
|
87
89
|
|
|
@@ -102,6 +104,15 @@ GitProject for the repository, project is the active Project and clargs is
|
|
|
102
104
|
the parsed command line. An int return is the exit status. Any other return
|
|
103
105
|
exits with 0.
|
|
104
106
|
|
|
107
|
+
Before a command runs, git-project writes the project's ``branch`` and
|
|
108
|
+
``remote`` to the config when they are unset. A command that must not
|
|
109
|
+
write the config, such as a dry run, opts out::
|
|
110
|
+
|
|
111
|
+
parser.set_defaults(write_project_defaults=False)
|
|
112
|
+
|
|
113
|
+
The command then sees no default branch or remote unless the config has
|
|
114
|
+
one.
|
|
115
|
+
|
|
105
116
|
A plugin extends another plugin's command in ``modify_arguments``. Find its
|
|
106
117
|
parser by key with ``parser_manager.find_parser(key)``, add options to it,
|
|
107
118
|
and wrap its function::
|
|
@@ -22,6 +22,11 @@
|
|
|
22
22
|
# with git-project. If not, see <https://www.gnu.org/licenses/>.
|
|
23
23
|
|
|
24
24
|
|
|
25
|
+
import sys
|
|
26
|
+
|
|
27
|
+
import pygit2
|
|
28
|
+
|
|
29
|
+
from .exception import GitProjectError
|
|
25
30
|
from .git import Git
|
|
26
31
|
from .scopedobj import ScopedConfigObject
|
|
27
32
|
|
|
@@ -38,8 +43,8 @@ class Project(ScopedConfigObject):
|
|
|
38
43
|
it, so reading a project attribute gives the value from the topmost scope
|
|
39
44
|
that has it. See git_project.scopedobj.
|
|
40
45
|
|
|
41
|
-
|
|
42
|
-
|
|
46
|
+
get sets the default branch and remote when they are missing, unless
|
|
47
|
+
set_defaults is False. See set_defaults.
|
|
43
48
|
|
|
44
49
|
"""
|
|
45
50
|
|
|
@@ -60,10 +65,8 @@ class Project(ScopedConfigObject):
|
|
|
60
65
|
"""
|
|
61
66
|
super().__init__(git, section, subsection, ident, **kwargs)
|
|
62
67
|
|
|
63
|
-
self.set_defaults()
|
|
64
|
-
|
|
65
68
|
@classmethod
|
|
66
|
-
def get(cls, git, section, **kwargs):
|
|
69
|
+
def get(cls, git, section, set_defaults=True, **kwargs):
|
|
67
70
|
"""A factory to construct the active project from its git config.
|
|
68
71
|
|
|
69
72
|
cls: The derived class being constructed.
|
|
@@ -73,10 +76,14 @@ class Project(ScopedConfigObject):
|
|
|
73
76
|
section: The project name. It is mapped to a git config section name, so
|
|
74
77
|
'.' and '_' become '-'.
|
|
75
78
|
|
|
79
|
+
set_defaults: Whether to call set_defaults, which may write the config.
|
|
80
|
+
|
|
76
81
|
kwargs: Keyword arguments of property values to set upon construction.
|
|
77
82
|
|
|
78
83
|
"""
|
|
79
84
|
project = super().get(git, section, None, None, **kwargs)
|
|
85
|
+
if set_defaults:
|
|
86
|
+
project.set_defaults()
|
|
80
87
|
return project
|
|
81
88
|
|
|
82
89
|
def set_defaults(self):
|
|
@@ -204,7 +211,9 @@ class Project(ScopedConfigObject):
|
|
|
204
211
|
|
|
205
212
|
def prune_branch(self, branch, keep_remote_branch=False):
|
|
206
213
|
"""Delete a branch locally and, unless keep_remote_branch is set, on any
|
|
207
|
-
remotes on which it exists.
|
|
214
|
+
remotes on which it exists. A remote that cannot be reached, or that
|
|
215
|
+
refuses the delete, gets a warning, and the local branch is deleted
|
|
216
|
+
anyway.
|
|
208
217
|
|
|
209
218
|
branch: The branch to delete.
|
|
210
219
|
|
|
@@ -213,8 +222,25 @@ class Project(ScopedConfigObject):
|
|
|
213
222
|
|
|
214
223
|
"""
|
|
215
224
|
if not keep_remote_branch:
|
|
225
|
+
# Raise a bad ssh.id here, so the handler below cannot report it
|
|
226
|
+
# as a remote refusal.
|
|
227
|
+
self._git.get_ssh_id()
|
|
216
228
|
for remote in self.iterremotes():
|
|
217
|
-
|
|
218
|
-
|
|
229
|
+
# A remote failure must not stop the local delete. libgit2
|
|
230
|
+
# does not read ~/.ssh/config, so a host alias there does not
|
|
231
|
+
# resolve.
|
|
232
|
+
try:
|
|
233
|
+
if self._git.remote_branch_exists(branch, remote):
|
|
234
|
+
self._git.delete_remote_branch(branch, remote)
|
|
235
|
+
except pygit2.GitError:
|
|
236
|
+
# The error may hold the URL, so it is not printed.
|
|
237
|
+
print(
|
|
238
|
+
f"warning: cannot reach remote {remote} to check or "
|
|
239
|
+
f"delete {branch}",
|
|
240
|
+
file=sys.stderr,
|
|
241
|
+
)
|
|
242
|
+
except GitProjectError as error:
|
|
243
|
+
# The remote refused the delete, and says why.
|
|
244
|
+
print(f"warning: {remote}: {error}", file=sys.stderr)
|
|
219
245
|
if self._git.committish_exists(branch):
|
|
220
246
|
self._git.delete_branch(Git.refname_to_branch_name(branch))
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
#
|
|
3
|
+
# SPDX-FileCopyrightText: 2020-present David A. Greene <dag@obbligato.org>
|
|
4
|
+
|
|
5
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
+
|
|
7
|
+
# Copyright 2024 David A. Greene
|
|
8
|
+
|
|
9
|
+
# This file is part of git-project
|
|
10
|
+
|
|
11
|
+
# git-project is free software: you can redistribute it and/or modify it under
|
|
12
|
+
# the terms of the GNU Affero General Public License as published by the Free
|
|
13
|
+
# Software Foundation, either version 3 of the License, or (at your option) any
|
|
14
|
+
# later version.
|
|
15
|
+
|
|
16
|
+
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
17
|
+
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
18
|
+
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
19
|
+
# details.
|
|
20
|
+
|
|
21
|
+
# You should have received a copy of the GNU Affero General Public License along
|
|
22
|
+
# with git-project. If not, see <https://www.gnu.org/licenses/>.
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
import pytest
|
|
26
|
+
|
|
27
|
+
import git_project
|
|
28
|
+
from git_project.test_support import check_config_file
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_main_no_dup(reset_directory, git, project):
|
|
32
|
+
project._git.validate_config()
|
|
33
|
+
|
|
34
|
+
project._git.validate_config()
|
|
35
|
+
git_project.main_impl(["config", "branch"])
|
|
36
|
+
|
|
37
|
+
project.build = "devrel"
|
|
38
|
+
|
|
39
|
+
project._git.validate_config()
|
|
40
|
+
git_project.main_impl(["config", "branch"])
|
|
41
|
+
|
|
42
|
+
project.add_item("build", "check-devrel")
|
|
43
|
+
|
|
44
|
+
project._git.validate_config()
|
|
45
|
+
git_project.main_impl(["config", "branch"])
|
|
46
|
+
|
|
47
|
+
check_config_file("project", "build", {"devrel", "check-devrel"})
|
|
48
|
+
|
|
49
|
+
project._git.validate_config()
|
|
50
|
+
git_project.main_impl(["config", "branch"])
|
|
51
|
+
|
|
52
|
+
check_config_file("project", "build", {"devrel", "check-devrel"})
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_main_help_shows_summary(reset_directory, git, capsys):
|
|
56
|
+
with pytest.raises(SystemExit):
|
|
57
|
+
git_project.main_impl(["--help"])
|
|
58
|
+
|
|
59
|
+
out = capsys.readouterr().out
|
|
60
|
+
assert "git <project> <command> [<options>]" in out
|
|
61
|
+
assert "The name git-project runs under selects the active project." in out
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class _DefaultsPlugin(git_project.Plugin):
|
|
65
|
+
"""Adds 'look', which may write the defaults, and 'peek', which may not."""
|
|
66
|
+
|
|
67
|
+
def __init__(self):
|
|
68
|
+
super().__init__("defaults")
|
|
69
|
+
self.branch_at_initialize = None
|
|
70
|
+
|
|
71
|
+
def initialize(self, git, gitproject, project, plugin_manager):
|
|
72
|
+
self.branch_at_initialize = project.has_item("branch")
|
|
73
|
+
|
|
74
|
+
def add_arguments(
|
|
75
|
+
self, git, gitproject, project, parser_manager, plugin_manager
|
|
76
|
+
):
|
|
77
|
+
look = git_project.add_top_level_command(
|
|
78
|
+
parser_manager, "look", "look"
|
|
79
|
+
)
|
|
80
|
+
look.set_defaults(func=lambda *args: 0)
|
|
81
|
+
peek = git_project.add_top_level_command(
|
|
82
|
+
parser_manager, "peek", "peek"
|
|
83
|
+
)
|
|
84
|
+
peek.set_defaults(func=lambda *args: 0, write_project_defaults=False)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@pytest.fixture
|
|
88
|
+
def defaults_plugin(monkeypatch):
|
|
89
|
+
plugin = _DefaultsPlugin()
|
|
90
|
+
|
|
91
|
+
def load_plugins(self, git, project):
|
|
92
|
+
self.plugins.append(plugin)
|
|
93
|
+
|
|
94
|
+
monkeypatch.setattr(
|
|
95
|
+
git_project.PluginManager, "load_plugins", load_plugins
|
|
96
|
+
)
|
|
97
|
+
monkeypatch.setattr("sys.argv", ["git-project"])
|
|
98
|
+
return plugin
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.mark.parametrize("command, written", [("look", True), ("peek", False)])
|
|
102
|
+
def test_main_project_defaults(
|
|
103
|
+
reset_directory, git, defaults_plugin, command, written
|
|
104
|
+
):
|
|
105
|
+
assert not git.config.has_item("project", "branch")
|
|
106
|
+
assert not git.config.has_item("project", "remote")
|
|
107
|
+
|
|
108
|
+
git_project.main_impl([command])
|
|
109
|
+
|
|
110
|
+
config = git_project.Git().config
|
|
111
|
+
assert config.has_item("project", "branch") == written
|
|
112
|
+
assert config.has_item("project", "remote") == written
|
|
113
|
+
if written:
|
|
114
|
+
assert config.get_item("project", "branch") == "master"
|
|
115
|
+
assert config.get_item("project", "remote") == "origin"
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
def test_main_project_defaults_before_initialize(
|
|
119
|
+
reset_directory, git, defaults_plugin
|
|
120
|
+
):
|
|
121
|
+
assert not git.config.has_item("project", "branch")
|
|
122
|
+
|
|
123
|
+
git_project.main_impl(["look"])
|
|
124
|
+
|
|
125
|
+
assert defaults_plugin.branch_at_initialize is True
|
|
@@ -208,3 +208,54 @@ def test_project_branch_is_pushed_indirectly(project):
|
|
|
208
208
|
|
|
209
209
|
def test_project_branch_is_merged_indirectly(project):
|
|
210
210
|
assert project.branch_is_merged("pushed_indirectly")
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
def test_project_prune_branch_unreachable_remote(
|
|
214
|
+
reset_directory, remote_repository, tmp_path_factory, capsys
|
|
215
|
+
):
|
|
216
|
+
project = clone_with_pushed_branch(remote_repository, tmp_path_factory)
|
|
217
|
+
missing = tmp_path_factory.mktemp("missing") / "none.git"
|
|
218
|
+
project._git.config.set_item("remote.origin", "url", f"file://{missing}")
|
|
219
|
+
|
|
220
|
+
project.prune_branch("pushed")
|
|
221
|
+
|
|
222
|
+
assert not project._git.committish_exists("pushed")
|
|
223
|
+
assert (
|
|
224
|
+
"warning: cannot reach remote origin to check or delete pushed"
|
|
225
|
+
in capsys.readouterr().err
|
|
226
|
+
)
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
def test_project_prune_branch_remote_refuses_delete(
|
|
230
|
+
reset_directory, remote_repository, tmp_path_factory, capsys, monkeypatch
|
|
231
|
+
):
|
|
232
|
+
project = clone_with_pushed_branch(remote_repository, tmp_path_factory)
|
|
233
|
+
|
|
234
|
+
# libgit2's local transport ignores receive.denyDeletes, so make the push
|
|
235
|
+
# callback refuse, as it does for a server's rejection.
|
|
236
|
+
def refuse(self, refname, message):
|
|
237
|
+
raise git_project.GitProjectError(
|
|
238
|
+
"Could not prune remote branch: deletion prohibited"
|
|
239
|
+
)
|
|
240
|
+
|
|
241
|
+
monkeypatch.setattr(
|
|
242
|
+
git_project.Git.RemoteBranchDeleteCallback,
|
|
243
|
+
"push_update_reference",
|
|
244
|
+
refuse,
|
|
245
|
+
)
|
|
246
|
+
|
|
247
|
+
project.prune_branch("pushed")
|
|
248
|
+
|
|
249
|
+
assert not project._git.committish_exists("pushed")
|
|
250
|
+
assert "warning: origin: Could not prune remote branch" in (
|
|
251
|
+
capsys.readouterr().err
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def test_project_get_without_defaults(git):
|
|
256
|
+
project = git_project.Project.get(git, "project", set_defaults=False)
|
|
257
|
+
|
|
258
|
+
assert not project.has_item("remote")
|
|
259
|
+
assert not project.has_item("branch")
|
|
260
|
+
assert not git.config.has_item("project", "remote")
|
|
261
|
+
assert not git.config.has_item("project", "branch")
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env python3
|
|
2
|
-
#
|
|
3
|
-
# SPDX-FileCopyrightText: 2020-present David A. Greene <dag@obbligato.org>
|
|
4
|
-
|
|
5
|
-
# SPDX-License-Identifier: AGPL-3.0-or-later
|
|
6
|
-
|
|
7
|
-
# Copyright 2024 David A. Greene
|
|
8
|
-
|
|
9
|
-
# This file is part of git-project
|
|
10
|
-
|
|
11
|
-
# git-project is free software: you can redistribute it and/or modify it under
|
|
12
|
-
# the terms of the GNU Affero General Public License as published by the Free
|
|
13
|
-
# Software Foundation, either version 3 of the License, or (at your option) any
|
|
14
|
-
# later version.
|
|
15
|
-
|
|
16
|
-
# This program is distributed in the hope that it will be useful, but WITHOUT
|
|
17
|
-
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
18
|
-
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
19
|
-
# details.
|
|
20
|
-
|
|
21
|
-
# You should have received a copy of the GNU Affero General Public License along
|
|
22
|
-
# with git-project. If not, see <https://www.gnu.org/licenses/>.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
import pytest
|
|
26
|
-
|
|
27
|
-
import git_project
|
|
28
|
-
from git_project.test_support import check_config_file
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
def test_main_no_dup(reset_directory, git, project):
|
|
32
|
-
project._git.validate_config()
|
|
33
|
-
|
|
34
|
-
project._git.validate_config()
|
|
35
|
-
git_project.main_impl(["config", "branch"])
|
|
36
|
-
|
|
37
|
-
project.build = "devrel"
|
|
38
|
-
|
|
39
|
-
project._git.validate_config()
|
|
40
|
-
git_project.main_impl(["config", "branch"])
|
|
41
|
-
|
|
42
|
-
project.add_item("build", "check-devrel")
|
|
43
|
-
|
|
44
|
-
project._git.validate_config()
|
|
45
|
-
git_project.main_impl(["config", "branch"])
|
|
46
|
-
|
|
47
|
-
check_config_file("project", "build", {"devrel", "check-devrel"})
|
|
48
|
-
|
|
49
|
-
project._git.validate_config()
|
|
50
|
-
git_project.main_impl(["config", "branch"])
|
|
51
|
-
|
|
52
|
-
check_config_file("project", "build", {"devrel", "check-devrel"})
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
def test_main_help_shows_summary(reset_directory, git, capsys):
|
|
56
|
-
with pytest.raises(SystemExit):
|
|
57
|
-
git_project.main_impl(["--help"])
|
|
58
|
-
|
|
59
|
-
out = capsys.readouterr().out
|
|
60
|
-
assert "git <project> <command> [<options>]" in out
|
|
61
|
-
assert "The name git-project runs under selects the active project." in out
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|