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.
Files changed (48) hide show
  1. {git_project-0.0.40 → git_project-0.0.41}/PKG-INFO +30 -35
  2. {git_project-0.0.40 → git_project-0.0.41}/_version.py +2 -2
  3. {git_project-0.0.40 → git_project-0.0.41}/docs/changelog.rst +25 -1
  4. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/__init__.py +10 -9
  5. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/exception.py +0 -4
  6. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/git.py +1 -1
  7. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/substitutable.py +35 -42
  8. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/test_support/common.py +1 -0
  9. {git_project-0.0.40 → git_project-0.0.41}/tests/test_git.py +8 -2
  10. {git_project-0.0.40 → git_project-0.0.41}/tests/test_parsermanager.py +13 -0
  11. {git_project-0.0.40 → git_project-0.0.41}/tests/test_substitutable.py +112 -5
  12. {git_project-0.0.40 → git_project-0.0.41}/.gitignore +0 -0
  13. {git_project-0.0.40 → git_project-0.0.41}/CONTRIBUTORS +0 -0
  14. {git_project-0.0.40 → git_project-0.0.41}/COPYING +0 -0
  15. {git_project-0.0.40 → git_project-0.0.41}/MANIFEST.in +0 -0
  16. {git_project-0.0.40 → git_project-0.0.41}/docs/Makefile +0 -0
  17. {git_project-0.0.40 → git_project-0.0.41}/docs/api.rst +0 -0
  18. {git_project-0.0.40 → git_project-0.0.41}/docs/authors.rst +0 -0
  19. {git_project-0.0.40 → git_project-0.0.41}/docs/conf.py +0 -0
  20. {git_project-0.0.40 → git_project-0.0.41}/docs/contributing.rst +0 -0
  21. {git_project-0.0.40 → git_project-0.0.41}/docs/index.rst +0 -0
  22. {git_project-0.0.40 → git_project-0.0.41}/docs/intro.rst +0 -0
  23. {git_project-0.0.40 → git_project-0.0.41}/docs/license.rst +0 -0
  24. {git_project-0.0.40 → git_project-0.0.41}/docs/make.bat +0 -0
  25. {git_project-0.0.40 → git_project-0.0.41}/docs/plugins.rst +0 -0
  26. {git_project-0.0.40 → git_project-0.0.41}/pyproject.toml +0 -0
  27. {git_project-0.0.40 → git_project-0.0.41}/requirements.txt +0 -0
  28. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/commandline.py +0 -0
  29. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/configobj.py +0 -0
  30. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/gitproject.py +0 -0
  31. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/main.py +0 -0
  32. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/parsermanager.py +0 -0
  33. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/plugin.py +0 -0
  34. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/pluginmanager.py +0 -0
  35. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/project.py +0 -0
  36. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/py.typed +0 -0
  37. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/runnable.py +0 -0
  38. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/scopedobj.py +0 -0
  39. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/shell.py +0 -0
  40. {git_project-0.0.40 → git_project-0.0.41}/src/git_project/test_support/__init__.py +0 -0
  41. {git_project-0.0.40 → git_project-0.0.41}/tests/conftest.py +0 -0
  42. {git_project-0.0.40 → git_project-0.0.41}/tests/test_confobj.py +0 -0
  43. {git_project-0.0.40 → git_project-0.0.41}/tests/test_gitproject.py +0 -0
  44. {git_project-0.0.40 → git_project-0.0.41}/tests/test_main.py +0 -0
  45. {git_project-0.0.40 → git_project-0.0.41}/tests/test_project.py +0 -0
  46. {git_project-0.0.40 → git_project-0.0.41}/tests/test_runnable.py +0 -0
  47. {git_project-0.0.40 → git_project-0.0.41}/tests/test_scopedobj.py +0 -0
  48. {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.40
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
- To write a literal brace, write ``{{}`` for ``{`` and ``{}}`` for ``}``.
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
- **A value is evaluated as Python.** git-project substitutes a value by
155
- evaluating it as a Python f-string. So ``{1+1}`` becomes ``2``, and any
156
- Python expression in braces runs when the value is substituted. Treat the
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.40`_ - 2026-10-05
217
+ `0.0.41`_ - 2026-10-06
216
218
  ----------------------
217
- Added
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 now ``GitProjectError``. The old name still
226
- works as an alias, and a later release removes it.
227
- - The ``git_project._contributing`` module is gone. The guide to working
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
- - ``substitute_value``, ``substitute_command`` and ``run`` shared one
234
- default ``formats`` dict across calls, and ``substitute_value`` added its
235
- names to it. So within one process, an object could resolve a name it does
236
- not define to another object's value. Each call now works on its own copy,
237
- and a ``formats`` dict passed in is no longer changed.
238
- - Removing one value of a config key failed when the value held a space.
239
- It was split into several arguments to ``git config --unset``. The pattern
240
- now reaches git as given, so a pattern escaped twice to get through that
241
- split must be escaped once.
242
- - ``Git.get_git_common_dir`` returns an absolute path in a worktree that plain
243
- ``git worktree add`` made. It returned the relative path that git writes, so
244
- ``{git_common_dir}`` substituted ``../..`` there.
245
-
246
- .. _Unreleased: https://github.com/greened/git-project/compare/v0.0.40...HEAD
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.40'
22
- __version_tuple__ = version_tuple = (0, 0, 40)
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.40...HEAD
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
- To write a literal brace, write ``{{}`` for ``{`` and ``{}}`` for ``}``.
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
- **A value is evaluated as Python.** git-project substitutes a value by
147
- evaluating it as a Python f-string. So ``{1+1}`` becomes ``2``, and any
148
- Python expression in braces runs when the value is substituted. Treat the
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, GitProjectException
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",
@@ -42,7 +42,3 @@ class GitProjectError(Exception):
42
42
  def message(self):
43
43
  command = Path(sys.argv[0]).name
44
44
  return f"{command}: {self._message}"
45
-
46
-
47
- # The old name, kept so that plugins written against it still import.
48
- GitProjectException = GitProjectError
@@ -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
- The string is evaluated as a Python f-string with these names as its
44
- globals, again and again until it stops changing. So substitution runs any
45
- Python expression in braces. Treat config values as code.
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
- # Allow escaping braces by surrounding each brace with braces. This is
156
- # not valid f-string syntax and is unlikely to be used in ordinary
157
- # config values. Replace with an equally unlikely sequence, then
158
- # substitute on that string.
159
-
160
- escaped_braces = False
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
- escaped_braces = (
163
- escaped_braces or "{{}" in string or "{}}" in string
164
- )
165
- if escaped_braces:
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, "}")
@@ -92,6 +92,7 @@ class ParserManagerMock:
92
92
  return False
93
93
  if self_default[1] != other_default[1]:
94
94
  return False
95
+ return True
95
96
 
96
97
  def __hash__(self):
97
98
  raise TypeError(f"unhashable type: '{type(self).__name__}'")
@@ -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(git_project.GitProjectError, match="Will not prune"):
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(git_project.GitProjectError, match="Will not prune"):
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 test_substitutable_substitute_fstring(reset_directory, git):
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
- command
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