[projects/git-slug] Tryb --quiet wycisza komunikat o pobraniu refs
arekm
arekm at pld-linux.org
Tue May 12 15:09:00 CEST 2026
commit 7634c64db659833c43eb5e4b094b2f02371eb52b
Author: Arkadiusz Miśkiewicz <arekm at maven.pl>
Date: Wed Apr 8 00:09:03 2026 +0200
Tryb --quiet wycisza komunikat o pobraniu refs
Komunikat 'Fetched refs from server' był drukowany bezwarunkowo,
ignorując flagę --quiet. Teraz respektuje ją jak pozostałe
komunikaty postępu w fetch_packages().
slug.py | 11 ++++++-----
tests/test_failure_paths.py | 46 +++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 52 insertions(+), 5 deletions(-)
---
diff --git a/slug.py b/slug.py
index d8aa7c3..29c1fcd 100755
--- a/slug.py
+++ b/slug.py
@@ -616,11 +616,12 @@ def fetch_packages(options, return_all=False):
"""
branch_refs = getrefs(options.branch, options.repopattern)
all_refs = branch_refs
- import datetime
- refs_time = datetime.datetime.fromtimestamp(
- branch_refs.refs_mtime, datetime.timezone.utc).astimezone().strftime('%Y-%m-%d %H:%M:%S %Z')
- print('Fetched refs from server (last change: {})'.format(refs_time),
- file=sys.stderr)
+ if not options.quiet:
+ import datetime
+ refs_time = datetime.datetime.fromtimestamp(
+ branch_refs.refs_mtime, datetime.timezone.utc).astimezone().strftime('%Y-%m-%d %H:%M:%S %Z')
+ print('Fetched refs from server (last change: {})'.format(refs_time),
+ file=sys.stderr)
had_errors = False
pkgs_new = []
if options.newpkgs:
diff --git a/tests/test_failure_paths.py b/tests/test_failure_paths.py
index 563b8bc..755539a 100644
--- a/tests/test_failure_paths.py
+++ b/tests/test_failure_paths.py
@@ -232,6 +232,52 @@ def test_fetch_packages_clone_mode_only_fetches_new_repos(monkeypatch, make_opti
assert captured["fetch_args"][0][1] == {"refs/heads/master": "sha-new"}
+def test_fetch_packages_quiet_suppresses_progress_output(monkeypatch, make_options, capsys):
+ # Regresja: komunikat 'Fetched refs from server' (a także pozostałe
+ # komunikaty postępu z fetch_packages) musi respektować --quiet.
+ # Wcześniej drukowany był bezwarunkowo, łamiąc kontrakt trybu cichego.
+ refs = SimpleNamespace(
+ heads={"pkg-a": {"refs/heads/master": "sha-a"}},
+ refs_mtime=0,
+ )
+
+ class FakeGitRepo:
+ def __init__(self, path):
+ self.path = path
+ self.wtree = path
+
+ def fake_run_worker(function, options, args):
+ # Zwróć listę "zaktualizowanych" repo, żeby trafić też w gałąź
+ # drukującą podsumowanie 'Updated N repo(s)...'.
+ return ["updated-pkg-a"]
+
+ monkeypatch.setattr(slug, "getrefs", lambda *args: refs)
+ monkeypatch.setattr(slug.os.path, "isdir", lambda path: True)
+ monkeypatch.setattr(slug, "run_worker", fake_run_worker)
+ monkeypatch.setattr(slug, "GitRepo", FakeGitRepo)
+
+ options = make_options(
+ branch=["master"],
+ repopattern=["pkg-*"],
+ newpkgs=False,
+ prune=False,
+ depth=0,
+ omitexisting=False,
+ quiet=True,
+ )
+
+ result = slug.fetch_packages(options)
+
+ assert result == ["updated-pkg-a"]
+ err = capsys.readouterr().err
+ # W trybie quiet żaden z komunikatów postępu fetch_packages() nie
+ # powinien się pojawić na stderr.
+ assert "Fetched refs from server" not in err
+ assert "Checking" not in err
+ assert "Updated" not in err
+ assert "already up to date" not in err
+
+
def test_fetch_packages_marks_errors_on_partial_init_failures(monkeypatch, make_options):
refs = SimpleNamespace(
heads={
================================================================
---- gitweb:
http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4a7e426b8f1a3571094b5dc89412bc49b8f29666
More information about the pld-cvs-commit
mailing list