use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.
the class StickyApprovalsIT method noCodeChange.
private void noCodeChange(String changeId) throws Exception {
TestRepository<?>.CommitBuilder<?> commitBuilder = testRepo.amendRef("HEAD").insertChangeId(changeId.substring(1));
commitBuilder.message("New subject " + System.nanoTime()).author(admin.getIdent()).committer(new PersonIdent(admin.getIdent(), testRepo.getDate()));
commitBuilder.create();
GitUtil.pushHead(testRepo, "refs/for/master", false);
assertThat(getChangeKind(changeId)).isEqualTo(NO_CODE_CHANGE);
}
use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.
the class AbstractSubmit method assertRebase.
protected void assertRebase(TestRepository<?> testRepo, boolean contentMerge) throws Exception {
Repository repo = testRepo.getRepository();
RevCommit localHead = getHead(repo);
RevCommit remoteHead = getRemoteHead();
assert_().withFailureMessage(String.format("%s not equal %s", localHead.name(), remoteHead.name())).that(localHead.getId()).isNotEqualTo(remoteHead.getId());
assertThat(remoteHead.getParentCount()).isEqualTo(1);
if (!contentMerge) {
assertThat(getLatestRemoteDiff()).isEqualTo(getLatestDiff(repo));
}
assertThat(remoteHead.getShortMessage()).isEqualTo(localHead.getShortMessage());
}
use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.
the class AbstractPushForReview method accidentallyPushNewPatchSetDirectlyToBranch.
private Change.Id accidentallyPushNewPatchSetDirectlyToBranch() throws Exception {
PushOneCommit.Result r = createChange();
RevCommit ps1Commit = r.getCommit();
Change c = r.getChange().change();
RevCommit ps2Commit;
try (Repository repo = repoManager.openRepository(project)) {
// Create a new patch set of the change directly in Gerrit's repository,
// without pushing it. In reality it's more likely that the client would
// create and push this behind Gerrit's back (e.g. an admin accidentally
// using direct ssh access to the repo), but that's harder to do in tests.
TestRepository<?> tr = new TestRepository<>(repo);
ps2Commit = tr.branch("refs/heads/master").commit().message(ps1Commit.getShortMessage() + " v2").insertChangeId(r.getChangeId().substring(1)).create();
}
testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master")).call();
testRepo.reset(ps2Commit);
ChangeData cd = byCommit(ps1Commit);
assertThat(cd.change().getStatus()).isEqualTo(Change.Status.NEW);
assertThat(getPatchSetRevisions(cd)).containsExactlyEntriesIn(ImmutableMap.of(1, ps1Commit.name()));
return c.getId();
}
use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.
the class AbstractPushForReview method mergedOptionWithExistingChangeInsertsPatchSet.
@Test
public void mergedOptionWithExistingChangeInsertsPatchSet() throws Exception {
String master = "refs/heads/master";
grant(project, master, Permission.PUSH, true);
PushOneCommit.Result r = pushTo("refs/for/master");
r.assertOkStatus();
ObjectId c1 = r.getCommit().copy();
// Create a PS2 commit directly on master in the server's repo. This
// simulates the client amending locally and pushing directly to the branch,
// expecting the change to be auto-closed, but the change metadata update
// fails.
ObjectId c2;
try (Repository repo = repoManager.openRepository(project)) {
TestRepository<?> tr = new TestRepository<>(repo);
RevCommit commit2 = tr.amend(c1).message("New subject").insertChangeId(r.getChangeId().substring(1)).create();
c2 = commit2.copy();
tr.update(master, c2);
}
testRepo.git().fetch().setRefSpecs(new RefSpec("refs/heads/master")).call();
testRepo.reset(c2);
String ref = "refs/for/master%merged";
assertPushOk(pushHead(testRepo, ref, false), ref);
EnumSet<ListChangesOption> opts = EnumSet.of(ListChangesOption.ALL_REVISIONS);
ChangeInfo info = gApi.changes().id(r.getChangeId()).get(opts);
assertThat(info.currentRevision).isEqualTo(c2.name());
assertThat(info.revisions.keySet()).containsExactly(c1.name(), c2.name());
// TODO(dborowitz): Fix ReceiveCommits to also auto-close the change.
assertThat(info.status).isEqualTo(ChangeStatus.NEW);
}
use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.
the class CreateChangeIT method createNewCommitWithoutChangeId.
private RevCommit createNewCommitWithoutChangeId() throws Exception {
try (Repository repo = repoManager.openRepository(project);
RevWalk walk = new RevWalk(repo)) {
Ref ref = repo.exactRef("refs/heads/master");
RevCommit tip = null;
if (ref != null) {
tip = walk.parseCommit(ref.getObjectId());
}
TestRepository<?> testSrcRepo = new TestRepository<>(repo);
TestRepository<?>.BranchBuilder<?> builder = testSrcRepo.branch("refs/heads/master");
RevCommit revCommit = tip == null ? builder.commit().message("commit 1").add("a.txt", "content").create() : builder.commit().parent(tip).message("commit 1").add("a.txt", "content").create();
assertThat(GitUtil.getChangeId(testSrcRepo, revCommit)).isEmpty();
return revCommit;
}
}
Aggregations