Skip to content

Commit 047ac2b

Browse files
committed
push: --ask stops for confirmation on warnings
Resolves: #150 Signed-off-by: Arthur Zamarin <[email protected]>
1 parent d5d4eed commit 047ac2b

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

src/pkgdev/scripts/pkgdev_push.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import shlex
33

44
from pkgcheck import reporters, scan
5+
from pkgcheck.results import Warning as PkgcheckWarning
56
from snakeoil.cli import arghparse
67
from snakeoil.cli.input import userquery
78

@@ -58,17 +59,23 @@ def _push(options, out, err):
5859

5960
# scan commits for QA issues
6061
pipe = scan(options.scan_args)
62+
has_warnings = False
6163
with reporters.FancyReporter(out) as reporter:
6264
for result in pipe:
6365
reporter.report(result)
66+
if result.level == PkgcheckWarning.level:
67+
has_warnings = True
6468

6569
# fail on errors unless they're ignored
6670
if pipe.errors:
6771
with reporters.FancyReporter(out) as reporter:
6872
out.write(out.bold, out.fg("red"), "\nFAILURES", out.reset)
6973
for result in sorted(pipe.errors):
7074
reporter.report(result)
71-
if not (options.ask and userquery("Push commits anyway?", out, err)):
75+
if not (options.ask and userquery("Push commits anyway?", out, err, default_answer=False)):
76+
return 1
77+
elif has_warnings and options.ask:
78+
if not userquery("warnings detected, push commits anyway?", out, err, default_answer=False):
7279
return 1
7380

7481
# push commits upstream

tests/scripts/test_pkgdev_push.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,26 @@ def test_failed_push(self, capsys):
124124
), pytest.raises(SystemExit) as excinfo, chdir(self.child_git_repo.path):
125125
self.script()
126126
assert excinfo.value.code == 0
127+
128+
def test_warnings(self, capsys):
129+
pkgdir = os.path.dirname(self.child_repo.create_ebuild("cat/pkg-1"))
130+
os.makedirs((filesdir := pjoin(pkgdir, "files")), exist_ok=True)
131+
with open(pjoin(filesdir, "foo"), "w") as f:
132+
f.write("")
133+
self.child_git_repo.add_all("cat/pkg-1")
134+
135+
# scans with warnings ask for confirmation before pushing with "--ask"
136+
with patch("sys.argv", self.args + ["--ask"]), patch(
137+
"sys.stdin", StringIO("n\n")
138+
), pytest.raises(SystemExit) as excinfo, chdir(self.child_git_repo.path):
139+
self.script()
140+
assert excinfo.value.code == 1
141+
out, err = capsys.readouterr()
142+
assert "EmptyFile" in out
143+
144+
# but without "--ask" it still pushes
145+
with patch("sys.argv", self.args), pytest.raises(SystemExit) as excinfo, chdir(
146+
self.child_git_repo.path
147+
):
148+
self.script()
149+
assert excinfo.value.code == 0

0 commit comments

Comments
 (0)