cmdline/pull: Print final status even if noninteractive
authorColin Walters <walters@verbum.org>
Thu, 29 Jun 2017 14:23:32 +0000 (10:23 -0400)
committerAtomic Bot <atomic-devel@projectatomic.io>
Thu, 29 Jun 2017 16:16:25 +0000 (16:16 +0000)
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
tests/pull-test.sh

index bd3ac11583a725ea32dea027cb5e3b912efa40e2..edb0955088ac9fbd1ba3ffb3ccf147f3326f16c6 100644 (file)
@@ -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);
index 7b4fbe942b6ea6bc00ab76e4dc28e33346d97197..1da0fa4c3c72f7c971908b1db69aa8aca869ed73 100644 (file)
@@ -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"