git-project 0.0.40__tar.gz → 0.0.41__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.40 → git_project-0.0.41}/PKG-INFO +30 -35
- {git_project-0.0.40 → git_project-0.0.41}/_version.py +2 -2
- {git_project-0.0.40 → git_project-0.0.41}/docs/changelog.rst +25 -1
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/__init__.py +10 -9
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/exception.py +0 -4
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/git.py +1 -1
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/substitutable.py +35 -42
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/test_support/common.py +1 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_git.py +8 -2
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_parsermanager.py +13 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_substitutable.py +112 -5
- {git_project-0.0.40 → git_project-0.0.41}/.gitignore +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/CONTRIBUTORS +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/COPYING +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/MANIFEST.in +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/Makefile +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/api.rst +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/authors.rst +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/conf.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/contributing.rst +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/index.rst +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/intro.rst +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/license.rst +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/make.bat +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/docs/plugins.rst +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/pyproject.toml +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/requirements.txt +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/commandline.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/configobj.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/gitproject.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/main.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/parsermanager.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/plugin.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/pluginmanager.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/project.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/py.typed +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/runnable.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/scopedobj.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/shell.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/src/git_project/test_support/__init__.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/conftest.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_confobj.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_gitproject.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_main.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_project.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_runnable.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_scopedobj.py +0 -0
- {git_project-0.0.40 → git_project-0.0.41}/tests/test_shell.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.41
|
|
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
|
|
@@ -148,14 +148,16 @@ the value of ``name``. A name can be:
|
|
|
148
148
|
The root of the current worktree
|
|
149
149
|
|
|
150
150
|
Substitution repeats until the value stops changing, so a value can name
|
|
151
|
-
another value that itself contains ``{name}``. A value may not name itself.
|
|
152
|
-
|
|
151
|
+
another value that itself contains ``{name}``. A value may not name itself. To
|
|
152
|
+
write a literal brace, write ``{{}`` for ``{`` and ``{}}`` for ``}``. A name is
|
|
153
|
+
ASCII letters, digits and underscores, and does not start with a digit. Other
|
|
154
|
+
text in single braces, such as ``{x.upper()}`` or ``{}``, stays as written, but
|
|
155
|
+
a doubled ``{{`` or ``}}`` becomes one brace. A name that is not defined is an
|
|
156
|
+
error.
|
|
153
157
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
git config as code, and do not include config from a source you do not
|
|
158
|
-
trust. A value that contains a ``'`` cannot be substituted.
|
|
158
|
+
Substitution inserts each value as written, and the ``run`` plugin runs
|
|
159
|
+
its commands through a shell. Treat the git config as code, and do not
|
|
160
|
+
include config from a source you do not trust.
|
|
159
161
|
|
|
160
162
|
Getting help
|
|
161
163
|
============
|
|
@@ -212,38 +214,31 @@ Authors
|
|
|
212
214
|
.. _David Greene: https://github.com/greened
|
|
213
215
|
|
|
214
216
|
|
|
215
|
-
`0.0.
|
|
217
|
+
`0.0.41`_ - 2026-10-06
|
|
216
218
|
----------------------
|
|
217
|
-
|
|
218
|
-
.....
|
|
219
|
-
- ``capture_command`` takes a list of arguments as well as a string.
|
|
220
|
-
- The package ships a ``py.typed`` marker, so mypy checks code that
|
|
221
|
-
uses git-project against its annotations.
|
|
222
|
-
|
|
223
|
-
Changed
|
|
219
|
+
Removed
|
|
224
220
|
.......
|
|
225
|
-
- ``GitProjectException`` is
|
|
226
|
-
|
|
227
|
-
-
|
|
228
|
-
on git-project is in the docs only, and its Tests section is now the
|
|
229
|
-
``git_project.test_support`` package documentation.
|
|
221
|
+
- The ``GitProjectException`` alias is gone. Use ``GitProjectError``.
|
|
222
|
+
core-plugins 0.0.28 is the first release that uses the new name, so an
|
|
223
|
+
older core-plugins fails to import with this git-project.
|
|
230
224
|
|
|
231
225
|
Fixed
|
|
232
226
|
.....
|
|
233
|
-
- ``
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
``
|
|
245
|
-
|
|
246
|
-
.. _Unreleased: https://github.com/greened/git-project/compare/v0.0.
|
|
227
|
+
- ``prune_worktree`` refused to prune a worktree with the message
|
|
228
|
+
``Will not prune existing worktree {name}``. It now names the worktree.
|
|
229
|
+
- ``ParserManagerMock.ParserMock`` compared unequal to an equal mock:
|
|
230
|
+
``==`` returned None, and ``!=`` returned True.
|
|
231
|
+
|
|
232
|
+
Security
|
|
233
|
+
........
|
|
234
|
+
- Substitution no longer evaluates a config value as a Python f-string.
|
|
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
|
|
241
|
+
.. _0.0.41: https://github.com/greened/git-project/compare/v0.0.40...v0.0.41
|
|
247
242
|
.. _0.0.40: https://github.com/greened/git-project/compare/v0.0.39...v0.0.40
|
|
248
243
|
.. _0.0.39: https://github.com/greened/git-project/compare/v0.0.38...v0.0.39
|
|
249
244
|
.. _0.0.38: https://github.com/greened/git-project/compare/v0.0.37...v0.0.38
|
|
@@ -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.41'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 0, 41)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -31,6 +31,29 @@ ChangeLog
|
|
|
31
31
|
`Unreleased`_
|
|
32
32
|
-------------
|
|
33
33
|
|
|
34
|
+
`0.0.41`_ - 2026-10-06
|
|
35
|
+
----------------------
|
|
36
|
+
Removed
|
|
37
|
+
.......
|
|
38
|
+
- The ``GitProjectException`` alias is gone. Use ``GitProjectError``.
|
|
39
|
+
core-plugins 0.0.28 is the first release that uses the new name, so an
|
|
40
|
+
older core-plugins fails to import with this git-project.
|
|
41
|
+
|
|
42
|
+
Fixed
|
|
43
|
+
.....
|
|
44
|
+
- ``prune_worktree`` refused to prune a worktree with the message
|
|
45
|
+
``Will not prune existing worktree {name}``. It now names the worktree.
|
|
46
|
+
- ``ParserManagerMock.ParserMock`` compared unequal to an equal mock:
|
|
47
|
+
``==`` returned None, and ``!=`` returned True.
|
|
48
|
+
|
|
49
|
+
Security
|
|
50
|
+
........
|
|
51
|
+
- Substitution no longer evaluates a config value as a Python f-string.
|
|
52
|
+
Before, any expression in braces ran, so a value from an included config
|
|
53
|
+
file could run code. Now only ``{name}`` is replaced, and an expression
|
|
54
|
+
such as ``{x.replace(...)}`` stays as written. A value may now contain
|
|
55
|
+
``'``, and a backslash in a value stays as written.
|
|
56
|
+
|
|
34
57
|
`0.0.40`_ - 2026-10-05
|
|
35
58
|
----------------------
|
|
36
59
|
Added
|
|
@@ -154,7 +177,8 @@ Fixed
|
|
|
154
177
|
``git_project``. No declared environment supplied Sphinx either, so a
|
|
155
178
|
``docs`` environment with Sphinx is now declared.
|
|
156
179
|
|
|
157
|
-
.. _Unreleased: https://github.com/greened/git-project/compare/v0.0.
|
|
180
|
+
.. _Unreleased: https://github.com/greened/git-project/compare/v0.0.41...HEAD
|
|
181
|
+
.. _0.0.41: https://github.com/greened/git-project/compare/v0.0.40...v0.0.41
|
|
158
182
|
.. _0.0.40: https://github.com/greened/git-project/compare/v0.0.39...v0.0.40
|
|
159
183
|
.. _0.0.39: https://github.com/greened/git-project/compare/v0.0.38...v0.0.39
|
|
160
184
|
.. _0.0.38: https://github.com/greened/git-project/compare/v0.0.37...v0.0.38
|
|
@@ -140,14 +140,16 @@ the value of ``name``. A name can be:
|
|
|
140
140
|
The root of the current worktree
|
|
141
141
|
|
|
142
142
|
Substitution repeats until the value stops changing, so a value can name
|
|
143
|
-
another value that itself contains ``{name}``. A value may not name itself.
|
|
144
|
-
|
|
143
|
+
another value that itself contains ``{name}``. A value may not name itself. To
|
|
144
|
+
write a literal brace, write ``{{}`` for ``{`` and ``{}}`` for ``}``. A name is
|
|
145
|
+
ASCII letters, digits and underscores, and does not start with a digit. Other
|
|
146
|
+
text in single braces, such as ``{x.upper()}`` or ``{}``, stays as written, but
|
|
147
|
+
a doubled ``{{`` or ``}}`` becomes one brace. A name that is not defined is an
|
|
148
|
+
error.
|
|
145
149
|
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
git config as code, and do not include config from a source you do not
|
|
150
|
-
trust. A value that contains a ``'`` cannot be substituted.
|
|
150
|
+
Substitution inserts each value as written, and the ``run`` plugin runs
|
|
151
|
+
its commands through a shell. Treat the git config as code, and do not
|
|
152
|
+
include config from a source you do not trust.
|
|
151
153
|
|
|
152
154
|
Getting help
|
|
153
155
|
============
|
|
@@ -175,7 +177,7 @@ from .commandline import (
|
|
|
175
177
|
parse_arguments,
|
|
176
178
|
)
|
|
177
179
|
from .configobj import ConfigObject
|
|
178
|
-
from .exception import GitProjectError
|
|
180
|
+
from .exception import GitProjectError
|
|
179
181
|
from .git import Git
|
|
180
182
|
from .gitproject import GitProject
|
|
181
183
|
from .main import main_impl
|
|
@@ -193,7 +195,6 @@ __all__ = [
|
|
|
193
195
|
"Git",
|
|
194
196
|
"GitProject",
|
|
195
197
|
"GitProjectError",
|
|
196
|
-
"GitProjectException",
|
|
197
198
|
"ParserManager",
|
|
198
199
|
"Plugin",
|
|
199
200
|
"PluginManager",
|
|
@@ -893,7 +893,7 @@ class Git:
|
|
|
893
893
|
"""
|
|
894
894
|
worktree = self._repo.lookup_worktree(name)
|
|
895
895
|
if os.path.exists(worktree.path):
|
|
896
|
-
raise GitProjectError("Will not prune existing worktree {name}")
|
|
896
|
+
raise GitProjectError(f"Will not prune existing worktree {name}")
|
|
897
897
|
|
|
898
898
|
# Prune the worktree. For some reason, libgit2 treats a worktree as
|
|
899
899
|
# valid unless both the worktree directory and data dir under
|
|
@@ -40,16 +40,27 @@ The names come from four places, and a later one wins over an earlier one:
|
|
|
40
40
|
A name that none of them define is looked up as a scope name through
|
|
41
41
|
``get_scope``, and gives that scope's ident.
|
|
42
42
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
Substitution replaces each ``{name}`` whose name is ASCII letters, digits and
|
|
44
|
+
underscores and does not start with a digit, and repeats until the string stops
|
|
45
|
+
changing. Nothing is evaluated. Other text in single braces, such as
|
|
46
|
+
``{x.replace("a", "b")}``, ``{x[0]}`` or ``{}``, stays as written. A doubled
|
|
47
|
+
``{{`` or ``}}`` becomes one brace on each pass. A name that no source defines
|
|
48
|
+
and that names no scope raises ``NameError``.
|
|
46
49
|
|
|
47
50
|
"""
|
|
48
51
|
|
|
52
|
+
import re
|
|
49
53
|
from pathlib import Path
|
|
50
54
|
|
|
51
55
|
from .configobj import ConfigObject
|
|
52
56
|
|
|
57
|
+
# One alternation, scanned left to right like an f-string: a doubled
|
|
58
|
+
# brace is a literal brace, and only a bare identifier is a field.
|
|
59
|
+
_FIELD = re.compile(r"\{\{|\}\}|\{([A-Za-z_][A-Za-z0-9_]*)\}")
|
|
60
|
+
# Git config cannot hold NUL, so a config value cannot collide with these.
|
|
61
|
+
_LBRACE = "\x00("
|
|
62
|
+
_RBRACE = "\x00)"
|
|
63
|
+
|
|
53
64
|
|
|
54
65
|
class SubstitutableConfigObject(ConfigObject):
|
|
55
66
|
"""Base class for objects that use git-config as a backing store and allow
|
|
@@ -143,51 +154,33 @@ class SubstitutableConfigObject(ConfigObject):
|
|
|
143
154
|
f"Recursive substitution: {key} is in {value}"
|
|
144
155
|
)
|
|
145
156
|
|
|
146
|
-
def try_format(string, formats):
|
|
147
|
-
return eval(f"f'{string}'", formats)
|
|
148
|
-
|
|
149
157
|
def add_scope(project, key, formats):
|
|
150
158
|
scope = project.get_scope(key)
|
|
151
159
|
if scope:
|
|
152
160
|
value = scope.get_ident()
|
|
153
161
|
formats[key] = value
|
|
154
162
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
163
|
+
def expand(match):
|
|
164
|
+
token = match.group(0)
|
|
165
|
+
if token == "{{":
|
|
166
|
+
return "{"
|
|
167
|
+
if token == "}}":
|
|
168
|
+
return "}"
|
|
169
|
+
name = match.group(1)
|
|
170
|
+
if name not in formats:
|
|
171
|
+
add_scope(project, name, formats)
|
|
172
|
+
if name not in formats:
|
|
173
|
+
raise NameError(f"name {name!r} is not defined", name=name)
|
|
174
|
+
return str(formats[name])
|
|
175
|
+
|
|
176
|
+
# Hide escaped braces on every pass, so that neither an escape in
|
|
177
|
+
# the string nor one in a substituted value is read as a field.
|
|
161
178
|
while True:
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
)
|
|
165
|
-
if
|
|
166
|
-
string = string.replace("{{}", "[[[")
|
|
167
|
-
string = string.replace("{}}", "]]]")
|
|
168
|
-
try:
|
|
169
|
-
newstring = try_format(string, formats)
|
|
170
|
-
except KeyError as exception:
|
|
171
|
-
# See if this is a scope name.
|
|
172
|
-
for key in exception.args:
|
|
173
|
-
add_scope(project, key, formats)
|
|
174
|
-
# Try again after adding scopes.
|
|
175
|
-
newstring = try_format(string, formats)
|
|
176
|
-
except NameError as exception:
|
|
177
|
-
# args is simply the error message, with the name surrounded by
|
|
178
|
-
# '. Use .name attribute after upgrading to python 3.10.
|
|
179
|
-
for arg in exception.args:
|
|
180
|
-
key = arg.split("'")[1]
|
|
181
|
-
add_scope(project, key, formats)
|
|
182
|
-
# Try again after adding scopes.
|
|
183
|
-
newstring = try_format(string, formats)
|
|
184
|
-
|
|
185
|
-
changed = False if newstring == string else True
|
|
186
|
-
string = newstring
|
|
187
|
-
if not changed:
|
|
188
|
-
if escaped_braces:
|
|
189
|
-
string = string.replace("[[[", "{")
|
|
190
|
-
string = string.replace("]]]", "}")
|
|
179
|
+
string = string.replace("{{}", _LBRACE)
|
|
180
|
+
string = string.replace("{}}", _RBRACE)
|
|
181
|
+
newstring = _FIELD.sub(expand, string)
|
|
182
|
+
if newstring == string:
|
|
191
183
|
break
|
|
184
|
+
string = newstring
|
|
192
185
|
|
|
193
|
-
return string
|
|
186
|
+
return string.replace(_LBRACE, "{").replace(_RBRACE, "}")
|
|
@@ -342,7 +342,10 @@ def test_git_worktree(reset_directory, local_repository):
|
|
|
342
342
|
|
|
343
343
|
assert os.path.exists(worktree_path)
|
|
344
344
|
|
|
345
|
-
with pytest.raises(
|
|
345
|
+
with pytest.raises(
|
|
346
|
+
git_project.GitProjectError,
|
|
347
|
+
match="Will not prune existing worktree test-wt",
|
|
348
|
+
):
|
|
346
349
|
git.prune_worktree("test-wt")
|
|
347
350
|
|
|
348
351
|
shutil.rmtree(worktree_checkout_path)
|
|
@@ -1053,7 +1056,10 @@ def test_git_worktree_subdir(reset_directory, local_repository):
|
|
|
1053
1056
|
wtgit = git_project.Git()
|
|
1054
1057
|
assert wtgit.get_current_branch() == "user/test-wt"
|
|
1055
1058
|
|
|
1056
|
-
with pytest.raises(
|
|
1059
|
+
with pytest.raises(
|
|
1060
|
+
git_project.GitProjectError,
|
|
1061
|
+
match="Will not prune existing worktree test-wt",
|
|
1062
|
+
):
|
|
1057
1063
|
git.prune_worktree("test-wt")
|
|
1058
1064
|
|
|
1059
1065
|
shutil.rmtree(worktree_checkout_path)
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
# You should have received a copy of the GNU Affero General Public License along
|
|
22
22
|
# with git-project. If not, see <https://www.gnu.org/licenses/>.
|
|
23
23
|
|
|
24
|
+
from git_project.test_support import ParserManagerMock
|
|
25
|
+
|
|
24
26
|
|
|
25
27
|
def test_get_or_add_parser_name_and_key(reset_directory, parser_manager):
|
|
26
28
|
command = parser_manager.find_subparser("command")
|
|
@@ -37,3 +39,14 @@ def test_get_or_add_parser_name_and_key(reset_directory, parser_manager):
|
|
|
37
39
|
# The name is what the user types.
|
|
38
40
|
clargs = parser_manager.parse_args(["visible"])
|
|
39
41
|
assert clargs.command == "visible"
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_parser_mock_equality():
|
|
45
|
+
def make(help_text):
|
|
46
|
+
parser = ParserManagerMock.ParserMock("thekey")
|
|
47
|
+
parser.add_argument("name", help=help_text)
|
|
48
|
+
parser.set_defaults(func="handler")
|
|
49
|
+
return parser
|
|
50
|
+
|
|
51
|
+
assert make("same") == make("same")
|
|
52
|
+
assert make("same") != make("different")
|
|
@@ -436,7 +436,9 @@ def test_substitutable_substitute_command_rebase_worktree(
|
|
|
436
436
|
)
|
|
437
437
|
|
|
438
438
|
|
|
439
|
-
def
|
|
439
|
+
def test_substitutable_substitute_expression_stays_literal(
|
|
440
|
+
reset_directory, git
|
|
441
|
+
):
|
|
440
442
|
class MyProject(git_project.ScopedConfigObject):
|
|
441
443
|
def __init__(self):
|
|
442
444
|
super().__init__(
|
|
@@ -457,10 +459,15 @@ def test_substitutable_substitute_fstring(reset_directory, git):
|
|
|
457
459
|
git._repo.branches.create("imerge/user/test-fstr", commit)
|
|
458
460
|
|
|
459
461
|
git.checkout("imerge/user/test-fstr")
|
|
460
|
-
current_branch = git.get_current_branch()
|
|
461
462
|
|
|
462
463
|
git_project.run_command_with_shell("git rebase --exec false origin/master")
|
|
463
464
|
|
|
465
|
+
command = substitutable.substitute_value(
|
|
466
|
+
git, project, "cd {builddir}/{branch}"
|
|
467
|
+
)
|
|
468
|
+
|
|
469
|
+
assert command == "cd /path/to/build/imerge/user/test-fstr"
|
|
470
|
+
|
|
464
471
|
substitutable.command = (
|
|
465
472
|
'cd {builddir}/{branch.replace("imerge/", "", 1)} && make {target}'
|
|
466
473
|
)
|
|
@@ -469,9 +476,8 @@ def test_substitutable_substitute_fstring(reset_directory, git):
|
|
|
469
476
|
git, project, substitutable.command
|
|
470
477
|
)
|
|
471
478
|
|
|
472
|
-
assert (
|
|
473
|
-
|
|
474
|
-
== f'cd {project.builddir}/{current_branch.replace("imerge/", "", 1)} && make {project.target}'
|
|
479
|
+
assert command == (
|
|
480
|
+
'cd /path/to/build/{branch.replace("imerge/", "", 1)} && make debug'
|
|
475
481
|
)
|
|
476
482
|
|
|
477
483
|
|
|
@@ -704,3 +710,104 @@ def test_substitutable_substitute_formats_not_shared(reset_directory, git):
|
|
|
704
710
|
# The second object has no leaked item, so it cannot see the first's.
|
|
705
711
|
with pytest.raises(NameError):
|
|
706
712
|
second.substitute_value(git, project, "{leaked}")
|
|
713
|
+
|
|
714
|
+
|
|
715
|
+
class MyTargetProject(git_project.ScopedConfigObject):
|
|
716
|
+
def __init__(self, git):
|
|
717
|
+
super().__init__(
|
|
718
|
+
git,
|
|
719
|
+
"project",
|
|
720
|
+
None,
|
|
721
|
+
"myproject",
|
|
722
|
+
builddir="/path/to/build",
|
|
723
|
+
target="debug",
|
|
724
|
+
)
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
def substitute(git, string):
|
|
728
|
+
substitutable = MySubstitutable.get(git, "project", "test")
|
|
729
|
+
project = MyTargetProject(git)
|
|
730
|
+
return substitutable.substitute_value(git, project, string)
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
def test_substitutable_substitute_no_code_execution(
|
|
734
|
+
reset_directory, git, tmp_path
|
|
735
|
+
):
|
|
736
|
+
pwned = tmp_path / "pwned"
|
|
737
|
+
value = f'{{__import__("os").system("touch {pwned}")}}'
|
|
738
|
+
|
|
739
|
+
assert substitute(git, value) == value
|
|
740
|
+
assert not pwned.exists()
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
def test_substitutable_substitute_single_quote(reset_directory, git):
|
|
744
|
+
assert substitute(git, "echo '{target}'") == "echo 'debug'"
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
@pytest.mark.parametrize(
|
|
748
|
+
"value",
|
|
749
|
+
[
|
|
750
|
+
"{target.upper()}",
|
|
751
|
+
"{target[0]}",
|
|
752
|
+
"{target.__class__}",
|
|
753
|
+
"{target!r}",
|
|
754
|
+
"{target:>8}",
|
|
755
|
+
"{1+1}",
|
|
756
|
+
"{ target }",
|
|
757
|
+
],
|
|
758
|
+
# The fixtures put the test id in a repo path, so keep it plain.
|
|
759
|
+
ids=["call", "index", "attribute", "conversion", "spec", "sum", "spaces"],
|
|
760
|
+
)
|
|
761
|
+
def test_substitutable_substitute_attribute_index_spec_literal(
|
|
762
|
+
reset_directory, git, value
|
|
763
|
+
):
|
|
764
|
+
assert substitute(git, value) == value
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
@pytest.mark.parametrize(
|
|
768
|
+
"value, expected",
|
|
769
|
+
[
|
|
770
|
+
("awk '{print $1}' {target}", "awk '{print $1}' debug"),
|
|
771
|
+
(r"find . -exec echo {} \;", r"find . -exec echo {} \;"),
|
|
772
|
+
("a { b", "a { b"),
|
|
773
|
+
("a } b", "a } b"),
|
|
774
|
+
],
|
|
775
|
+
# The fixtures put the test id in a repo path, so keep it plain.
|
|
776
|
+
ids=["awk", "empty", "open", "close"],
|
|
777
|
+
)
|
|
778
|
+
def test_substitutable_substitute_stray_braces_literal(
|
|
779
|
+
reset_directory, git, value, expected
|
|
780
|
+
):
|
|
781
|
+
assert substitute(git, value) == expected
|
|
782
|
+
|
|
783
|
+
|
|
784
|
+
def test_substitutable_substitute_escaped_name_not_substituted(
|
|
785
|
+
reset_directory, git
|
|
786
|
+
):
|
|
787
|
+
assert substitute(git, "{{}target{}}") == "{target}"
|
|
788
|
+
|
|
789
|
+
|
|
790
|
+
def test_substitutable_substitute_doubled_braces(reset_directory, git):
|
|
791
|
+
assert substitute(git, "{{target}}") == "debug"
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
def test_substitutable_substitute_sentinel_text_literal(reset_directory, git):
|
|
795
|
+
assert substitute(git, "[[[x]]] {{}y{}}") == "[[[x]]] {y}"
|
|
796
|
+
|
|
797
|
+
|
|
798
|
+
def test_substitutable_substitute_two_scopes_one_pass(reset_directory, git):
|
|
799
|
+
class MyScope(git_project.ScopedConfigObject):
|
|
800
|
+
def __init__(self, subsection, ident):
|
|
801
|
+
super().__init__(git, "project", subsection, ident)
|
|
802
|
+
|
|
803
|
+
substitutable = MySubstitutable.get(git, "project", "test")
|
|
804
|
+
|
|
805
|
+
project = MyTargetProject(git)
|
|
806
|
+
project.push_scope(MyScope("worktree", "myworktree"))
|
|
807
|
+
project.push_scope(MyScope("build", "mybuild"))
|
|
808
|
+
|
|
809
|
+
command = substitutable.substitute_value(
|
|
810
|
+
git, project, "{worktree}/{build}"
|
|
811
|
+
)
|
|
812
|
+
|
|
813
|
+
assert command == "myworktree/mybuild"
|
|
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
|