From 296ef25e12d1c4a49e98b3f9e0a86a31b3762a98 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 16 Mar 2018 14:19:28 -0400 Subject: [PATCH] lib/core: Support : syntax when listing refs Allow users to pass `:` to list all refs we have locally belonging to ``. Also (re-)allow the similar `:.` syntax for backwards compatibility with flatpak. Closes: #1500 Approved by: cgwalters --- src/libostree/ostree-repo-refs.c | 20 ++++++++++++++++++-- tests/test-refs.sh | 7 +++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/libostree/ostree-repo-refs.c b/src/libostree/ostree-repo-refs.c index b96cfad0..ad0fd57c 100644 --- a/src/libostree/ostree-repo-refs.c +++ b/src/libostree/ostree-repo-refs.c @@ -629,8 +629,24 @@ _ostree_repo_list_refs_internal (OstreeRepo *self, const char *prefix_path; const char *path; - if (!ostree_parse_refspec (refspec_prefix, &remote, &ref_prefix, error)) - return FALSE; + /* special-case ":" and ":.", which ostree_parse_refspec won't like */ + if (g_str_has_suffix (refspec_prefix, ":") || + g_str_has_suffix (refspec_prefix, ":.")) + { + const char *colon = strrchr (refspec_prefix, ':'); + g_autofree char *r = g_strndup (refspec_prefix, colon - refspec_prefix); + if (ostree_validate_remote_name (r, NULL)) + { + remote = g_steal_pointer (&r); + ref_prefix = g_strdup ("."); + } + } + + if (!ref_prefix) + { + if (!ostree_parse_refspec (refspec_prefix, &remote, &ref_prefix, error)) + return FALSE; + } if (!(flags & OSTREE_REPO_LIST_REFS_EXT_EXCLUDE_REMOTES) && remote) { diff --git a/tests/test-refs.sh b/tests/test-refs.sh index 50862d76..f4fe1833 100755 --- a/tests/test-refs.sh +++ b/tests/test-refs.sh @@ -147,6 +147,13 @@ ${CMD_PREFIX} ostree --repo=repo refs local1 --create=origin:local1 ${CMD_PREFIX} ostree --repo=repo refs | wc -l > refscount.create6 assert_file_has_content refscount.create6 "^11$" +#Check that we can list just remote refs +${CMD_PREFIX} ostree --repo=repo refs origin: | wc -l > refscount.create7 +assert_file_has_content refscount.create7 "^2$" # origin:remote1 origin:local1 +#Also support :. for backcompat with flatpak +${CMD_PREFIX} ostree --repo=repo refs origin:. | wc -l > refscount.create8 +assert_file_has_content refscount.create8 "^2$" # origin:remote1 origin:local1 + echo "ok refs" # Test symlinking a ref