Support "refs/heads/..." as rebase base
Change-Id: Ie44f82a89227cb9288e4814db2f1ee7dd3375f03
Google-Bug-Id: b/340668088
Release-Notes: support "refs/heads/..." as rebase base
diff --git a/java/com/google/gerrit/server/change/RebaseUtil.java b/java/com/google/gerrit/server/change/RebaseUtil.java
index 93fcbc6..4e487e1 100644
--- a/java/com/google/gerrit/server/change/RebaseUtil.java
+++ b/java/com/google/gerrit/server/change/RebaseUtil.java
@@ -420,6 +420,15 @@
// Gerrit change.
return ObjectId.fromString(inputBase);
}
+
+ // Support "refs/heads/..."
+ Ref ref = git.getRefDatabase().exactRef(inputBase);
+ if (ref != null
+ && isBaseRevisionInDestBranch(
+ rw, ObjectId.toString(ref.getObjectId()), git, change.getDest())) {
+ return ref.getObjectId();
+ }
+
throw new ResourceConflictException(
"base revision is missing from the destination branch: " + inputBase);
}
diff --git a/javatests/com/google/gerrit/acceptance/api/change/RebaseIT.java b/javatests/com/google/gerrit/acceptance/api/change/RebaseIT.java
index 7f21eb6..a5de579 100644
--- a/javatests/com/google/gerrit/acceptance/api/change/RebaseIT.java
+++ b/javatests/com/google/gerrit/acceptance/api/change/RebaseIT.java
@@ -858,6 +858,24 @@
}
@Test
+ public void rebaseChangeWithRefsHeadsMaster() throws Exception {
+ RevCommit desiredBase =
+ createNewCommitWithoutChangeId(/*branch=*/ "refs/heads/master", "file", "content");
+ PushOneCommit.Result child = createChange();
+ RebaseInput ri = new RebaseInput();
+
+ // rebase child onto desiredBase (referenced by ref)
+ ri.base = "refs/heads/master";
+ rebaseCallWithInput.call(child.getChangeId(), ri);
+
+ PatchSet ps2 = child.getPatchSet();
+ assertThat(ps2.id().get()).isEqualTo(2);
+ RevisionInfo childInfo =
+ get(child.getChangeId(), CURRENT_REVISION, CURRENT_COMMIT).getCurrentRevision();
+ assertThat(childInfo.commit.parents.get(0).commit).isEqualTo(desiredBase.name());
+ }
+
+ @Test
public void cannotRebaseChangeWithInvalidBaseCommit() throws Exception {
// Create another branch and push the desired parent commit to it.
String branchName = "foo";