Skip to content

Commit

Permalink
lib/core: Support <remote>: syntax when listing refs
Browse files Browse the repository at this point in the history
Allow users to pass `<remote>:` to list all refs we have locally
belonging to `<remote>`. Also (re-)allow the similar `<remote>:.` syntax
for backwards compatibility with flatpak.

Closes: #1500
Approved by: cgwalters
  • Loading branch information
jlebon authored and rh-atomic-bot committed Mar 16, 2018
1 parent 10fb740 commit 296ef25
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/libostree/ostree-repo-refs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<remote>:" and "<remote>:.", 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)
{
Expand Down
7 changes: 7 additions & 0 deletions tests/test-refs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 296ef25

Please sign in to comment.