mirror of
https://github.com/flatpak/flatpak.git
synced 2026-10-21 23:25:33 -04:00
Fetch the default branch when adding a remote from its repo's summary file
Just like we do with the title, fetch the default-branch from the repository's summary file and use that information when adding a remote reference from the command line. https://github.com/flatpak/flatpak/issues/221
This commit is contained in:
1 parent
54598331cc
commit
c492def9a7
3 files changed
+65
-1
No files matched your search
@@ -267,6 +267,7 @@ update_remote_with_extra_metadata (FlatpakDir* dir,
|
||||
GError **error)
|
||||
{
|
||||
g_autofree char *title = NULL;
|
||||
g_autofree char *default_branch = NULL;
|
||||
g_autoptr(GKeyFile) config = NULL;
|
||||
|
||||
if (opt_title == NULL)
|
||||
@@ -279,7 +280,17 @@ update_remote_with_extra_metadata (FlatpakDir* dir,
|
||||
opt_title = title;
|
||||
}
|
||||
|
||||
if (title != NULL)
|
||||
if (opt_default_branch == NULL)
|
||||
{
|
||||
default_branch = flatpak_dir_fetch_remote_default_branch (dir,
|
||||
remote,
|
||||
NULL,
|
||||
NULL);
|
||||
if (default_branch)
|
||||
opt_default_branch = default_branch;
|
||||
}
|
||||
|
||||
if (title != NULL || default_branch != NULL)
|
||||
{
|
||||
config = get_config_from_opts (dir, remote);
|
||||
return flatpak_dir_modify_remote (dir, remote, config, gpg_data, cancellable, error);
|
||||
|
||||
@@ -5260,6 +5260,55 @@ flatpak_dir_fetch_remote_title (FlatpakDir *self,
|
||||
return g_steal_pointer (&title);
|
||||
}
|
||||
|
||||
char *
|
||||
flatpak_dir_fetch_remote_default_branch (FlatpakDir *self,
|
||||
const char *remote,
|
||||
GCancellable *cancellable,
|
||||
GError **error)
|
||||
{
|
||||
g_autoptr(GError) my_error = NULL;
|
||||
g_autoptr(GBytes) summary_bytes = NULL;
|
||||
g_autoptr(GVariant) summary = NULL;
|
||||
g_autoptr(GVariant) extensions = NULL;
|
||||
GVariantDict dict;
|
||||
g_autofree char *default_branch = NULL;
|
||||
|
||||
if (error == NULL)
|
||||
error = &my_error;
|
||||
|
||||
if (!flatpak_dir_ensure_repo (self, cancellable, error))
|
||||
return NULL;
|
||||
|
||||
if (!flatpak_dir_remote_fetch_summary (self, remote,
|
||||
&summary_bytes,
|
||||
cancellable, error))
|
||||
return FALSE;
|
||||
|
||||
if (summary_bytes == NULL)
|
||||
{
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_FAILED,
|
||||
_("Remote default-branch not available; server has no summary file"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
summary = g_variant_ref_sink (g_variant_new_from_bytes (OSTREE_SUMMARY_GVARIANT_FORMAT,
|
||||
summary_bytes, FALSE));
|
||||
extensions = g_variant_get_child_value (summary, 1);
|
||||
|
||||
g_variant_dict_init (&dict, extensions);
|
||||
g_variant_dict_lookup (&dict, "xa.default-branch", "s", &default_branch);
|
||||
g_variant_dict_end (&dict);
|
||||
|
||||
if (default_branch == NULL)
|
||||
{
|
||||
g_set_error_literal (error, G_IO_ERROR, G_IO_ERROR_NOT_FOUND,
|
||||
_("Remote default-branch not set"));
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return g_steal_pointer (&default_branch);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
flatpak_dir_parse_summary_for_ref (FlatpakDir *self,
|
||||
GVariant *summary,
|
||||
|
||||
@@ -424,6 +424,10 @@ char * flatpak_dir_fetch_remote_title (FlatpakDir *self,
|
||||
const char *remote,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
char * flatpak_dir_fetch_remote_default_branch (FlatpakDir *self,
|
||||
const char *remote,
|
||||
GCancellable *cancellable,
|
||||
GError **error);
|
||||
gboolean flatpak_dir_fetch_ref_cache (FlatpakDir *self,
|
||||
const char *remote_name,
|
||||
const char *ref,
|
||||
|
||||
Reference in new issue
Block a user