From: Anton Gerasimov Date: Mon, 13 Feb 2017 16:34:18 +0000 (+0100) Subject: admin-switch: Don't segfault if there's no remote X-Git-Tag: archive/raspbian/2022.1-3+rpi1~1^2~4^2~40^2~42 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=b8f4465b50ba9ff87fb6f44c2f93d7b574754c0a;p=ostree.git admin-switch: Don't segfault if there's no remote Switching between local branches should be supported too. Signed-off-by: Anton Gerasimov Closes: #683 Approved by: cgwalters --- diff --git a/src/ostree/ot-admin-builtin-switch.c b/src/ostree/ot-admin-builtin-switch.c index 877cbe96..d72aeebd 100644 --- a/src/ostree/ot-admin-builtin-switch.c +++ b/src/ostree/ot-admin-builtin-switch.c @@ -53,6 +53,7 @@ ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GErro g_autofree char *new_remote = NULL; g_autofree char *new_ref = NULL; g_autofree char *new_refspec = NULL; + const char* remote; glnx_unref_object OstreeSysrootUpgrader *upgrader = NULL; glnx_unref_object OstreeAsyncProgress *progress = NULL; gboolean changed; @@ -101,12 +102,17 @@ ot_admin_builtin_switch (int argc, char **argv, GCancellable *cancellable, GErro 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); + remote = origin_remote; else - new_refspec = g_strconcat (new_remote, ":", new_ref, NULL); - + remote = new_remote; + + if (remote) + new_refspec = g_strconcat (remote, ":", new_ref, NULL); + else + new_refspec = g_strdup (new_ref); + if (strcmp (origin_refspec, new_refspec) == 0) { g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,