git-project 0.1.2__tar.gz → 0.1.3__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {git_project-0.1.2 → git_project-0.1.3}/PKG-INFO +31 -22
- {git_project-0.1.2 → git_project-0.1.3}/_version.py +2 -2
- {git_project-0.1.2 → git_project-0.1.3}/docs/changelog.rst +33 -1
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/configobj.py +4 -4
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/git.py +26 -10
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/main.py +16 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/project.py +7 -2
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/shell.py +54 -5
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_confobj.py +45 -2
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_git.py +89 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_main.py +38 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_project.py +31 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_scopedobj.py +1 -1
- git_project-0.1.3/tests/test_shell.py +220 -0
- git_project-0.1.2/tests/test_shell.py +0 -55
- {git_project-0.1.2 → git_project-0.1.3}/.gitignore +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/CONTRIBUTORS +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/COPYING +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/MANIFEST.in +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/changelog.d/README.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/changelog.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/Makefile +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/api.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/authors.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/conf.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/contributing.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/index.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/intro.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/license.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/make.bat +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/docs/plugins.rst +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/pyproject.toml +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/requirements.txt +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/__init__.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/commandline.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/exception.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/gitproject.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/parsermanager.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/plugin.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/pluginmanager.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/py.typed +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/runnable.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/scopedobj.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/substitutable.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/test_support/__init__.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/src/git_project/test_support/common.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/conftest.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_changelog.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_gitproject.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_parsermanager.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_runnable.py +0 -0
- {git_project-0.1.2 → git_project-0.1.3}/tests/test_substitutable.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: git-project
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
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
|
|
@@ -228,30 +228,39 @@ Authors
|
|
|
228
228
|
.. _David Greene: https://github.com/greened
|
|
229
229
|
|
|
230
230
|
|
|
231
|
-
`0.1.
|
|
231
|
+
`0.1.3`_ - 2026-11-17
|
|
232
232
|
---------------------
|
|
233
|
+
Changed
|
|
234
|
+
.......
|
|
235
|
+
- Reading a key with several values as an attribute now gives a
|
|
236
|
+
``tuple`` instead of a ``frozenset``. Code that compares the value
|
|
237
|
+
with a set, or uses set operations on it, needs ``set(...)``.
|
|
238
|
+
|
|
233
239
|
Fixed
|
|
234
240
|
.....
|
|
235
|
-
- ``Git.
|
|
236
|
-
name
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
``
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
241
|
+
- ``Git.checkout``, ``Git.add_worktree``, ``Git.update_symbolic_ref`` and
|
|
242
|
+
``Git.committish_is_pushed`` now take a short name that is both a branch and
|
|
243
|
+
a tag as the branch, and so do ``Project.branch_is_merged``,
|
|
244
|
+
``Project.branch_is_merged_remotely`` and ``Project.branch_is_pushed``. The
|
|
245
|
+
tag was taken in its place. A checkout or a symbolic ref could then land on
|
|
246
|
+
the tag, a worktree add failed, and a branch could be reported merged,
|
|
247
|
+
unmerged, pushed or unpushed by the tag's commit. The new
|
|
248
|
+
``Git.branch_or_committish_ref`` does the lookup. An unmerged SHA given to
|
|
249
|
+
``Project.branch_is_merged`` or ``Project.branch_is_pushed`` now gives False
|
|
250
|
+
instead of an ``AttributeError``.
|
|
251
|
+
- A key with several values now gives them in the same order on every
|
|
252
|
+
run, the order git reads them from the config files. Before, the order
|
|
253
|
+
changed from one run to the next, so choices and ``--menu=json`` built
|
|
254
|
+
from such a key were reordered.
|
|
255
|
+
- ``run_command_with_shell`` no longer dies on a Ctrl-C or a SIGTERM while
|
|
256
|
+
its command runs. It waits for the command and returns its status. A
|
|
257
|
+
SIGTERM is sent on to the command, and so is a SIGINT when git-project is
|
|
258
|
+
not in the terminal's foreground group. Before, git-project exited and left
|
|
259
|
+
the command running. When the command dies of a signal, git-project now
|
|
260
|
+
exits by the same signal, so a shell loop running it stops on a Ctrl-C.
|
|
261
|
+
|
|
262
|
+
.. _Unreleased: https://github.com/greened/git-project/compare/v0.1.3...HEAD
|
|
263
|
+
.. _0.1.3: https://github.com/greened/git-project/compare/v0.1.2...v0.1.3
|
|
255
264
|
.. _0.1.2: https://github.com/greened/git-project/compare/v0.1.1...v0.1.2
|
|
256
265
|
.. _0.1.1: https://github.com/greened/git-project/compare/v0.1.0...v0.1.1
|
|
257
266
|
.. _0.1.0: https://github.com/greened/git-project/compare/v0.0.44...v0.1.0
|
|
@@ -18,7 +18,7 @@ version_tuple: tuple[int | str, ...]
|
|
|
18
18
|
commit_id: str | None
|
|
19
19
|
__commit_id__: str | None
|
|
20
20
|
|
|
21
|
-
__version__ = version = '0.1.
|
|
22
|
-
__version_tuple__ = version_tuple = (0, 1,
|
|
21
|
+
__version__ = version = '0.1.3'
|
|
22
|
+
__version_tuple__ = version_tuple = (0, 1, 3)
|
|
23
23
|
|
|
24
24
|
__commit_id__ = commit_id = None
|
|
@@ -31,6 +31,37 @@ ChangeLog
|
|
|
31
31
|
`Unreleased`_
|
|
32
32
|
-------------
|
|
33
33
|
|
|
34
|
+
`0.1.3`_ - 2026-11-17
|
|
35
|
+
---------------------
|
|
36
|
+
Changed
|
|
37
|
+
.......
|
|
38
|
+
- Reading a key with several values as an attribute now gives a
|
|
39
|
+
``tuple`` instead of a ``frozenset``. Code that compares the value
|
|
40
|
+
with a set, or uses set operations on it, needs ``set(...)``.
|
|
41
|
+
|
|
42
|
+
Fixed
|
|
43
|
+
.....
|
|
44
|
+
- ``Git.checkout``, ``Git.add_worktree``, ``Git.update_symbolic_ref`` and
|
|
45
|
+
``Git.committish_is_pushed`` now take a short name that is both a branch and
|
|
46
|
+
a tag as the branch, and so do ``Project.branch_is_merged``,
|
|
47
|
+
``Project.branch_is_merged_remotely`` and ``Project.branch_is_pushed``. The
|
|
48
|
+
tag was taken in its place. A checkout or a symbolic ref could then land on
|
|
49
|
+
the tag, a worktree add failed, and a branch could be reported merged,
|
|
50
|
+
unmerged, pushed or unpushed by the tag's commit. The new
|
|
51
|
+
``Git.branch_or_committish_ref`` does the lookup. An unmerged SHA given to
|
|
52
|
+
``Project.branch_is_merged`` or ``Project.branch_is_pushed`` now gives False
|
|
53
|
+
instead of an ``AttributeError``.
|
|
54
|
+
- A key with several values now gives them in the same order on every
|
|
55
|
+
run, the order git reads them from the config files. Before, the order
|
|
56
|
+
changed from one run to the next, so choices and ``--menu=json`` built
|
|
57
|
+
from such a key were reordered.
|
|
58
|
+
- ``run_command_with_shell`` no longer dies on a Ctrl-C or a SIGTERM while
|
|
59
|
+
its command runs. It waits for the command and returns its status. A
|
|
60
|
+
SIGTERM is sent on to the command, and so is a SIGINT when git-project is
|
|
61
|
+
not in the terminal's foreground group. Before, git-project exited and left
|
|
62
|
+
the command running. When the command dies of a signal, git-project now
|
|
63
|
+
exits by the same signal, so a shell loop running it stops on a Ctrl-C.
|
|
64
|
+
|
|
34
65
|
`0.1.2`_ - 2026-10-22
|
|
35
66
|
---------------------
|
|
36
67
|
Fixed
|
|
@@ -291,7 +322,8 @@ Fixed
|
|
|
291
322
|
``git_project``. No declared environment supplied Sphinx either, so a
|
|
292
323
|
``docs`` environment with Sphinx is now declared.
|
|
293
324
|
|
|
294
|
-
.. _Unreleased: https://github.com/greened/git-project/compare/v0.1.
|
|
325
|
+
.. _Unreleased: https://github.com/greened/git-project/compare/v0.1.3...HEAD
|
|
326
|
+
.. _0.1.3: https://github.com/greened/git-project/compare/v0.1.2...v0.1.3
|
|
295
327
|
.. _0.1.2: https://github.com/greened/git-project/compare/v0.1.1...v0.1.2
|
|
296
328
|
.. _0.1.1: https://github.com/greened/git-project/compare/v0.1.0...v0.1.1
|
|
297
329
|
.. _0.1.0: https://github.com/greened/git-project/compare/v0.0.44...v0.1.0
|
|
@@ -36,7 +36,7 @@ arguments on top.
|
|
|
36
36
|
Setting an attribute writes it to the config at once, and reading it reads
|
|
37
37
|
the config. Values must be strings. ``add_item`` adds a value to a key
|
|
38
38
|
instead of replacing it, which makes a key with several values. Read back, a
|
|
39
|
-
key with several values gives a ``
|
|
39
|
+
key with several values gives a ``tuple``, in the order git reads the values.
|
|
40
40
|
|
|
41
41
|
The attributes are properties on the class, not on the instance. The first
|
|
42
42
|
time a class sets a key, the class gains a property for it, and every
|
|
@@ -243,12 +243,12 @@ class ConfigObject:
|
|
|
243
243
|
git config when written."""
|
|
244
244
|
|
|
245
245
|
def fun_get(self):
|
|
246
|
-
result =
|
|
246
|
+
result = tuple(dict.fromkeys(self.iter_multival(name)))
|
|
247
247
|
if not result:
|
|
248
248
|
return None
|
|
249
249
|
if len(result) == 1:
|
|
250
|
-
return result
|
|
251
|
-
return
|
|
250
|
+
return result[0]
|
|
251
|
+
return result
|
|
252
252
|
|
|
253
253
|
def fun_set(self, value):
|
|
254
254
|
self._set_item(name, value)
|
|
@@ -170,7 +170,8 @@ class Git:
|
|
|
170
170
|
|
|
171
171
|
def __init__(self, key):
|
|
172
172
|
self._key = key
|
|
173
|
-
|
|
173
|
+
# A dict, not a set, so values keep config file order.
|
|
174
|
+
self._values = {}
|
|
174
175
|
|
|
175
176
|
@property
|
|
176
177
|
def key(self):
|
|
@@ -202,7 +203,7 @@ class Git:
|
|
|
202
203
|
def add_value(self, value):
|
|
203
204
|
"""Add a value to this key, potentially turning it into a multi-value key."""
|
|
204
205
|
assert value not in self._values
|
|
205
|
-
self._values
|
|
206
|
+
self._values[value] = None
|
|
206
207
|
|
|
207
208
|
def clear(self):
|
|
208
209
|
"""Remove all values for this key."""
|
|
@@ -215,7 +216,7 @@ class Git:
|
|
|
215
216
|
def remove_value(self, pattern):
|
|
216
217
|
"""Remove the specified value from this key, leaving any other values in place."""
|
|
217
218
|
self._values = {
|
|
218
|
-
value
|
|
219
|
+
value: None
|
|
219
220
|
for value in self._values
|
|
220
221
|
if not re.search(pattern, value)
|
|
221
222
|
}
|
|
@@ -385,8 +386,8 @@ class Git:
|
|
|
385
386
|
sections[section] = {}
|
|
386
387
|
section_entry = sections[section]
|
|
387
388
|
if key not in section_entry:
|
|
388
|
-
section_entry[key] =
|
|
389
|
-
section_entry[key]
|
|
389
|
+
section_entry[key] = {}
|
|
390
|
+
section_entry[key][entry.value] = None
|
|
390
391
|
|
|
391
392
|
self._git.validate_config()
|
|
392
393
|
for section_name, section_dict in sections.items():
|
|
@@ -661,6 +662,18 @@ class Git:
|
|
|
661
662
|
"""Translate a committish to a refname."""
|
|
662
663
|
return self.committish_to_ref(committish).name
|
|
663
664
|
|
|
665
|
+
def branch_or_committish_ref(self, committish):
|
|
666
|
+
"""Translate a committish to a reference object, or None for one with no
|
|
667
|
+
ref, such as a SHA. A branch wins over a tag of the same name."""
|
|
668
|
+
try:
|
|
669
|
+
branch = self._repo.branches.get(committish)
|
|
670
|
+
except pygit2.InvalidSpecError:
|
|
671
|
+
# Not a branch name at all, such as master~1.
|
|
672
|
+
branch = None
|
|
673
|
+
if branch is not None:
|
|
674
|
+
return branch
|
|
675
|
+
return self.committish_to_ref(committish)
|
|
676
|
+
|
|
664
677
|
def get_committish_commit(self, committish):
|
|
665
678
|
"""Get the commit object for a committish."""
|
|
666
679
|
commit = self._repo.revparse_single(committish)
|
|
@@ -832,8 +845,11 @@ class Git:
|
|
|
832
845
|
on the remote under another branch.
|
|
833
846
|
|
|
834
847
|
"""
|
|
835
|
-
|
|
836
|
-
|
|
848
|
+
ref = self.branch_or_committish_ref(committish)
|
|
849
|
+
if ref is None:
|
|
850
|
+
return False
|
|
851
|
+
refname = ref.name
|
|
852
|
+
local_oid = self.get_committish_oid(refname)
|
|
837
853
|
remote_refname = self.get_remote_push_refname(refname, remote)
|
|
838
854
|
if not self.committish_exists(remote_refname):
|
|
839
855
|
return False
|
|
@@ -1137,7 +1153,7 @@ class Git:
|
|
|
1137
1153
|
|
|
1138
1154
|
def checkout(self, committish):
|
|
1139
1155
|
"""Make the given committish active in the current worktree."""
|
|
1140
|
-
refname = self.
|
|
1156
|
+
refname = self.branch_or_committish_ref(committish).name
|
|
1141
1157
|
self._repo.checkout(refname)
|
|
1142
1158
|
|
|
1143
1159
|
def add_worktree(self, name, path, committish):
|
|
@@ -1145,7 +1161,7 @@ class Git:
|
|
|
1145
1161
|
with the given name to use as a handle.
|
|
1146
1162
|
|
|
1147
1163
|
"""
|
|
1148
|
-
ref = self.
|
|
1164
|
+
ref = self.branch_or_committish_ref(committish)
|
|
1149
1165
|
parent_path = Path(path).parent
|
|
1150
1166
|
if not parent_path.exists():
|
|
1151
1167
|
os.makedirs(parent_path)
|
|
@@ -1174,7 +1190,7 @@ class Git:
|
|
|
1174
1190
|
|
|
1175
1191
|
"""
|
|
1176
1192
|
ref = self._repo.references.get(name)
|
|
1177
|
-
refname = self.
|
|
1193
|
+
refname = self.branch_or_committish_ref(committish).name
|
|
1178
1194
|
if ref:
|
|
1179
1195
|
ref.set_target(
|
|
1180
1196
|
refname, f"Reset {name} to {committish} for worktree"
|
|
@@ -44,11 +44,15 @@ does the work, in this order:
|
|
|
44
44
|
#. Check the config file again, and return what ``func`` returned.
|
|
45
45
|
|
|
46
46
|
main exits with that value when it is an int, and with 0 otherwise. A
|
|
47
|
+
negative value -N, from a command killed by signal N, makes main die of
|
|
48
|
+
signal N, or exit with 128+N if the signal does not stop it. A
|
|
47
49
|
GitProjectError prints its message and exits with a failure status. See
|
|
48
50
|
git_project.plugin for what a plugin does at each step.
|
|
49
51
|
|
|
50
52
|
"""
|
|
51
53
|
|
|
54
|
+
import os
|
|
55
|
+
import signal
|
|
52
56
|
import sys
|
|
53
57
|
from pathlib import Path
|
|
54
58
|
|
|
@@ -101,6 +105,18 @@ def main_impl(args=None):
|
|
|
101
105
|
def main(args=None):
|
|
102
106
|
try:
|
|
103
107
|
rc = main_impl(args)
|
|
108
|
+
if isinstance(rc, int) and rc < 0:
|
|
109
|
+
# A command killed by signal N gives -N. Die of the same signal,
|
|
110
|
+
# so that a shell running us in a loop sees the Ctrl-C and stops.
|
|
111
|
+
sys.stdout.flush()
|
|
112
|
+
sys.stderr.flush()
|
|
113
|
+
try:
|
|
114
|
+
signal.signal(-rc, signal.SIG_DFL)
|
|
115
|
+
except (OSError, ValueError):
|
|
116
|
+
pass
|
|
117
|
+
else:
|
|
118
|
+
os.kill(os.getpid(), -rc)
|
|
119
|
+
raise SystemExit(128 - rc)
|
|
104
120
|
# Only an int return is an exit code; command funcs may return a
|
|
105
121
|
# domain object (e.g. the created Worktree), which must not turn a
|
|
106
122
|
# successful run into a non-zero process exit.
|
|
@@ -157,7 +157,9 @@ class Project(ScopedConfigObject):
|
|
|
157
157
|
committish: The committish to check
|
|
158
158
|
|
|
159
159
|
"""
|
|
160
|
-
|
|
160
|
+
ref = self._git.branch_or_committish_ref(committish)
|
|
161
|
+
# A bare SHA has no ref, and revparse takes it as it is.
|
|
162
|
+
refname = ref.name if ref is not None else committish
|
|
161
163
|
for target in self.iterbranches():
|
|
162
164
|
target_refname = target
|
|
163
165
|
if target in self._git.iterbranches():
|
|
@@ -184,8 +186,11 @@ class Project(ScopedConfigObject):
|
|
|
184
186
|
committish: The committish to check
|
|
185
187
|
|
|
186
188
|
"""
|
|
189
|
+
ref = self._git.branch_or_committish_ref(committish)
|
|
190
|
+
# A bare SHA has no ref, and revparse takes it as it is.
|
|
191
|
+
refname = ref.name if ref is not None else committish
|
|
187
192
|
for branch in self.iterbranches():
|
|
188
|
-
if self._git.refname_is_merged(
|
|
193
|
+
if self._git.refname_is_merged(refname, branch):
|
|
189
194
|
return True
|
|
190
195
|
# See if it might be merged (and therefore pushed) on the remote.
|
|
191
196
|
return self.branch_is_merged_remotely(committish)
|
|
@@ -34,9 +34,12 @@ with shlex.split and run the result directly.
|
|
|
34
34
|
"""
|
|
35
35
|
|
|
36
36
|
import io
|
|
37
|
+
import os
|
|
37
38
|
import shlex
|
|
39
|
+
import signal
|
|
38
40
|
import subprocess
|
|
39
41
|
import tempfile
|
|
42
|
+
import threading
|
|
40
43
|
|
|
41
44
|
|
|
42
45
|
def run_command_with_shell(command, dry_run=False, show_command=False):
|
|
@@ -48,20 +51,66 @@ def run_command_with_shell(command, dry_run=False, show_command=False):
|
|
|
48
51
|
|
|
49
52
|
show_command: Print the command before running it.
|
|
50
53
|
|
|
54
|
+
While the command runs, SIGINT and SIGTERM do not stop this process.
|
|
55
|
+
A SIGTERM is sent on to the command. A SIGINT is sent on only when
|
|
56
|
+
this process is not in the terminal's foreground group, since a
|
|
57
|
+
Ctrl-C there reaches the command directly. The command decides
|
|
58
|
+
whether to exit, and its status is returned. Off the main thread,
|
|
59
|
+
signals are left alone.
|
|
60
|
+
|
|
51
61
|
"""
|
|
52
62
|
|
|
53
63
|
if dry_run or show_command:
|
|
54
64
|
print(command)
|
|
55
65
|
|
|
56
66
|
if not dry_run:
|
|
57
|
-
|
|
67
|
+
if threading.current_thread() is not threading.main_thread():
|
|
68
|
+
# Only the main thread can install a signal handler.
|
|
69
|
+
return subprocess.Popen(command, shell=True).wait()
|
|
70
|
+
|
|
71
|
+
proc = None
|
|
72
|
+
pending = []
|
|
73
|
+
|
|
74
|
+
def forward(signum, frame):
|
|
75
|
+
if proc is None:
|
|
76
|
+
pending.append(signum)
|
|
77
|
+
elif not (signum == signal.SIGINT and _terminal_signals_us()):
|
|
78
|
+
proc.send_signal(signum)
|
|
79
|
+
|
|
80
|
+
# A Python handler, not SIG_IGN, so that exec resets it to the
|
|
81
|
+
# default in the child.
|
|
82
|
+
old_int = signal.signal(signal.SIGINT, forward)
|
|
83
|
+
old_term = signal.signal(signal.SIGTERM, forward)
|
|
84
|
+
try:
|
|
85
|
+
proc = subprocess.Popen(command, shell=True)
|
|
86
|
+
# Popen has returned, so the handler can send directly. A signal
|
|
87
|
+
# queued while Popen ran is sent now, which can repeat a Ctrl-C the
|
|
88
|
+
# child already got if it came after the fork.
|
|
89
|
+
for signum in pending:
|
|
90
|
+
proc.send_signal(signum)
|
|
91
|
+
return proc.wait()
|
|
92
|
+
finally:
|
|
93
|
+
signal.signal(signal.SIGINT, old_int)
|
|
94
|
+
signal.signal(signal.SIGTERM, old_term)
|
|
58
95
|
|
|
59
|
-
|
|
60
|
-
proc.communicate()
|
|
96
|
+
return 0
|
|
61
97
|
|
|
62
|
-
return proc.returncode
|
|
63
98
|
|
|
64
|
-
|
|
99
|
+
def _terminal_signals_us():
|
|
100
|
+
"""Return whether our process group is in the foreground of the
|
|
101
|
+
controlling terminal. A Ctrl-C there has reached the child already.
|
|
102
|
+
|
|
103
|
+
"""
|
|
104
|
+
try:
|
|
105
|
+
fd = os.open("/dev/tty", os.O_RDONLY)
|
|
106
|
+
except OSError:
|
|
107
|
+
return False
|
|
108
|
+
try:
|
|
109
|
+
return os.tcgetpgrp(fd) == os.getpgrp()
|
|
110
|
+
except OSError:
|
|
111
|
+
return False
|
|
112
|
+
finally:
|
|
113
|
+
os.close(fd)
|
|
65
114
|
|
|
66
115
|
|
|
67
116
|
def capture_command(
|
|
@@ -21,7 +21,10 @@
|
|
|
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
|
+
import json
|
|
24
25
|
import os
|
|
26
|
+
import subprocess
|
|
27
|
+
import sys
|
|
25
28
|
|
|
26
29
|
import pygit2
|
|
27
30
|
import pytest
|
|
@@ -221,6 +224,46 @@ def test_confobj_multival(reset_directory, git):
|
|
|
221
224
|
assert values == {"one", "two"}
|
|
222
225
|
|
|
223
226
|
|
|
227
|
+
# Eight values in no sorted order, so neither a set nor a sort yields
|
|
228
|
+
# this order by chance.
|
|
229
|
+
MULTIVAL_ORDER = ["hello", "bye", "zeta", "alpha", "mid", "omega", "beta", "x"]
|
|
230
|
+
|
|
231
|
+
MULTIVAL_READER = """
|
|
232
|
+
import json
|
|
233
|
+
import git_project
|
|
234
|
+
|
|
235
|
+
class MyThing(git_project.ConfigObject):
|
|
236
|
+
pass
|
|
237
|
+
|
|
238
|
+
git = git_project.Git()
|
|
239
|
+
thing = MyThing.get(git, "project", "mything", "test")
|
|
240
|
+
print(json.dumps([list(thing.iter_multival("test")), list(thing.test)]))
|
|
241
|
+
"""
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
@pytest.mark.parametrize("seed", ["0", "1", "2", "3", "4"])
|
|
245
|
+
def test_confobj_multival_keeps_config_order(reset_directory, git, seed):
|
|
246
|
+
thing = MyThing.get(git, "project", "test")
|
|
247
|
+
for value in MULTIVAL_ORDER:
|
|
248
|
+
thing.add_item("test", value)
|
|
249
|
+
|
|
250
|
+
assert list(thing.iter_multival("test")) == MULTIVAL_ORDER
|
|
251
|
+
assert thing.test == tuple(MULTIVAL_ORDER)
|
|
252
|
+
|
|
253
|
+
# A new process loads the config fresh, and its string hashes change
|
|
254
|
+
# with the seed.
|
|
255
|
+
env = dict(os.environ, PYTHONHASHSEED=seed)
|
|
256
|
+
proc = subprocess.run(
|
|
257
|
+
[sys.executable, "-c", MULTIVAL_READER],
|
|
258
|
+
env=env,
|
|
259
|
+
capture_output=True,
|
|
260
|
+
text=True,
|
|
261
|
+
check=True,
|
|
262
|
+
timeout=60,
|
|
263
|
+
)
|
|
264
|
+
assert json.loads(proc.stdout) == [MULTIVAL_ORDER, MULTIVAL_ORDER]
|
|
265
|
+
|
|
266
|
+
|
|
224
267
|
def test_confobj_write(reset_directory, git):
|
|
225
268
|
thing = MyThing.get(git, "project", "test")
|
|
226
269
|
|
|
@@ -291,7 +334,7 @@ def test_confobj_iteritems_multi(reset_directory, git):
|
|
|
291
334
|
|
|
292
335
|
assert result == [
|
|
293
336
|
("first", "firstdefault"),
|
|
294
|
-
("second",
|
|
337
|
+
("second", ("seconddefault", "secondsecond")),
|
|
295
338
|
]
|
|
296
339
|
|
|
297
340
|
|
|
@@ -309,7 +352,7 @@ def test_confobj_get_multi(reset_directory, git):
|
|
|
309
352
|
|
|
310
353
|
assert result == [
|
|
311
354
|
("first", "firstdefault"),
|
|
312
|
-
("second",
|
|
355
|
+
("second", ("seconddefault", "secondsecond")),
|
|
313
356
|
]
|
|
314
357
|
|
|
315
358
|
|
|
@@ -362,6 +362,28 @@ def test_git_worktree(reset_directory, local_repository):
|
|
|
362
362
|
assert not os.path.exists(worktree_path)
|
|
363
363
|
|
|
364
364
|
|
|
365
|
+
def test_git_add_worktree_tag_shadows_branch(
|
|
366
|
+
reset_directory, local_repository
|
|
367
|
+
):
|
|
368
|
+
os.chdir(local_repository.path)
|
|
369
|
+
|
|
370
|
+
git = git_project.Git()
|
|
371
|
+
|
|
372
|
+
commit, _ref = git._repo.resolve_refish("HEAD")
|
|
373
|
+
git._repo.branches.create("test-wt", commit)
|
|
374
|
+
git._repo.references.create("refs/tags/test-wt", commit.id)
|
|
375
|
+
|
|
376
|
+
worktree_checkout_path = Path.cwd() / ".." / ".." / "test-wt"
|
|
377
|
+
|
|
378
|
+
git.add_worktree("test-wt", str(worktree_checkout_path), "test-wt")
|
|
379
|
+
|
|
380
|
+
worktree_repo = pygit2.Repository(str(worktree_checkout_path))
|
|
381
|
+
assert worktree_repo.head.name == "refs/heads/test-wt"
|
|
382
|
+
|
|
383
|
+
shutil.rmtree(worktree_checkout_path)
|
|
384
|
+
git.prune_worktree("test-wt")
|
|
385
|
+
|
|
386
|
+
|
|
365
387
|
def test_git_get_working_copy_root(reset_directory, local_repository):
|
|
366
388
|
os.chdir(local_repository.path)
|
|
367
389
|
|
|
@@ -404,6 +426,29 @@ def test_git_committish_to_refname(reset_directory, local_repository):
|
|
|
404
426
|
assert git.committish_to_refname("HEAD") == "refs/heads/master"
|
|
405
427
|
|
|
406
428
|
|
|
429
|
+
def test_git_branch_or_committish_ref_tag_shadows_branch(
|
|
430
|
+
reset_directory, local_repository
|
|
431
|
+
):
|
|
432
|
+
os.chdir(local_repository.path)
|
|
433
|
+
|
|
434
|
+
master = local_repository.revparse_single("refs/heads/master")
|
|
435
|
+
local_repository.references.create("refs/tags/unmerged", master.id)
|
|
436
|
+
local_repository.references.create("refs/tags/only-a-tag", master.id)
|
|
437
|
+
|
|
438
|
+
git = git_project.Git()
|
|
439
|
+
|
|
440
|
+
assert (
|
|
441
|
+
git.branch_or_committish_ref("unmerged").name == "refs/heads/unmerged"
|
|
442
|
+
)
|
|
443
|
+
assert (
|
|
444
|
+
git.branch_or_committish_ref("only-a-tag").name
|
|
445
|
+
== "refs/tags/only-a-tag"
|
|
446
|
+
)
|
|
447
|
+
assert git.branch_or_committish_ref("HEAD").name == "refs/heads/master"
|
|
448
|
+
assert git.branch_or_committish_ref("master~1") is None
|
|
449
|
+
assert git.branch_or_committish_ref(str(master.id)) is None
|
|
450
|
+
|
|
451
|
+
|
|
407
452
|
def test_git_get_committish_oid(reset_directory, local_repository):
|
|
408
453
|
os.chdir(local_repository.path)
|
|
409
454
|
|
|
@@ -560,6 +605,22 @@ def test_git_committish_is_pushed(reset_directory, local_repository):
|
|
|
560
605
|
assert not git.committish_is_pushed("notpushed", "origin")
|
|
561
606
|
|
|
562
607
|
|
|
608
|
+
def test_git_committish_is_pushed_tag_shadows_branch(
|
|
609
|
+
reset_directory, local_repository
|
|
610
|
+
):
|
|
611
|
+
os.chdir(local_repository.path)
|
|
612
|
+
|
|
613
|
+
pushed = local_repository.revparse_single("refs/heads/pushed")
|
|
614
|
+
notpushed = local_repository.revparse_single("refs/heads/notpushed")
|
|
615
|
+
local_repository.references.create("refs/tags/pushed", notpushed.id)
|
|
616
|
+
local_repository.references.create("refs/tags/notpushed", pushed.id)
|
|
617
|
+
|
|
618
|
+
git = git_project.Git()
|
|
619
|
+
|
|
620
|
+
assert git.committish_is_pushed("pushed", "origin")
|
|
621
|
+
assert not git.committish_is_pushed("notpushed", "origin")
|
|
622
|
+
|
|
623
|
+
|
|
563
624
|
def test_git_refname_is_merged(reset_directory, local_repository):
|
|
564
625
|
os.chdir(local_repository.path)
|
|
565
626
|
|
|
@@ -1401,6 +1462,19 @@ def test_git_checkout(reset_directory, local_repository):
|
|
|
1401
1462
|
)
|
|
1402
1463
|
|
|
1403
1464
|
|
|
1465
|
+
def test_git_checkout_tag_shadows_branch(reset_directory, local_repository):
|
|
1466
|
+
os.chdir(local_repository.path)
|
|
1467
|
+
|
|
1468
|
+
master = local_repository.revparse_single("refs/heads/master")
|
|
1469
|
+
local_repository.references.create("refs/tags/unmerged", master.id)
|
|
1470
|
+
|
|
1471
|
+
git = git_project.Git()
|
|
1472
|
+
|
|
1473
|
+
git.checkout("unmerged")
|
|
1474
|
+
|
|
1475
|
+
assert git.get_current_refname() == "refs/heads/unmerged"
|
|
1476
|
+
|
|
1477
|
+
|
|
1404
1478
|
def test_git_update_symbolic_ref(reset_directory, local_repository):
|
|
1405
1479
|
os.chdir(local_repository.path)
|
|
1406
1480
|
|
|
@@ -1423,6 +1497,21 @@ def test_git_update_symbolic_ref(reset_directory, local_repository):
|
|
|
1423
1497
|
assert git.get_committish_oid("HEAD") == git.get_committish_oid("master")
|
|
1424
1498
|
|
|
1425
1499
|
|
|
1500
|
+
def test_git_update_symbolic_ref_tag_shadows_branch(
|
|
1501
|
+
reset_directory, local_repository
|
|
1502
|
+
):
|
|
1503
|
+
os.chdir(local_repository.path)
|
|
1504
|
+
|
|
1505
|
+
master = local_repository.revparse_single("refs/heads/master")
|
|
1506
|
+
local_repository.references.create("refs/tags/unmerged", master.id)
|
|
1507
|
+
|
|
1508
|
+
git = git_project.Git()
|
|
1509
|
+
|
|
1510
|
+
git.update_symbolic_ref("HEAD", "unmerged")
|
|
1511
|
+
|
|
1512
|
+
assert local_repository.references["HEAD"].target == "refs/heads/unmerged"
|
|
1513
|
+
|
|
1514
|
+
|
|
1426
1515
|
def test_git_delete_branch(reset_directory, local_repository):
|
|
1427
1516
|
os.chdir(local_repository.path)
|
|
1428
1517
|
|
|
@@ -21,6 +21,9 @@
|
|
|
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
|
+
import signal
|
|
25
|
+
import subprocess
|
|
26
|
+
import sys
|
|
24
27
|
|
|
25
28
|
import pytest
|
|
26
29
|
|
|
@@ -123,3 +126,38 @@ def test_main_project_defaults_before_initialize(
|
|
|
123
126
|
git_project.main_impl(["look"])
|
|
124
127
|
|
|
125
128
|
assert defaults_plugin.branch_at_initialize is True
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
@pytest.mark.parametrize("signum", [signal.SIGINT, signal.SIGTERM])
|
|
132
|
+
def test_main_dies_of_the_signal_that_killed_the_command(signum):
|
|
133
|
+
# Stand in for a command func whose child was killed by signum.
|
|
134
|
+
code = (
|
|
135
|
+
"import git_project.main as m\n"
|
|
136
|
+
f"m.main_impl = lambda args=None: {-signum}\n"
|
|
137
|
+
"m.main()\n"
|
|
138
|
+
)
|
|
139
|
+
proc = subprocess.run(
|
|
140
|
+
[sys.executable, "-c", code],
|
|
141
|
+
capture_output=True,
|
|
142
|
+
check=False,
|
|
143
|
+
timeout=10,
|
|
144
|
+
)
|
|
145
|
+
assert b"Traceback" not in proc.stderr
|
|
146
|
+
assert proc.returncode == -signum
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def test_main_exits_128_plus_n_for_an_uncatchable_signal():
|
|
150
|
+
# SIGKILL cannot be reset to its default, so main exits 128+N instead.
|
|
151
|
+
code = (
|
|
152
|
+
"import git_project.main as m\n"
|
|
153
|
+
f"m.main_impl = lambda args=None: {-signal.SIGKILL}\n"
|
|
154
|
+
"m.main()\n"
|
|
155
|
+
)
|
|
156
|
+
proc = subprocess.run(
|
|
157
|
+
[sys.executable, "-c", code],
|
|
158
|
+
capture_output=True,
|
|
159
|
+
check=False,
|
|
160
|
+
timeout=10,
|
|
161
|
+
)
|
|
162
|
+
assert b"Traceback" not in proc.stderr
|
|
163
|
+
assert proc.returncode == 128 + signal.SIGKILL
|
|
@@ -133,6 +133,37 @@ def test_project_branch_is_merged_tag_shadows_branch(git):
|
|
|
133
133
|
assert not project.branch_is_merged("refs/heads/unmerged")
|
|
134
134
|
|
|
135
135
|
|
|
136
|
+
def test_project_branch_is_merged_short_name_tag_shadows_branch(git, project):
|
|
137
|
+
# A tag named like the branch being checked, on master.
|
|
138
|
+
repo = git._repo
|
|
139
|
+
master = repo.revparse_single("refs/heads/master")
|
|
140
|
+
repo.references.create("refs/tags/unmerged", master.id)
|
|
141
|
+
|
|
142
|
+
assert not project.branch_is_merged("unmerged")
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
def test_project_branch_is_merged_sha(git, project):
|
|
146
|
+
merged_local = git._repo.revparse_single("refs/heads/merged_local")
|
|
147
|
+
|
|
148
|
+
assert project.branch_is_merged(str(merged_local.id))
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
def test_project_unmerged_sha(git, project):
|
|
152
|
+
unmerged = git._repo.revparse_single("refs/heads/unmerged")
|
|
153
|
+
|
|
154
|
+
assert not project.branch_is_merged(str(unmerged.id))
|
|
155
|
+
assert not project.branch_is_pushed(str(unmerged.id))
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_project_branch_is_merged_remotely_tag_shadows_branch(git, project):
|
|
159
|
+
# A tag named like the branch being checked, on origin/master.
|
|
160
|
+
repo = git._repo
|
|
161
|
+
origin_master = repo.revparse_single("refs/remotes/origin/master")
|
|
162
|
+
repo.references.create("refs/tags/notpushed", origin_master.id)
|
|
163
|
+
|
|
164
|
+
assert not project.branch_is_merged_remotely("notpushed")
|
|
165
|
+
|
|
166
|
+
|
|
136
167
|
def test_project_branch_is_pushed(project):
|
|
137
168
|
assert not project.branch_is_pushed("master")
|
|
138
169
|
assert project.branch_is_pushed("pushed")
|
|
@@ -185,7 +185,7 @@ def test_scopedobj_iteritems_multi(reset_directory, git):
|
|
|
185
185
|
|
|
186
186
|
assert result == {
|
|
187
187
|
("name", "child"),
|
|
188
|
-
("value",
|
|
188
|
+
("value", ("ChildScope", "second")),
|
|
189
189
|
("parentonly", "ParentOnly"),
|
|
190
190
|
("childonly", "ChildOnly"),
|
|
191
191
|
}
|
|
@@ -0,0 +1,220 @@
|
|
|
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 2020 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
|
+
import os
|
|
25
|
+
import pty
|
|
26
|
+
import select
|
|
27
|
+
import shlex
|
|
28
|
+
import signal
|
|
29
|
+
import subprocess
|
|
30
|
+
import sys
|
|
31
|
+
import threading
|
|
32
|
+
import time
|
|
33
|
+
|
|
34
|
+
import pytest
|
|
35
|
+
|
|
36
|
+
import git_project
|
|
37
|
+
|
|
38
|
+
TIMEOUT = 10
|
|
39
|
+
|
|
40
|
+
# Counts the named signal, then exits 7 a little after the first one so that
|
|
41
|
+
# a duplicate delivery is counted too. With "die" it takes the default action.
|
|
42
|
+
CHILD = """
|
|
43
|
+
import signal, sys, time
|
|
44
|
+
hits = []
|
|
45
|
+
if sys.argv[1] == "die":
|
|
46
|
+
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
|
47
|
+
else:
|
|
48
|
+
signal.signal(getattr(signal, sys.argv[1]), lambda s, f: hits.append(s))
|
|
49
|
+
print("ready", flush=True)
|
|
50
|
+
deadline = time.monotonic() + 10
|
|
51
|
+
while not hits and time.monotonic() < deadline:
|
|
52
|
+
time.sleep(0.01)
|
|
53
|
+
time.sleep(0.3)
|
|
54
|
+
print(f"got {len(hits)}", flush=True)
|
|
55
|
+
sys.exit(7)
|
|
56
|
+
"""
|
|
57
|
+
|
|
58
|
+
PARENT = """
|
|
59
|
+
import signal, sys
|
|
60
|
+
import git_project
|
|
61
|
+
rc = git_project.run_command_with_shell(sys.argv[1])
|
|
62
|
+
print(f"rc {rc}", flush=True)
|
|
63
|
+
restored = (
|
|
64
|
+
signal.getsignal(signal.SIGINT) is signal.default_int_handler
|
|
65
|
+
and signal.getsignal(signal.SIGTERM) == signal.SIG_DFL
|
|
66
|
+
)
|
|
67
|
+
print(f"restored {restored}", flush=True)
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def child_command(mode):
|
|
72
|
+
return shlex.join([sys.executable, "-c", CHILD, mode])
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def read_until(fd, marker):
|
|
76
|
+
out = b""
|
|
77
|
+
deadline = time.monotonic() + TIMEOUT
|
|
78
|
+
while marker not in out:
|
|
79
|
+
ready, _, _ = select.select([fd], [], [], deadline - time.monotonic())
|
|
80
|
+
assert ready, f"timed out waiting for {marker!r}: {out!r}"
|
|
81
|
+
try:
|
|
82
|
+
chunk = os.read(fd, 4096)
|
|
83
|
+
except OSError:
|
|
84
|
+
break
|
|
85
|
+
if not chunk:
|
|
86
|
+
break
|
|
87
|
+
out += chunk
|
|
88
|
+
return out
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def run_parent_and_signal(mode, signum):
|
|
92
|
+
"""Run PARENT without a terminal and send signum to its pid alone."""
|
|
93
|
+
proc = subprocess.Popen(
|
|
94
|
+
[sys.executable, "-c", PARENT, child_command(mode)],
|
|
95
|
+
stdout=subprocess.PIPE,
|
|
96
|
+
stderr=subprocess.PIPE,
|
|
97
|
+
start_new_session=True,
|
|
98
|
+
)
|
|
99
|
+
try:
|
|
100
|
+
read_until(proc.stdout.fileno(), b"ready")
|
|
101
|
+
os.kill(proc.pid, signum)
|
|
102
|
+
out, err = proc.communicate(timeout=TIMEOUT)
|
|
103
|
+
finally:
|
|
104
|
+
proc.kill()
|
|
105
|
+
proc.wait(timeout=TIMEOUT)
|
|
106
|
+
proc.stdout.close()
|
|
107
|
+
proc.stderr.close()
|
|
108
|
+
return proc.returncode, out.decode(), err.decode()
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_run_command_with_shell_returns_zero_on_success():
|
|
112
|
+
assert git_project.run_command_with_shell("true") == 0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def test_run_command_with_shell_returns_nonzero_on_failure():
|
|
116
|
+
assert git_project.run_command_with_shell("false") != 0
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
def test_run_command_with_shell_dry_run_returns_zero():
|
|
120
|
+
assert git_project.run_command_with_shell("false", dry_run=True) == 0
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def test_iter_command_yields_lines():
|
|
124
|
+
assert list(git_project.iter_command('printf "a\\nb\\n"')) == [
|
|
125
|
+
"a\n",
|
|
126
|
+
"b\n",
|
|
127
|
+
]
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
def test_iter_command_failure_reports_status_and_stderr():
|
|
131
|
+
with pytest.raises(Exception, match="exited with code 3") as info:
|
|
132
|
+
list(git_project.iter_command('sh -c "echo oops >&2; exit 3"'))
|
|
133
|
+
assert "oops" in str(info.value)
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def test_capture_command_takes_a_list():
|
|
137
|
+
assert git_project.capture_command(["printf", "%s", "a b"]) == b"a b"
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
@pytest.mark.parametrize("signame", ["SIGINT", "SIGTERM"])
|
|
141
|
+
def test_run_command_with_shell_forwards_a_signal_sent_to_its_pid(signame):
|
|
142
|
+
rc, out, err = run_parent_and_signal(signame, getattr(signal, signame))
|
|
143
|
+
assert "Traceback" not in err
|
|
144
|
+
assert rc == 0
|
|
145
|
+
assert "got 1" in out
|
|
146
|
+
assert "rc 7" in out
|
|
147
|
+
assert "restored True" in out
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def test_run_command_with_shell_returns_status_of_a_killed_child():
|
|
151
|
+
rc, out, err = run_parent_and_signal("die", signal.SIGINT)
|
|
152
|
+
assert "Traceback" not in err
|
|
153
|
+
assert rc == 0
|
|
154
|
+
assert f"rc {-signal.SIGINT}" in out
|
|
155
|
+
assert "restored True" in out
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def test_run_command_with_shell_survives_ctrl_c_from_the_terminal():
|
|
159
|
+
pid, master = pty.fork()
|
|
160
|
+
if pid == 0:
|
|
161
|
+
try:
|
|
162
|
+
os.execv(
|
|
163
|
+
sys.executable,
|
|
164
|
+
[sys.executable, "-c", PARENT, child_command("SIGINT")],
|
|
165
|
+
)
|
|
166
|
+
finally:
|
|
167
|
+
os._exit(127)
|
|
168
|
+
done = 0
|
|
169
|
+
try:
|
|
170
|
+
out = read_until(master, b"ready")
|
|
171
|
+
os.write(master, b"\x03")
|
|
172
|
+
out += read_until(master, b"restored")
|
|
173
|
+
out += read_until(master, b"\n")
|
|
174
|
+
deadline = time.monotonic() + TIMEOUT
|
|
175
|
+
while True:
|
|
176
|
+
done, status = os.waitpid(pid, os.WNOHANG)
|
|
177
|
+
if done:
|
|
178
|
+
break
|
|
179
|
+
assert time.monotonic() < deadline, out
|
|
180
|
+
time.sleep(0.01)
|
|
181
|
+
finally:
|
|
182
|
+
if not done:
|
|
183
|
+
os.kill(pid, signal.SIGKILL)
|
|
184
|
+
os.waitpid(pid, 0)
|
|
185
|
+
os.close(master)
|
|
186
|
+
out = out.decode(errors="replace")
|
|
187
|
+
assert "Traceback" not in out
|
|
188
|
+
assert os.waitstatus_to_exitcode(status) == 0
|
|
189
|
+
# The child shares the terminal's foreground group, so the parent must
|
|
190
|
+
# not send it a second SIGINT.
|
|
191
|
+
assert "got 1" in out
|
|
192
|
+
assert "rc 7" in out
|
|
193
|
+
assert "restored True" in out
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
def test_run_command_with_shell_restores_signal_handlers():
|
|
197
|
+
def handler(signum, frame):
|
|
198
|
+
pass
|
|
199
|
+
|
|
200
|
+
old_int = signal.signal(signal.SIGINT, handler)
|
|
201
|
+
old_term = signal.signal(signal.SIGTERM, handler)
|
|
202
|
+
try:
|
|
203
|
+
assert git_project.run_command_with_shell("true") == 0
|
|
204
|
+
assert signal.getsignal(signal.SIGINT) is handler
|
|
205
|
+
assert signal.getsignal(signal.SIGTERM) is handler
|
|
206
|
+
finally:
|
|
207
|
+
signal.signal(signal.SIGINT, old_int)
|
|
208
|
+
signal.signal(signal.SIGTERM, old_term)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def test_run_command_with_shell_runs_off_the_main_thread():
|
|
212
|
+
result = []
|
|
213
|
+
thread = threading.Thread(
|
|
214
|
+
target=lambda: result.append(
|
|
215
|
+
git_project.run_command_with_shell("exit 3")
|
|
216
|
+
)
|
|
217
|
+
)
|
|
218
|
+
thread.start()
|
|
219
|
+
thread.join(timeout=TIMEOUT)
|
|
220
|
+
assert result == [3]
|
|
@@ -1,55 +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 2020 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
|
-
import pytest
|
|
25
|
-
|
|
26
|
-
import git_project
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def test_run_command_with_shell_returns_zero_on_success():
|
|
30
|
-
assert git_project.run_command_with_shell("true") == 0
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def test_run_command_with_shell_returns_nonzero_on_failure():
|
|
34
|
-
assert git_project.run_command_with_shell("false") != 0
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
def test_run_command_with_shell_dry_run_returns_zero():
|
|
38
|
-
assert git_project.run_command_with_shell("false", dry_run=True) == 0
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
def test_iter_command_yields_lines():
|
|
42
|
-
assert list(git_project.iter_command('printf "a\\nb\\n"')) == [
|
|
43
|
-
"a\n",
|
|
44
|
-
"b\n",
|
|
45
|
-
]
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
def test_iter_command_failure_reports_status_and_stderr():
|
|
49
|
-
with pytest.raises(Exception, match="exited with code 3") as info:
|
|
50
|
-
list(git_project.iter_command('sh -c "echo oops >&2; exit 3"'))
|
|
51
|
-
assert "oops" in str(info.value)
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
def test_capture_command_takes_a_list():
|
|
55
|
-
assert git_project.capture_command(["printf", "%s", "a b"]) == b"a b"
|
|
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
|