Search in sources :

Example 26 with CommitBuilder

use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.

the class PushCertificateCheckerTest method setUp.

@Before
public void setUp() throws Exception {
    TestKey key1 = validKeyWithoutExpiration();
    TestKey key3 = expiredKey();
    repo = new InMemoryRepository(new DfsRepositoryDescription("repo"));
    store = new PublicKeyStore(repo);
    store.add(key1.getPublicKeyRing());
    store.add(key3.getPublicKeyRing());
    PersonIdent ident = new PersonIdent("A U Thor", "author@example.com");
    CommitBuilder cb = new CommitBuilder();
    cb.setAuthor(ident);
    cb.setCommitter(ident);
    assertEquals(RefUpdate.Result.NEW, store.save(cb));
    signedPushConfig = new SignedPushConfig();
    signedPushConfig.setCertNonceSeed("sekret");
    signedPushConfig.setCertNonceSlopLimit(60 * 24);
    checker = newChecker(true);
}
Also used : TestKey(com.google.gerrit.gpg.testutil.TestKey) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) SignedPushConfig(org.eclipse.jgit.transport.SignedPushConfig) PersonIdent(org.eclipse.jgit.lib.PersonIdent) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) DfsRepositoryDescription(org.eclipse.jgit.internal.storage.dfs.DfsRepositoryDescription) Before(org.junit.Before)

Example 27 with CommitBuilder

use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.

the class PublicKeyCheckerTest method save.

private void save() throws Exception {
    PersonIdent ident = new PersonIdent("A U Thor", "author@example.com");
    CommitBuilder cb = new CommitBuilder();
    cb.setAuthor(ident);
    cb.setCommitter(ident);
    RefUpdate.Result result = store.save(cb);
    switch(result) {
        case NEW:
        case FAST_FORWARD:
        case FORCED:
            break;
        case IO_FAILURE:
        case LOCK_FAILURE:
        case NOT_ATTEMPTED:
        case NO_CHANGE:
        case REJECTED:
        case REJECTED_CURRENT_BRANCH:
        case RENAMED:
        default:
            throw new AssertionError(result);
    }
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) RefUpdate(org.eclipse.jgit.lib.RefUpdate)

Example 28 with CommitBuilder

use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.

the class NotesBranchUtil method createCommit.

private RevCommit createCommit(NoteMap map, PersonIdent author, String message, RevCommit... parents) throws IOException {
    CommitBuilder b = new CommitBuilder();
    b.setTreeId(map.writeTree(inserter));
    b.setAuthor(author != null ? author : gerritIdent);
    b.setCommitter(gerritIdent);
    if (parents.length > 0) {
        b.setParentIds(parents);
    }
    b.setMessage(message);
    ObjectId commitId = inserter.insert(b);
    inserter.flush();
    return revWalk.parseCommit(commitId);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder)

Example 29 with CommitBuilder

use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.

the class MergeUtil method writeMergeCommit.

public CodeReviewCommit writeMergeCommit(PersonIdent author, PersonIdent committer, CodeReviewRevWalk rw, ObjectInserter inserter, Branch.NameKey destBranch, CodeReviewCommit mergeTip, ObjectId treeId, CodeReviewCommit n) throws IOException, MissingObjectException, IncorrectObjectTypeException {
    final List<CodeReviewCommit> merged = new ArrayList<>();
    rw.reset();
    rw.markStart(n);
    rw.markUninteresting(mergeTip);
    CodeReviewCommit crc;
    while ((crc = rw.next()) != null) {
        if (crc.getPatchsetId() != null) {
            merged.add(crc);
        }
    }
    StringBuilder msgbuf = new StringBuilder().append(summarize(rw, merged));
    if (!R_HEADS_MASTER.equals(destBranch.get())) {
        msgbuf.append(" into ");
        msgbuf.append(destBranch.getShortName());
    }
    if (merged.size() > 1) {
        msgbuf.append("\n\n* changes:\n");
        for (final CodeReviewCommit c : merged) {
            rw.parseBody(c);
            msgbuf.append("  ");
            msgbuf.append(c.getShortMessage());
            msgbuf.append("\n");
        }
    }
    final CommitBuilder mergeCommit = new CommitBuilder();
    mergeCommit.setTreeId(treeId);
    mergeCommit.setParentIds(mergeTip, n);
    mergeCommit.setAuthor(author);
    mergeCommit.setCommitter(committer);
    mergeCommit.setMessage(msgbuf.toString());
    CodeReviewCommit mergeResult = rw.parseCommit(inserter.insert(mergeCommit));
    mergeResult.setControl(n.getControl());
    return mergeResult;
}
Also used : ArrayList(java.util.ArrayList) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder)

