summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Lebon <jonathan@jlebon.com>2018-10-30 13:21:46 -0400
committerAtomic Bot <atomic-devel@projectatomic.io>2018-10-31 12:32:30 +0000
commit34a8867749122550cd5d1b80ce22ba4340e00691 (patch)
treec8b13cead1c4b0044fe69ddd2b2d41a600d7e50f
parent51752baf0e841d7a1843b4e77852878077dfe660 (diff)
downloadostree-34a8867749122550cd5d1b80ce22ba4340e00691.tar.gz
bin/refs: Disallow creating broken aliases
This is the alias version of #1749. I.e. we want to make sure that one can't even create an alias which would end up dangling. See also: https://pagure.io/releng/issue/7891 Closes: #1768 Approved by: sinnykumari
-rw-r--r--src/ostree/ot-builtin-refs.c3
-rwxr-xr-xtests/test-refs.sh8
2 files changed, 10 insertions, 1 deletions
diff --git a/src/ostree/ot-builtin-refs.c b/src/ostree/ot-builtin-refs.c
index f88d08a6..630605a0 100644
--- a/src/ostree/ot-builtin-refs.c
+++ b/src/ostree/ot-builtin-refs.c
@@ -221,6 +221,9 @@ static gboolean do_ref (OstreeRepo *repo, const char *refspec_prefix, GCancellab
{
if (remote)
return glnx_throw (error, "Cannot create alias to remote ref: %s", remote);
+ if (!g_hash_table_contains (refs, refspec_prefix))
+ return glnx_throw (error, "Cannot create alias to non-existent ref: %s",
+ refspec_prefix);
if (!ostree_repo_set_alias_ref_immediate (repo, remote, ref, refspec_prefix,
cancellable, error))
goto out;
diff --git a/tests/test-refs.sh b/tests/test-refs.sh
index 1730423d..83da04ff 100755
--- a/tests/test-refs.sh
+++ b/tests/test-refs.sh
@@ -25,7 +25,7 @@ set -euo pipefail
setup_fake_remote_repo1 "archive"
-echo '1..6'
+echo '1..7'
cd ${test_tmpdir}
mkdir repo
@@ -207,3 +207,9 @@ if ${CMD_PREFIX} ostree --repo=repo refs -A exampleos/x86_64/27/server --create=
fi
assert_file_has_content_literal err.txt 'Cannot create alias to remote ref'
echo "ok ref no alias remote"
+
+if ${CMD_PREFIX} ostree --repo=repo refs -A --create foobar nonexistent 2>err.txt; then
+ fatal "Created alias to nonexistent ref?"
+fi
+assert_file_has_content_literal err.txt 'Cannot create alias to non-existent ref'
+echo "ok ref no broken alias"