From 1a9a473580e9066f5d4a969932d703b5b104b2b7 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 29 Jun 2017 10:23:32 -0400 Subject: [PATCH] cmdline/pull: Print final status even if noninteractive Previously, `ostree pull` was silent if not on a tty. I don't see a reason not to print the final status line at least. This is prep for more work in the test suite, so I can write assertions on the output. But it should also be nicer for people who e.g. do an `ostree pull` in a Jenkins job or whatever. Closes: #981 Approved by: jlebon --- src/ostree/ot-builtin-pull.c | 20 ++++++++++++++++++-- tests/pull-test.sh | 6 ++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/ostree/ot-builtin-pull.c b/src/ostree/ot-builtin-pull.c index bd3ac115..edb09550 100644 --- a/src/ostree/ot-builtin-pull.c +++ b/src/ostree/ot-builtin-pull.c @@ -125,6 +125,13 @@ dry_run_console_progress_changed (OstreeAsyncProgress *progress, g_print ("%s\n", buf->str); } +static void +noninteractive_console_progress_changed (OstreeAsyncProgress *progress, + gpointer user_data) +{ + /* We do nothing here - we just want the final status */ +} + gboolean ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError **error) { @@ -302,6 +309,8 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError ** { if (console.is_tty) progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, &console); + else + progress = ostree_async_progress_new_and_connect (noninteractive_console_progress_changed, &console); } else { @@ -321,8 +330,15 @@ ostree_builtin_pull (int argc, char **argv, GCancellable *cancellable, GError ** progress, cancellable, error)) goto out; - if (progress) - ostree_async_progress_finish (progress); + if (!console.is_tty && !opt_dry_run) + { + g_assert (progress); + const char *status = ostree_async_progress_get_status (progress); + if (status) + g_print ("%s\n", status); + } + + ostree_async_progress_finish (progress); if (opt_dry_run) g_assert (printed_console_progress); diff --git a/tests/pull-test.sh b/tests/pull-test.sh index 7b4fbe94..1da0fa4c 100644 --- a/tests/pull-test.sh +++ b/tests/pull-test.sh @@ -39,8 +39,10 @@ echo "1..25" # Try both syntaxes repo_init --no-gpg-verify -${CMD_PREFIX} ostree --repo=repo pull origin main -${CMD_PREFIX} ostree --repo=repo pull origin:main +${CMD_PREFIX} ostree --repo=repo pull origin main >out.txt +assert_file_has_content out.txt "[1-9][0-9]* metadata, [1-9][0-9]* content objects fetched" +${CMD_PREFIX} ostree --repo=repo pull origin:main > out.txt +assert_not_file_has_content out.txt "content objects fetched" ${CMD_PREFIX} ostree --repo=repo fsck echo "ok pull"