Reapply: Revert "Use changeRefsById to track existing revisions"
This revert was lost when merging stable-2.11 into master.
This change reverts the commit that broke the %base option [1] which
allows to push a commit, which is already merged into a branch, for
review to another branch of the same project (same SHA-1).
Since 2.11 it is also new and shiny option on the project config page
"Create a new change for every commit not in the target branch" which
makes use of the %base parameter internally. This option is broken as
well, obviously.
New unit test is added that verifies this functionality and is failing
without this change, so that such regressions can be avoided in future.
This reverts commit 2ffd2cb83f
.
[1] https://gerrit-review.googlesource.com/Documentation/user-upload.html#base
Bug: Issue 3426
Change-Id: I9f66fc0977679be6153b58188c3c29716e97eb98
This commit is contained in:

committed by
David Ostrovsky

parent
eb1dcc089f
commit
767fdb668e
@@ -26,6 +26,8 @@ import com.google.gerrit.acceptance.AbstractDaemonTest;
|
||||
import com.google.gerrit.acceptance.GitUtil;
|
||||
import com.google.gerrit.acceptance.PushOneCommit;
|
||||
import com.google.gerrit.acceptance.TestAccount;
|
||||
import com.google.gerrit.common.data.Permission;
|
||||
import com.google.gerrit.extensions.api.projects.BranchInput;
|
||||
import com.google.gerrit.extensions.client.InheritableBoolean;
|
||||
import com.google.gerrit.extensions.common.ChangeInfo;
|
||||
import com.google.gerrit.extensions.common.EditInfo;
|
||||
@@ -33,6 +35,7 @@ import com.google.gerrit.extensions.common.LabelInfo;
|
||||
import com.google.gerrit.reviewdb.client.Change;
|
||||
|
||||
import org.eclipse.jgit.revwalk.RevCommit;
|
||||
import org.eclipse.jgit.transport.PushResult;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.DateTimeUtils;
|
||||
import org.joda.time.DateTimeUtils.MillisProvider;
|
||||
@@ -41,6 +44,7 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicLong;
|
||||
|
||||
@@ -385,4 +389,37 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
|
||||
r.assertErrorStatus(
|
||||
"not Signed-off-by author/committer/uploader in commit message footer");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPushSameCommitTwiceUsingMagicBranchBaseOption()
|
||||
throws Exception {
|
||||
grant(Permission.PUSH, project, "refs/heads/master");
|
||||
PushOneCommit.Result rBase = pushTo("refs/heads/master");
|
||||
rBase.assertOkStatus();
|
||||
|
||||
gApi.projects()
|
||||
.name(project.get())
|
||||
.branch("foo")
|
||||
.create(new BranchInput());
|
||||
|
||||
PushOneCommit push =
|
||||
pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT,
|
||||
"b.txt", "anotherContent");
|
||||
|
||||
PushOneCommit.Result r = push.to("refs/for/master");
|
||||
r.assertOkStatus();
|
||||
|
||||
PushResult pr = GitUtil.pushHead(
|
||||
testRepo, "refs/for/foo%base=" + rBase.getCommitId().name(), false, false);
|
||||
assertThat(pr.getMessages()).contains("changes: new: 1, refs: 1, done");
|
||||
|
||||
List<ChangeInfo> changes = query(r.getCommitId().name());
|
||||
assertThat(changes).hasSize(2);
|
||||
ChangeInfo c1 = get(changes.get(0).id);
|
||||
ChangeInfo c2 = get(changes.get(1).id);
|
||||
assertThat(c1.project).isEqualTo(c2.project);
|
||||
assertThat(c1.branch).isNotEqualTo(c2.branch);
|
||||
assertThat(c1.changeId).isEqualTo(c2.changeId);
|
||||
assertThat(c1.currentRevision).isEqualTo(c2.currentRevision);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user