From c5fc9ed2b546a88cbdafc37529def5385d6c54d5 Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Thu, 25 Feb 2016 17:33:46 +0900 Subject: [PATCH] Rebase: Improve error message when rebasing a change onto itself Change it from: "cannot depend on self" to "cannot rebase change onto itself" and add a test case for it. Also fix a couple of minor nits in rebaseOntoAbandonedChange. - use variable rather than calling getChangeId() again - fix indentation Change-Id: I70257c06af8872010958114537c092d4e9dcfc65 --- .../acceptance/api/change/ChangeIT.java | 23 +++++++++++++++---- .../google/gerrit/server/change/Rebase.java | 2 +- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java index 49f70dbbe6..ba317675e0 100644 --- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java +++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/api/change/ChangeIT.java @@ -477,11 +477,26 @@ public class ChangeIT extends AbstractDaemonTest { ri.base = r.getCommit().name(); exception.expect(ResourceConflictException.class); - exception.expectMessage("base change is abandoned: " + r.getChangeId()); + exception.expectMessage("base change is abandoned: " + changeId); gApi.changes() - .id(r2.getChangeId()) - .revision(r2.getCommit().name()) - .rebase(ri); + .id(r2.getChangeId()) + .revision(r2.getCommit().name()) + .rebase(ri); + } + + @Test + public void rebaseOntoSelf() throws Exception { + PushOneCommit.Result r = createChange(); + String changeId = r.getChangeId(); + String commit = r.getCommit().name(); + RebaseInput ri = new RebaseInput(); + ri.base = commit; + exception.expect(ResourceConflictException.class); + exception.expectMessage("cannot rebase change onto itself"); + gApi.changes() + .id(changeId) + .revision(commit) + .rebase(ri); } @Test diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java b/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java index 2e4d88a1b6..f07a7ed846 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/change/Rebase.java @@ -152,7 +152,7 @@ public class Rebase implements RestModifyView, if (!base.control().isPatchVisible(base.patchSet(), db)) { throw new AuthException("base revision not accessible: " + str); } else if (change.getId().equals(baseId.getParentKey())) { - throw new ResourceConflictException("cannot depend on self"); + throw new ResourceConflictException("cannot rebase change onto itself"); } Change baseChange = base.control().getChange();