[ostree] Require a PREFIX when deleting refs



commit 7727fe84d90099efadb535538f9aa22d83f78507
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Jan 6 09:36:45 2015 -0500

    Require a PREFIX when deleting refs
    
    Also fix the "ostree refs" help output to not give the impression that
    the --delete option takes its own PREFIX argument.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=742454

 src/ostree/ot-builtin-refs.c |   10 +++++++++-
 tests/basic-test.sh          |    2 ++
 2 files changed, 11 insertions(+), 1 deletions(-)
---
diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c
index 10dcc72..9b02ca9 100644
--- a/src/ostree/ot-builtin-refs.c
+++ b/src/ostree/ot-builtin-refs.c
@@ -30,7 +30,7 @@
 static gboolean opt_delete;
 
 static GOptionEntry options[] = {
-  { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing 
them", "PREFIX" },
+  { "delete", 0, 0, G_OPTION_ARG_NONE, &opt_delete, "Delete refs which match PREFIX, rather than listing 
them", NULL },
   { NULL }
 };
 
@@ -53,6 +53,14 @@ ostree_builtin_refs (int argc, char **argv, GCancellable *cancellable, GError **
   if (argc >= 2)
     refspec_prefix = argv[1];
 
+  /* Require a prefix when deleting to help avoid accidents. */
+  if (opt_delete && refspec_prefix == NULL)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "PREFIX is required when deleting refs");
+      goto out;
+    }
+
   if (!ostree_repo_list_refs (repo, refspec_prefix, &refs,
                               cancellable, error))
     goto out;
diff --git a/tests/basic-test.sh b/tests/basic-test.sh
index d097a32..106d9f1 100755
--- a/tests/basic-test.sh
+++ b/tests/basic-test.sh
@@ -45,6 +45,8 @@ $OSTREE refs > reflist
 assert_file_has_content reflist '^test2$'
 rm reflist
 
+$OSTREE refs --delete 2>/dev/null && (echo 1>&2 "refs --delete (without prefix) unexpectedly succeeded!"; 
exit 1)
+
 echo "ok refs"
 
 cd checkout-test2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]