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
This commit is contained in:
Matthew Barnes 2015-01-06 09:36:45 -05:00
parent 1e8e070102
commit 7727fe84d9
2 changed files with 11 additions and 1 deletions

View File

@ -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;

View File

@ -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