Search in sources :

Example 76 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class IdentRevFilterTest method caseSensitiveEmailLocalPart.

@Test
public void caseSensitiveEmailLocalPart() throws Exception {
    IdentRevFilter filter = IdentRevFilter.author("eSt");
    assertThat(filter.matchesPerson(new PersonIdent("null", "est@google.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("null", "Establish@google.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("null", "tESt@google.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("null", "tesTing@google.com"))).isFalse();
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Test(org.junit.Test)

Example 77 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class IdentRevFilterTest method matchesEmailDomain.

@Test
public void matchesEmailDomain() throws Exception {
    // git log --author matches the email domain as well as the enail name.
    IdentRevFilter filter = IdentRevFilter.author("eSt");
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@eSt.com"))).isTrue();
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@eStablish.com"))).isTrue();
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@teSt.com"))).isTrue();
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@teSting.com"))).isTrue();
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Test(org.junit.Test)

Example 78 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class IdentRevFilterTest method caseSensitiveEmailDomain.

@Test
public void caseSensitiveEmailDomain() throws Exception {
    IdentRevFilter filter = IdentRevFilter.author("eSt");
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@est.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@Establish.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@tESt.com"))).isFalse();
    assertThat(filter.matchesPerson(new PersonIdent("null", "null@tesTing.com"))).isFalse();
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Test(org.junit.Test)

Example 79 with PersonIdent

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

the class CreateMergePatchSet method applyImpl.

@Override
protected Response<ChangeInfo> applyImpl(BatchUpdate.Factory updateFactory, ChangeResource rsrc, MergePatchSetInput in) throws OrmException, IOException, InvalidChangeOperationException, RestApiException, UpdateException, PermissionBackendException {
    rsrc.permissions().database(db).check(ChangePermission.ADD_PATCH_SET);
    MergeInput merge = in.merge;
    if (merge == null || Strings.isNullOrEmpty(merge.source)) {
        throw new BadRequestException("merge.source must be non-empty");
    }
    ChangeControl ctl = rsrc.getControl();
    PatchSet ps = psUtil.current(db.get(), ctl.getNotes());
    ProjectControl projectControl = ctl.getProjectControl();
    Change change = ctl.getChange();
    Project.NameKey project = change.getProject();
    Branch.NameKey dest = change.getDest();
    try (Repository git = gitManager.openRepository(project);
        ObjectInserter oi = git.newObjectInserter();
        ObjectReader reader = oi.newReader();
        RevWalk rw = new RevWalk(reader)) {
        RevCommit sourceCommit = MergeUtil.resolveCommit(git, rw, merge.source);
        if (!projectControl.canReadCommit(db.get(), git, sourceCommit)) {
            throw new ResourceNotFoundException("cannot find source commit: " + merge.source + " to merge.");
        }
        RevCommit currentPsCommit = rw.parseCommit(ObjectId.fromString(ps.getRevision().get()));
        Timestamp now = TimeUtil.nowTs();
        IdentifiedUser me = user.get().asIdentifiedUser();
        PersonIdent author = me.newCommitterIdent(now, serverTimeZone);
        RevCommit newCommit = createMergeCommit(in, projectControl, dest, git, oi, rw, currentPsCommit, sourceCommit, author, ObjectId.fromString(change.getKey().get().substring(1)));
        PatchSet.Id nextPsId = ChangeUtil.nextPatchSetId(ps.getId());
        PatchSetInserter psInserter = patchSetInserterFactory.create(ctl, nextPsId, newCommit);
        try (BatchUpdate bu = updateFactory.create(db.get(), project, me, now)) {
            bu.setRepository(git, rw, oi);
            bu.addOp(ctl.getId(), psInserter.setMessage("Uploaded patch set " + nextPsId.get() + ".").setDraft(ps.isDraft()).setNotify(NotifyHandling.NONE).setCheckAddPatchSetPermission(false));
            bu.execute();
        }
        ChangeJson json = jsonFactory.create(ListChangesOption.CURRENT_REVISION);
        return Response.ok(json.format(psInserter.getChange()));
    }
}
Also used : MergeInput(com.google.gerrit.extensions.common.MergeInput) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) RevWalk(org.eclipse.jgit.revwalk.RevWalk) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) ProjectControl(com.google.gerrit.server.project.ProjectControl) Timestamp(java.sql.Timestamp) BatchUpdate(com.google.gerrit.server.update.BatchUpdate) Project(com.google.gerrit.reviewdb.client.Project) Repository(org.eclipse.jgit.lib.Repository) ObjectInserter(org.eclipse.jgit.lib.ObjectInserter) PersonIdent(org.eclipse.jgit.lib.PersonIdent) GerritPersonIdent(com.google.gerrit.server.GerritPersonIdent) ChangeControl(com.google.gerrit.server.project.ChangeControl) Branch(com.google.gerrit.reviewdb.client.Branch) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ObjectReader(org.eclipse.jgit.lib.ObjectReader) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 80 with PersonIdent

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

the class GetPatch method formatEmailHeader.

private static String formatEmailHeader(RevCommit commit) {
    StringBuilder b = new StringBuilder();
    PersonIdent author = commit.getAuthorIdent();
    String subject = commit.getShortMessage();
    String msg = commit.getFullMessage().substring(subject.length());
    if (msg.startsWith("\n\n")) {
        msg = msg.substring(2);
    }
    b.append("From ").append(commit.getName()).append(' ').append(// Fixed timestamp to match output of C Git's format-patch
    "Mon Sep 17 00:00:00 2001\n").append("From: ").append(author.getName()).append(" <").append(author.getEmailAddress()).append(">\n").append("Date: ").append(formatDate(author)).append('\n').append("Subject: [PATCH] ").append(subject).append('\n').append('\n').append(msg);
    if (!msg.endsWith("\n")) {
        b.append('\n');
    }
    return b.append("---\n\n").toString();
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)86 RevCommit (org.eclipse.jgit.revwalk.RevCommit)23 Test (org.junit.Test)21 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)19 ObjectId (org.eclipse.jgit.lib.ObjectId)18 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)15 RevWalk (org.eclipse.jgit.revwalk.RevWalk)13 Change (com.google.gerrit.reviewdb.client.Change)12 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)12 Repository (org.eclipse.jgit.lib.Repository)11 Account (com.google.gerrit.reviewdb.client.Account)10 IOException (java.io.IOException)9 RefUpdate (org.eclipse.jgit.lib.RefUpdate)9 Ref (org.eclipse.jgit.lib.Ref)8 TestRepository (org.eclipse.jgit.junit.TestRepository)7 Date (java.util.Date)6 Result (org.eclipse.jgit.lib.RefUpdate.Result)6 ArrayList (java.util.ArrayList)5 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4