pw_package: Suppress package progress messages
This reduces the output of `pw package install` so that progress info
and detached head warnings are no longer emitted.
Test: pw package remove emboss && pw package install emboss
Change-Id: I4ab91440aec332afd9c132257457781df926a4bf
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/208331
Pigweed-Auto-Submit: Eric Rahm <erahm@google.com>
Reviewed-by: Rob Mohr <mohrr@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Lint: Lint 🤖 <android-build-ayeaye@system.gserviceaccount.com>
diff --git a/pw_package/py/pw_package/git_repo.py b/pw_package/py/pw_package/git_repo.py
index 38c75b1..39ac7fe 100644
--- a/pw_package/py/pw_package/git_repo.py
+++ b/pw_package/py/pw_package/git_repo.py
@@ -24,6 +24,12 @@
_LOG: logging.Logger = logging.getLogger(__name__)
+_GIT_CONFIG = [
+ # Suppress "You are in 'detached HEAD' state" message
+ '-c',
+ 'advice.detachedHead=false',
+]
+
def git_stdout(
*args: Path | str, show_stderr=False, repo: Path | str = '.'
@@ -31,7 +37,7 @@
_LOG.debug('executing %r in %r', args, repo)
return (
subprocess.run(
- ['git', '-C', repo, *args],
+ ['git'] + _GIT_CONFIG + ['-C', repo, *args],
stdout=subprocess.PIPE,
stderr=None if show_stderr else subprocess.DEVNULL,
check=True,
@@ -45,7 +51,9 @@
*args: Path | str, repo: Path | str = '.'
) -> subprocess.CompletedProcess:
_LOG.debug('executing %r in %r', args, repo)
- return subprocess.run(['git', '-C', repo, *args], check=True)
+ return subprocess.run(
+ ['git'] + _GIT_CONFIG + ['-C', repo, *args], check=True
+ )
class GitRepo(pw_package.package_manager.Package):
@@ -143,12 +151,17 @@
# revision. If we later run commands that need history it will be
# retrieved on-demand. For small repositories the effect is negligible
# but for large repositories this should be a significant improvement.
+ # --filter=... causes progress messages to be printed to stderr even if
+ # using --quiet so we wrap our clone command in `get_stdout` to prevent
+ # the output from being emitted.
_LOG.debug('%s: checkout_full', self.name)
if self._commit:
- git('clone', '--filter=blob:none', self._url, path)
+ git_stdout('clone', '--filter=blob:none', self._url, path)
git('reset', '--hard', self._commit, repo=path)
elif self._tag:
- git('clone', '-b', self._tag, '--filter=blob:none', self._url, path)
+ git_stdout(
+ 'clone', '-b', self._tag, '--filter=blob:none', self._url, path
+ )
def checkout_sparse(self, path: Path) -> None:
_LOG.debug('%s: checkout_sparse', self.name)