Search in sources :

Example 76 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gitblit by gitblit.

the class GroovyScriptTest method testProtectRefsDeleteOtherBranch.

@Test
public void testProtectRefsDeleteOtherBranch() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    commands.add(new ReceiveCommand(ObjectId.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), ObjectId.zeroId(), "refs/heads/other"));
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);
    assertEquals(0, logger.messages.size());
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 77 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gitblit by gitblit.

the class GroovyScriptTest method testProtectRefsFastForward.

@Test
public void testProtectRefsFastForward() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    commands.add(new ReceiveCommand(ObjectId.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);
    assertEquals(0, logger.messages.size());
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 78 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gitblit by gitblit.

the class GroovyScriptTest method testClientLogging.

@Test
public void testClientLogging() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    commands.add(new ReceiveCommand(ObjectId.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.fifth)), ObjectId.fromString(GitBlitSuite.helloworldSettings.getRequiredString(HelloworldKeys.commit.deleted)), "refs/heads/master"));
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    File groovyDir = repositories().getHooksFolder();
    File tempScript = File.createTempFile("testClientLogging", "groovy", groovyDir);
    tempScript.deleteOnExit();
    BufferedWriter writer = new BufferedWriter(new FileWriter(tempScript));
    writer.write("clientLogger.info('this is a test message')\n");
    writer.flush();
    writer.close();
    test(tempScript.getName(), gitblit, logger, clientLogger, commands, repository);
    assertTrue("Message Missing", clientLogger.messages.contains("this is a test message"));
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) FileWriter(java.io.FileWriter) ArrayList(java.util.ArrayList) RepositoryModel(com.gitblit.models.RepositoryModel) File(java.io.File) Date(java.util.Date) BufferedWriter(java.io.BufferedWriter) Test(org.junit.Test)

Example 79 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.

the class AbstractSubmit method submitWithValidationMultiRepo.

@Test
public void submitWithValidationMultiRepo() throws Throwable {
    assume().that(isSubmitWholeTopicEnabled()).isTrue();
    String topic = "test-topic";
    // Create test projects
    Project.NameKey keyA = createProjectForPush(getSubmitType());
    TestRepository<?> repoA = cloneProject(keyA);
    Project.NameKey keyB = createProjectForPush(getSubmitType());
    TestRepository<?> repoB = cloneProject(keyB);
    // Create changes on project-a
    PushOneCommit.Result change1 = createChange(repoA, "master", "Change 1", "a.txt", "content", topic);
    PushOneCommit.Result change2 = createChange(repoA, "master", "Change 2", "b.txt", "content", topic);
    // Create changes on project-b
    PushOneCommit.Result change3 = createChange(repoB, "master", "Change 3", "a.txt", "content", topic);
    PushOneCommit.Result change4 = createChange(repoB, "master", "Change 4", "b.txt", "content", topic);
    List<PushOneCommit.Result> changes = Lists.newArrayList(change1, change2, change3, change4);
    for (PushOneCommit.Result change : changes) {
        approve(change.getChangeId());
    }
    // Construct validator which will throw on a second call.
    // Since there are 2 repos, first submit attempt will fail, the second will
    // succeed.
    List<String> projectsCalled = new ArrayList<>(4);
    OnSubmitValidationListener listener = new OnSubmitValidationListener() {

        @Override
        public void preBranchUpdate(Arguments args) throws ValidationException {
            String master = "refs/heads/master";
            assertThat(args.getCommands()).containsKey(master);
            ReceiveCommand cmd = args.getCommands().get(master);
            ObjectId newMasterId = cmd.getNewId();
            try (Repository repo = repoManager.openRepository(args.getProject())) {
                assertThat(repo.exactRef(master).getObjectId()).isEqualTo(cmd.getOldId());
                assertThat(args.getRef(master)).hasValue(newMasterId);
                args.getRevWalk().parseBody(args.getRevWalk().parseCommit(newMasterId));
            } catch (IOException e) {
                throw new AssertionError("failed checking new ref value", e);
            }
            projectsCalled.add(args.getProject().get());
            if (projectsCalled.size() == 2) {
                throw new ValidationException("time to fail");
            }
        }
    };
    try (Registration registration = extensionRegistry.newRegistration().add(listener)) {
        submitWithConflict(change4.getChangeId(), "time to fail");
        assertThat(projectsCalled).containsExactly(keyA.get(), keyB.get());
        for (PushOneCommit.Result change : changes) {
            change.assertChange(Change.Status.NEW, name(topic), admin);
        }
        submit(change4.getChangeId());
        assertThat(projectsCalled).containsExactly(keyA.get(), keyB.get(), keyA.get(), keyB.get());
        for (PushOneCommit.Result change : changes) {
            change.assertChange(Change.Status.MERGED, name(topic), admin);
        }
    }
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ValidationException(com.google.gerrit.server.validators.ValidationException) ObjectId(org.eclipse.jgit.lib.ObjectId) ArrayList(java.util.ArrayList) IOException(java.io.IOException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) Project(com.google.gerrit.entities.Project) TestRepository(org.eclipse.jgit.junit.TestRepository) Repository(org.eclipse.jgit.lib.Repository) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) OnSubmitValidationListener(com.google.gerrit.server.git.validators.OnSubmitValidationListener) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 80 with ReceiveCommand

use of org.eclipse.jgit.transport.ReceiveCommand in project gerrit by GerritCodeReview.

the class CommitRewriterTest method cleanUp.

@After
public void cleanUp() throws Exception {
    BatchRefUpdate bru = repo.getRefDatabase().newBatchUpdate();
    bru.setAllowNonFastForwards(true);
    for (Ref ref : repo.getRefDatabase().getRefsByPrefix(RefNames.REFS_CHANGES)) {
        Change.Id changeId = Change.Id.fromRef(ref.getName());
        if (changeId == null || !ref.getName().equals(RefNames.changeMetaRef(changeId))) {
            continue;
        }
        bru.addCommand(new ReceiveCommand(ref.getObjectId(), ObjectId.zeroId(), ref.getName()));
    }
    RefUpdateUtil.executeChecked(bru, repo);
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) Ref(org.eclipse.jgit.lib.Ref) Change(com.google.gerrit.entities.Change) BatchRefUpdate(org.eclipse.jgit.lib.BatchRefUpdate) After(org.junit.After)

Aggregations

ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)82 IOException (java.io.IOException)29 ArrayList (java.util.ArrayList)23 ObjectId (org.eclipse.jgit.lib.ObjectId)23 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)22 RevWalk (org.eclipse.jgit.revwalk.RevWalk)21 Repository (org.eclipse.jgit.lib.Repository)19 Ref (org.eclipse.jgit.lib.Ref)18 Test (org.junit.Test)16 RepositoryModel (com.gitblit.models.RepositoryModel)13 Map (java.util.Map)13 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)11 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)10 StorageException (com.google.gerrit.exceptions.StorageException)9 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)9 PersonIdent (org.eclipse.jgit.lib.PersonIdent)9 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)8 Collection (java.util.Collection)8