admin switch: Allow switching just remote names

This is a followup to the previous commit; for the installation media
case we want to keep the current origin ref, and only switch remotes.
This commit is contained in:
Colin Walters 2014-05-15 08:58:44 -04:00
parent 24e1bf2552
commit a864190a04
2 changed files with 21 additions and 6 deletions

View File

@ -78,8 +78,6 @@ ot_admin_builtin_switch (int argc, char **argv, OstreeSysroot *sysroot, GCancell
}
new_provided_refspec = argv[1];
if (!ostree_parse_refspec (new_provided_refspec, &new_remote, &new_ref, error))
goto out;
if (!ostree_sysroot_load (sysroot, cancellable, error))
goto out;
@ -95,11 +93,24 @@ ot_admin_builtin_switch (int argc, char **argv, OstreeSysroot *sysroot, GCancell
if (!ostree_parse_refspec (origin_refspec, &origin_remote, &origin_ref, error))
goto out;
if (!new_remote)
new_refspec = g_strconcat (origin_remote, ":", new_provided_refspec, NULL);
/* Allow just switching remotes */
if (g_str_has_suffix (new_provided_refspec, ":"))
{
new_remote = g_strdup (new_provided_refspec);
new_remote[strlen(new_remote)-1] = '\0';
new_ref = g_strdup (origin_ref);
}
else
new_refspec = g_strdup (new_provided_refspec);
{
if (!ostree_parse_refspec (new_provided_refspec, &new_remote, &new_ref, error))
goto out;
}
if (!new_remote)
new_refspec = g_strconcat (origin_remote, ":", new_ref, NULL);
else
new_refspec = g_strconcat (new_remote, ":", new_ref, NULL);
if (strcmp (origin_refspec, new_refspec) == 0)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,

View File

@ -50,3 +50,7 @@ ostree admin --sysroot=sysroot status > status.txt
assert_file_has_content status.txt anothertestos
echo "ok switch remotes"
ostree admin --sysroot=sysroot switch --os=testos testos:
echo "ok switch remote only"