Merge pull request #23 from matthiasclasen/update-to-commit

Some work towards rollback and checkout
tingping/wmclass
Alexander Larsson 2015-01-19 11:43:14 +01:00
commit c239e3b077
4 changed files with 69 additions and 3 deletions

View File

@ -46,6 +46,11 @@
<arg choice="opt">BRANCH</arg> can be specified to update a
specific branch.
</para>
<para>
Normally, this command updates the application to the tip
of its branch. But it is possible to check out another commit,
with the --commit option.
</para>
</refsect1>
@ -81,6 +86,14 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--commit=COMMIT</option></term>
<listitem><para>
Update to this commit, instead of the tip of the branch.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option></term>
<term><option>--verbose</option></term>

View File

@ -53,6 +53,11 @@
to keep running against an updated version of the runtime
they were built against.
</para>
<para>
Normally, this command updates the runtime to the tip
of its branch. But it is possible to check out another commit,
with the --commit option.
</para>
</refsect1>
@ -88,6 +93,14 @@
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>--commit=COMMIT</option></term>
<listitem><para>
Update to this commit, instead of the tip of the branch.
</para></listitem>
</varlistentry>
<varlistentry>
<term><option>-v</option></term>
<term><option>--verbose</option></term>

View File

@ -11,9 +11,11 @@
#include "xdg-app-utils.h"
static char *opt_arch;
static char *opt_commit;
static GOptionEntry options[] = {
{ "arch", 0, 0, G_OPTION_ARG_STRING, &opt_arch, "Arch to update for", "ARCH" },
{ "commit", 0, 0, G_OPTION_ARG_STRING, &opt_commit, "Commit to deploy", "COMMIT" },
{ NULL }
};
@ -67,7 +69,7 @@ xdg_app_builtin_update_runtime (int argc, char **argv, GCancellable *cancellable
previous_deployment = xdg_app_dir_read_active (dir, ref, cancellable);
my_error = NULL;
if (!xdg_app_dir_deploy (dir, ref, NULL, cancellable, &my_error))
if (!xdg_app_dir_deploy (dir, ref, opt_commit, cancellable, &my_error))
{
if (g_error_matches (my_error, XDG_APP_DIR_ERROR, XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
g_error_free (my_error);
@ -145,7 +147,7 @@ xdg_app_builtin_update_app (int argc, char **argv, GCancellable *cancellable, GE
previous_deployment = xdg_app_dir_read_active (dir, ref, cancellable);
my_error = NULL;
if (!xdg_app_dir_deploy (dir, ref, NULL, cancellable, &my_error))
if (!xdg_app_dir_deploy (dir, ref, opt_commit, cancellable, &my_error))
{
if (g_error_matches (my_error, XDG_APP_DIR_ERROR, XDG_APP_DIR_ERROR_ALREADY_DEPLOYED))
g_error_free (my_error);

View File

@ -732,15 +732,53 @@ xdg_app_dir_deploy (XdgAppDir *self,
if (!xdg_app_dir_ensure_repo (self, cancellable, error))
goto out;
deploy_base = xdg_app_dir_get_deploy_dir (self, ref);
if (checksum == NULL)
{
g_debug ("No checksum specified, getting tip of %s", ref);
if (!ostree_repo_resolve_rev (self->repo, ref, FALSE, &resolved_ref, error))
goto out;
checksum = resolved_ref;
}
else
{
gs_unref_object GFile *root = NULL;
gs_free char *commit = NULL;
deploy_base = xdg_app_dir_get_deploy_dir (self, ref);
g_debug ("Looking for checksum %s in local repo", checksum);
if (!ostree_repo_read_commit (self->repo, checksum, &root, &commit, cancellable, NULL))
{
GSConsole *console = NULL;
gs_unref_object OstreeAsyncProgress *progress = NULL;
const char *refs[2];
gs_unref_object GFile *origin = NULL;
gs_free char *repository = NULL;
refs[0] = checksum;
refs[1] = NULL;
origin = g_file_get_child (deploy_base, "origin");
if (!g_file_load_contents (origin, cancellable, &repository, NULL, NULL, error))
goto out;
g_debug ("Pulling checksum %s from remote %s", checksum, repository);
console = gs_console_get ();
if (console)
{
gs_console_begin_status_line (console, "", NULL, NULL);
progress = ostree_async_progress_new_and_connect (ostree_repo_pull_default_console_progress_changed, console);
}
if (!ostree_repo_pull (self->repo, repository,
(char **)refs, OSTREE_REPO_PULL_FLAGS_NONE,
progress,
cancellable, error))
goto out;
}
}
checkoutdir = g_file_get_child (deploy_base, checksum);
if (g_file_query_exists (checkoutdir, cancellable))