From 752368eb5b418cb8d54621d7121ee04e42330cb3 Mon Sep 17 00:00:00 2001 From: Jonathan Lebon Date: Fri, 5 May 2017 15:40:55 -0400 Subject: [PATCH] rebase: allow rebasing to a local branch This is a follow-up to commit 77acf62. There, we added support for rebasing from a local branch to another local branch. But in testing, it's also really useful to be able to rebase from a remote-based refspec to a local branch. We allow this here by slightly expanding the syntax of allowed refspecs. Now, we can use rpm-ostree all the time rather than fallback to `ostree admin deploy`, which isn't pkg-aware. Closes: #764 Approved by: cgwalters --- man/rpm-ostree.xml | 8 +++++--- src/daemon/rpmostreed-utils.c | 9 ++++++++- tests/check/test-basic.sh | 11 ++++++++++- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/man/rpm-ostree.xml b/man/rpm-ostree.xml index 68094e9e..4014cc6e 100644 --- a/man/rpm-ostree.xml +++ b/man/rpm-ostree.xml @@ -247,9 +247,11 @@ Boston, MA 02111-1307, USA. The full syntax is rebase REMOTENAME:BRANCHNAME. - It is also possible to specify just BRANCHNAME, - reusing the same remote, as well as using REMOTENAME:, - which will use the same branch on a different remote. + Specifying just BRANCHNAME will reuse the same + remote. You may also omit one of REMOTENAME or + BRANCHNAME (keeping the colon). In the former + case, the branch refers to a local branch; in the latter case, the + same branch will be used on a different remote. diff --git a/src/daemon/rpmostreed-utils.c b/src/daemon/rpmostreed-utils.c index 974c1bba..dd283055 100644 --- a/src/daemon/rpmostreed-utils.c +++ b/src/daemon/rpmostreed-utils.c @@ -137,12 +137,19 @@ rpmostreed_refspec_parse_partial (const gchar *new_provided_refspec, g_autofree gchar *ref = NULL; g_autofree gchar *remote = NULL; + gboolean infer_remote = TRUE;; /* Allow just switching remotes */ if (g_str_has_suffix (new_provided_refspec, ":")) { remote = g_strndup (new_provided_refspec, strlen(new_provided_refspec)-1); } + /* Allow switching to a local branch */ + else if (g_str_has_prefix (new_provided_refspec, ":")) + { + infer_remote = FALSE; + ref = g_strdup (new_provided_refspec + 1); + } else { g_autoptr(GError) parse_error = NULL; @@ -186,7 +193,7 @@ rpmostreed_refspec_parse_partial (const gchar *new_provided_refspec, } } - else if (remote == NULL) + else if (infer_remote && remote == NULL) { if (origin_remote) { diff --git a/tests/check/test-basic.sh b/tests/check/test-basic.sh index cdd5d590..597ec2fc 100755 --- a/tests/check/test-basic.sh +++ b/tests/check/test-basic.sh @@ -24,7 +24,7 @@ export RPMOSTREE_SUPPRESS_REQUIRES_ROOT_CHECK=yes ensure_dbus -echo "1..19" +echo "1..21" setup_os_repository "archive-z2" "syslinux" @@ -148,6 +148,15 @@ $OSTREE remote add secureos file://$(pwd)/testos-repo rpm-ostree rebase --os=testos secureos:$branch gpg-signed echo "ok deploy from remote with unsigned and signed commits" +rpm-ostree rebase --os=testos :$branch +assert_status_jq '.deployments[0].origin|startswith("testos/")' +echo "ok rebase from refspec with remote to local branch" + +$OSTREE commit -b another-branch --tree=ref=$branch +rpm-ostree rebase --os=testos another-branch +assert_status_jq '.deployments[0].origin == "another-branch"' +echo "ok rebase from local branch to local branch" + originpath=$(ostree admin --sysroot=sysroot --print-current-dir).origin echo "unconfigured-state=Access to TestOS requires ONE BILLION DOLLARS" >> ${originpath} rpm-ostree reload