use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class AbstractSubmit method onlySelfSubmit.
@Test
public void onlySelfSubmit() throws Exception {
// create project where only the change owner can submit
Project.NameKey p = createProject("p");
ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
Util.block(cfg, Permission.SUBMIT, REGISTERED_USERS, "refs/*");
Util.allow(cfg, Permission.SUBMIT, CHANGE_OWNER, "refs/*");
Util.allow(cfg, Permission.forLabel("Code-Review"), -2, +2, REGISTERED_USERS, "refs/*");
saveProjectConfig(p, cfg);
TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
PushOneCommit.Result result = push.to("refs/for/master");
result.assertOkStatus();
ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
assertThat(change.owner._accountId).isEqualTo(admin.id.get());
setApiUser(user);
submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
setApiUser(admin);
submit(result.getChangeId());
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class AbstractSubmit method noSelfSubmit.
@Test
public void noSelfSubmit() throws Exception {
// create project where submit is blocked for the change owner
Project.NameKey p = createProject("p");
ProjectConfig cfg = projectCache.checkedGet(p).getConfig();
Util.block(cfg, Permission.SUBMIT, CHANGE_OWNER, "refs/*");
Util.allow(cfg, Permission.SUBMIT, REGISTERED_USERS, "refs/heads/*");
Util.allow(cfg, Permission.forLabel("Code-Review"), -2, +2, REGISTERED_USERS, "refs/*");
saveProjectConfig(p, cfg);
TestRepository<InMemoryRepository> repo = cloneProject(p, admin);
PushOneCommit push = pushFactory.create(db, admin.getIdent(), repo);
PushOneCommit.Result result = push.to("refs/for/master");
result.assertOkStatus();
ChangeInfo change = gApi.changes().id(result.getChangeId()).get();
assertThat(change.owner._accountId).isEqualTo(admin.id.get());
submit(result.getChangeId(), new SubmitInput(), AuthException.class, "submit not permitted");
setApiUser(user);
submit(result.getChangeId());
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class AbstractSubmit method submitMergeOfNonChangeBranchNonTip.
@Test
public void submitMergeOfNonChangeBranchNonTip() throws Exception {
// Merge a branch with commits that have not been submitted as
// changes.
//
// MC -- merge commit (pushed for review and submitted)
// |\ S2 -- new stable tip (pushed directly to refs/heads/stable)
// M \ /
// | S1 -- stable (pushed directly to refs/heads/stable)
// | /
// I -- master
//
RevCommit initial = getRemoteHead(project, "master");
// push directly to stable to S1
PushOneCommit.Result s1 = pushFactory.create(db, admin.getIdent(), testRepo, "new commit into stable", "stable1.txt", "").to("refs/heads/stable");
// move the stable tip ahead to S2
pushFactory.create(db, admin.getIdent(), testRepo, "Tip of branch stable", "stable2.txt", "").to("refs/heads/stable");
testRepo.reset(initial);
// move the master ahead
PushOneCommit.Result m = pushFactory.create(db, admin.getIdent(), testRepo, "Move master ahead", "master.txt", "").to("refs/heads/master");
// create merge change
PushOneCommit mc = pushFactory.create(db, admin.getIdent(), testRepo, "The merge commit", "merge.txt", "");
mc.setParents(ImmutableList.of(m.getCommit(), s1.getCommit()));
PushOneCommit.Result mergeReview = mc.to("refs/for/master");
approve(mergeReview.getChangeId());
submit(mergeReview.getChangeId());
List<RevCommit> log = getRemoteLog();
assertThat(log).contains(s1.getCommit());
assertThat(log).contains(mergeReview.getCommit());
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class AbstractSubmit method submitWithCommitAndItsMergeCommitTogether.
@Test
public void submitWithCommitAndItsMergeCommitTogether() throws Exception {
assume().that(isSubmitWholeTopicEnabled()).isTrue();
RevCommit initialHead = getRemoteHead();
// Create a stable branch and bootstrap it.
gApi.projects().name(project.get()).branch("stable").create(new BranchInput());
PushOneCommit push = pushFactory.create(db, user.getIdent(), testRepo, "initial commit", "a.txt", "a");
PushOneCommit.Result change = push.to("refs/heads/stable");
RevCommit stable = getRemoteHead(project, "stable");
RevCommit master = getRemoteHead(project, "master");
assertThat(master).isEqualTo(initialHead);
assertThat(stable).isEqualTo(change.getCommit());
testRepo.git().fetch().call();
testRepo.git().branchCreate().setName("stable").setStartPoint(stable).call();
testRepo.git().branchCreate().setName("master").setStartPoint(master).call();
// Create a fix in stable branch.
testRepo.reset(stable);
RevCommit fix = testRepo.commit().parent(stable).message("small fix").add("b.txt", "b").insertChangeId().create();
testRepo.branch("refs/heads/stable").update(fix);
testRepo.git().push().setRefSpecs(new RefSpec("refs/heads/stable:refs/for/stable/" + name("topic"))).call();
// Merge the fix into master.
testRepo.reset(master);
RevCommit merge = testRepo.commit().parent(master).parent(fix).message("Merge stable into master").insertChangeId().create();
testRepo.branch("refs/heads/master").update(merge);
testRepo.git().push().setRefSpecs(new RefSpec("refs/heads/master:refs/for/master/" + name("topic"))).call();
// Submit together.
String fixId = GitUtil.getChangeId(testRepo, fix).get();
String mergeId = GitUtil.getChangeId(testRepo, merge).get();
approve(fixId);
approve(mergeId);
submit(mergeId);
assertMerged(fixId);
assertMerged(mergeId);
testRepo.git().fetch().call();
RevWalk rw = testRepo.getRevWalk();
master = rw.parseCommit(getRemoteHead(project, "master"));
assertThat(rw.isMergedInto(merge, master)).isTrue();
assertThat(rw.isMergedInto(fix, master)).isTrue();
}
use of com.google.gerrit.acceptance.PushOneCommit in project gerrit by GerritCodeReview.
the class AbstractSubmitByRebase method submitWithRebaseMergeCommit.
@Test
public void submitWithRebaseMergeCommit() throws Exception {
/*
* (HEAD, origin/master, origin/HEAD) Merge changes X,Y
|\
| * Merge branch 'master' into origin/master
| |\
| | * SHA Added a
| |/
* | Before
|/
* Initial empty repository
*/
RevCommit initialHead = getRemoteHead();
PushOneCommit.Result change1 = createChange("Added a", "a.txt", "");
PushOneCommit change2Push = pushFactory.create(db, admin.getIdent(), testRepo, "Merge to master", "m.txt", "");
change2Push.setParents(ImmutableList.of(initialHead, change1.getCommit()));
PushOneCommit.Result change2 = change2Push.to("refs/for/master");
testRepo.reset(initialHead);
PushOneCommit.Result change3 = createChange("Before", "b.txt", "");
approve(change3.getChangeId());
submit(change3.getChangeId());
approve(change1.getChangeId());
approve(change2.getChangeId());
submit(change2.getChangeId());
RevCommit newHead = getRemoteHead();
assertThat(newHead.getParentCount()).isEqualTo(2);
RevCommit headParent1 = parse(newHead.getParent(0).getId());
RevCommit headParent2 = parse(newHead.getParent(1).getId());
if (getSubmitType() == SubmitType.REBASE_ALWAYS) {
assertCurrentRevision(change3.getChangeId(), 2, headParent1.getId());
} else {
assertThat(change3.getCommit().getId()).isEqualTo(headParent1.getId());
}
assertThat(headParent1.getParentCount()).isEqualTo(1);
assertThat(headParent1.getParent(0)).isEqualTo(initialHead);
assertThat(headParent2.getId()).isEqualTo(change2.getCommit().getId());
assertThat(headParent2.getParentCount()).isEqualTo(2);
RevCommit headGrandparent1 = parse(headParent2.getParent(0).getId());
RevCommit headGrandparent2 = parse(headParent2.getParent(1).getId());
assertThat(headGrandparent1.getId()).isEqualTo(initialHead.getId());
assertThat(headGrandparent2.getId()).isEqualTo(change1.getCommit().getId());
}
Aggregations