Example 30 with CommitBuilder

use of org.eclipse.jgit.lib.CommitBuilder in project gerrit by GerritCodeReview.

the class SubmoduleOp method composeGitlinksCommit.

/** Amend an existing commit with gitlink updates */
public CodeReviewCommit composeGitlinksCommit(final Branch.NameKey subscriber, CodeReviewCommit currentCommit) throws IOException, SubmoduleException {
    OpenRepo or;
    try {
        or = orm.getRepo(subscriber.getParentKey());
    } catch (NoSuchProjectException | IOException e) {
        throw new SubmoduleException("Cannot access superproject", e);
    }
    StringBuilder msgbuf = new StringBuilder("");
    DirCache dc = readTree(or.rw, currentCommit);
    DirCacheEditor ed = dc.editor();
    for (SubmoduleSubscription s : targets.get(subscriber)) {
        updateSubmodule(dc, ed, msgbuf, s);
    }
    ed.finish();
    ObjectId newTreeId = dc.writeTree(or.ins);
    // Gitlinks are already updated, just return the commit
    if (newTreeId.equals(currentCommit.getTree())) {
        return currentCommit;
    }
    or.rw.parseBody(currentCommit);
    CommitBuilder commit = new CommitBuilder();
    commit.setTreeId(newTreeId);
    commit.setParentIds(currentCommit.getParents());
    if (verboseSuperProject != VerboseSuperprojectUpdate.FALSE) {
        // TODO(czhen): handle cherrypick footer
        commit.setMessage(currentCommit.getFullMessage() + "\n\n* submodules:\n" + msgbuf.toString());
    } else {
        commit.setMessage(currentCommit.getFullMessage());
    }
    commit.setAuthor(currentCommit.getAuthorIdent());
    commit.setCommitter(myIdent);
    ObjectId id = or.ins.insert(commit);
    CodeReviewCommit newCommit = or.rw.parseCommit(id);
    newCommit.copyFrom(currentCommit);
    return newCommit;
}
Also used : DirCache(org.eclipse.jgit.dircache.DirCache) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ObjectId(org.eclipse.jgit.lib.ObjectId) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) SubmoduleSubscription(com.google.gerrit.reviewdb.client.SubmoduleSubscription) IOException(java.io.IOException) DirCacheEditor(org.eclipse.jgit.dircache.DirCacheEditor)

Aggregations

CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)37 ObjectId (org.eclipse.jgit.lib.ObjectId)24 PersonIdent (org.eclipse.jgit.lib.PersonIdent)18 RefUpdate (org.eclipse.jgit.lib.RefUpdate)13 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)11 IOException (java.io.IOException)8 RevWalk (org.eclipse.jgit.revwalk.RevWalk)8 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)7 Result (org.eclipse.jgit.lib.RefUpdate.Result)6 DirCache (org.eclipse.jgit.dircache.DirCache)5 AnyObjectId (org.eclipse.jgit.lib.AnyObjectId)5 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)4 ObjectReader (org.eclipse.jgit.lib.ObjectReader)4 Repository (org.eclipse.jgit.lib.Repository)4 ThreeWayMerger (org.eclipse.jgit.merge.ThreeWayMerger)4 MergeConflictException (com.google.gerrit.extensions.restapi.MergeConflictException)3 OrmException (com.google.gwtorm.server.OrmException)3 ArrayList (java.util.ArrayList)3