diff options
author | Dan Nicholson <nicholson@endlessm.com> | 2019-06-10 09:47:44 -0500 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2019-06-12 15:00:19 +0000 |
commit | d916383953121f7bbd016a977caf85bc6f917422 (patch) | |
tree | 92ea9eefbeb4d0d78696eb602ff273df5e449bc5 | |
parent | 6733843f87aa3b1ad3dfe1ae76f0c76329617909 (diff) | |
download | ostree-d916383953121f7bbd016a977caf85bc6f917422.tar.gz |
bin/refs: Allow overwriting existing ref
Currently if you want to update a non-alias ref, you need to first check
if it exists and use either `ostree refs --create` or `ostree reset` as
appropriate. That's unnecessarily complicated and is much less
convenient than the old `write-refs` builtin that simply called
`ostree_repo_set_ref_immediate()` without any checks.
Add a `--force` option to be used with `--create` that does not raise an
error when the destination ref already exists.
Closes: #1870
Approved by: jlebon
-rw-r--r-- | bash/ostree | 1 | ||||
-rw-r--r-- | man/ostree-refs.xml | 10 | ||||
-rw-r--r-- | src/ostree/ot-builtin-refs.c | 10 | ||||
-rwxr-xr-x | tests/test-refs.sh | 5 |
4 files changed, 23 insertions, 3 deletions
diff --git a/bash/ostree b/bash/ostree index 5ba3d475..fc429983 100644 --- a/bash/ostree +++ b/bash/ostree @@ -952,6 +952,7 @@ _ostree_refs() { --collections -c --delete --list + --force " local options_with_args=" diff --git a/man/ostree-refs.xml b/man/ostree-refs.xml index 8d5a1d23..0ba6b1d7 100644 --- a/man/ostree-refs.xml +++ b/man/ostree-refs.xml @@ -126,6 +126,16 @@ Boston, MA 02111-1307, USA. PREFIX are deleted. </para></listitem> </varlistentry> + + <varlistentry> + <term><option>--force</option></term> + + <listitem><para> + When creating <literal>NEWREF</literal> with + <option>--create</option>, allow an existing ref to be + updated instead of erroring. + </para></listitem> + </varlistentry> </variablelist> </refsect1> diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c index 630605a0..1e0b1011 100644 --- a/src/ostree/ot-builtin-refs.c +++ b/src/ostree/ot-builtin-refs.c @@ -32,6 +32,7 @@ static gboolean opt_list; static gboolean opt_alias; static char *opt_create; static gboolean opt_collections; +static gboolean opt_force; /* ATTENTION: * Please remember to update the bash-completion script (bash/ostree) and @@ -44,6 +45,7 @@ static GOptionEntry options[] = { { "alias", 'A', 0, G_OPTION_ARG_NONE, &opt_alias, "If used with --create, create an alias, otherwise just list aliases", NULL }, { "create", 0, 0, G_OPTION_ARG_STRING, &opt_create, "Create a new ref for an existing commit", "NEWREF" }, { "collections", 'c', 0, G_OPTION_ARG_NONE, &opt_collections, "Enable listing collection IDs for refs", NULL }, + { "force", 0, 0, G_OPTION_ARG_NONE, &opt_force, "Overwrite existing refs when creating", NULL }, { NULL } }; @@ -89,7 +91,7 @@ do_ref_with_collections (OstreeRepo *repo, else goto out; } - if (checksum_existing != NULL) + if (!opt_force && checksum_existing != NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "--create specified but ref %s already exists", opt_create); @@ -205,9 +207,11 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab else goto out; } - /* We want to allow replacing an existing alias */ + /* We want to allow replacing an existing alias or a normal ref when + * forced + */ gboolean replacing_alias = opt_alias && g_hash_table_contains (ref_aliases, opt_create); - if (!replacing_alias && checksum_existing != NULL) + if (!replacing_alias && !opt_force && checksum_existing != NULL) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "--create specified but ref %s already exists", opt_create); diff --git a/tests/test-refs.sh b/tests/test-refs.sh index 83da04ff..d0f8e7da 100755 --- a/tests/test-refs.sh +++ b/tests/test-refs.sh @@ -90,6 +90,11 @@ if ${CMD_PREFIX} ostree --repo=repo refs foo/ctest --create=ctest; then assert_not_reached "refs --create unexpectedly succeeded in overwriting an existing prefix!" fi +# Force overwriting ctest and check the revision got updated +foo_ctest_rev=$(${CMD_PREFIX} ostree --repo=repo rev-parse foo/ctest) +${CMD_PREFIX} ostree --repo=repo refs foo/ctest --create=ctest --force +assert_ref repo ctest ${foo_ctest_rev} + # https://github.com/ostreedev/ostree/issues/1285 # One tool was creating .latest_rsync files in each dir, let's ignore stuff like # that. |