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;
}
}
use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.
the class MoveChangeIT method moveMergeCommitChange.
@Test
public void moveMergeCommitChange() throws Exception {
// Move a change which has a merge commit as the current PS
// Create a merge commit and push for review
PushOneCommit.Result r1 = createChange();
PushOneCommit.Result r2 = createChange();
TestRepository<?>.CommitBuilder<?> commitBuilder = testRepo.branch("HEAD").commit().insertChangeId();
commitBuilder.parent(r1.getCommit()).parent(r2.getCommit()).message("Move change Merge Commit").author(admin.getIdent()).committer(new PersonIdent(admin.getIdent(), testRepo.getDate()));
RevCommit c = commitBuilder.create();
pushHead(testRepo, "refs/for/master", false, false);
// Try to move the merge commit to another branch
Branch.NameKey newBranch = new Branch.NameKey(r1.getChange().change().getProject(), "moveTest");
createBranch(newBranch);
exception.expect(ResourceConflictException.class);
exception.expectMessage("Merge commit cannot be moved");
move(GitUtil.getChangeId(testRepo, c).get(), newBranch.get());
}
use of org.eclipse.jgit.junit.TestRepository in project gerrit by GerritCodeReview.
the class RepoSequenceTest method failOnWrongType.
@Test
public void failOnWrongType() throws Exception {
try (Repository repo = repoManager.openRepository(project)) {
TestRepository<Repository> tr = new TestRepository<>(repo);
tr.branch(RefNames.REFS_SEQUENCES + "id").commit().create();
try {
newSequence("id", 1, 3).next();
fail();
} catch (OrmException e) {
assertThat(e.getCause()).isInstanceOf(ExecutionException.class);
assertThat(e.getCause().getCause()).isInstanceOf(IncorrectObjectTypeException.class);
}
}
}
Aggregations