use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class ChangeIT method noteDbCommitsOnPatchSetCreation.
@Test
public void noteDbCommitsOnPatchSetCreation() throws Exception {
assume().that(notesMigration.readChanges()).isTrue();
PushOneCommit.Result r = createChange();
pushFactory.create(db, admin.getIdent(), testRepo, PushOneCommit.SUBJECT, "b.txt", "4711", r.getChangeId()).to("refs/for/master").assertOkStatus();
ChangeInfo c = gApi.changes().id(r.getChangeId()).get();
try (Repository repo = repoManager.openRepository(project);
RevWalk rw = new RevWalk(repo)) {
RevCommit commitPatchSetCreation = rw.parseCommit(repo.exactRef(changeMetaRef(new Change.Id(c._number))).getObjectId());
assertThat(commitPatchSetCreation.getShortMessage()).isEqualTo("Create patch set 2");
PersonIdent expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.updated, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
assertThat(commitPatchSetCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
assertThat(commitPatchSetCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.updated));
assertThat(commitPatchSetCreation.getParentCount()).isEqualTo(1);
RevCommit commitChangeCreation = rw.parseCommit(commitPatchSetCreation.getParent(0));
assertThat(commitChangeCreation.getShortMessage()).isEqualTo("Create change");
expectedAuthor = changeNoteUtil.newIdent(accountCache.get(admin.id).getAccount(), c.created, serverIdent.get(), AnonymousCowardNameProvider.DEFAULT);
assertThat(commitChangeCreation.getAuthorIdent()).isEqualTo(expectedAuthor);
assertThat(commitChangeCreation.getCommitterIdent()).isEqualTo(new PersonIdent(serverIdent.get(), c.created));
assertThat(commitChangeCreation.getParentCount()).isEqualTo(0);
}
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class ExternalIdIT method insertNonParsableExternalIds.
private Set<ConsistencyProblemInfo> insertNonParsableExternalIds() throws IOException {
MutableInteger i = new MutableInteger();
String scheme = "corrupt";
Set<ConsistencyProblemInfo> expectedProblems = new HashSet<>();
try (Repository repo = repoManager.openRepository(allUsers);
RevWalk rw = new RevWalk(repo)) {
String externalId = nextId(scheme, i);
String noteId = insertExternalIdWithoutAccountId(repo, rw, externalId);
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Value for 'externalId." + externalId + ".accountId' is missing, expected account ID"));
externalId = nextId(scheme, i);
noteId = insertExternalIdWithKeyThatDoesntMatchNoteId(repo, rw, externalId);
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': SHA1 of external ID '" + externalId + "' does not match note ID '" + noteId + "'"));
noteId = insertExternalIdWithInvalidConfig(repo, rw, nextId(scheme, i));
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Invalid line in config file"));
noteId = insertExternalIdWithEmptyNote(repo, rw, nextId(scheme, i));
expectedProblems.add(consistencyError("Invalid external ID config for note '" + noteId + "': Expected exactly 1 'externalId' section, found 0"));
}
return expectedProblems;
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class ExternalIdIT method insertExtIdBehindGerritsBack.
private void insertExtIdBehindGerritsBack(ExternalId extId) throws Exception {
try (Repository repo = repoManager.openRepository(allUsers);
RevWalk rw = new RevWalk(repo);
ObjectInserter ins = repo.newObjectInserter()) {
ObjectId rev = ExternalIdReader.readRevision(repo);
NoteMap noteMap = ExternalIdReader.readNoteMap(rw, rev);
ExternalIdsUpdate.insert(rw, ins, noteMap, extId);
ExternalIdsUpdate.commit(repo, rw, ins, rev, noteMap, "insert new ID", serverIdent.get(), serverIdent.get());
}
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.
protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, ObjectId expectedId) throws Exception {
submodule = name(submodule);
ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
RevWalk rw = repo.getRevWalk();
RevCommit c = rw.parseCommit(commitId);
rw.parseBody(c.getTree());
RevTree tree = c.getTree();
RevObject actualId = repo.get(tree, submodule);
assertThat(actualId).isEqualTo(expectedId);
}
use of org.eclipse.jgit.revwalk.RevWalk in project gerrit by GerritCodeReview.
the class SubmitOnPushIT method assertCommit.
private void assertCommit(Project.NameKey project, String branch) throws Exception {
try (Repository r = repoManager.openRepository(project);
RevWalk rw = new RevWalk(r)) {
RevCommit c = rw.parseCommit(r.exactRef(branch).getObjectId());
assertThat(c.getShortMessage()).isEqualTo(PushOneCommit.SUBJECT);
assertThat(c.getAuthorIdent().getEmailAddress()).isEqualTo(admin.email);
assertThat(c.getCommitterIdent().getEmailAddress()).isEqualTo(admin.email);
}
}
Aggregations