Search in sources :

Example 31 with ReceiveCommand

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

the class GroovyScriptTest method testProtectRefsDeleteTag.

@Test
public void testProtectRefsDeleteTag() throws Exception {
    MockGitblit gitblit = new MockGitblit();
    MockLogger logger = new MockLogger();
    MockClientLogger clientLogger = new MockClientLogger();
    List<ReceiveCommand> commands = new ArrayList<ReceiveCommand>();
    ReceiveCommand command = new ReceiveCommand(ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), ObjectId.zeroId(), "refs/tags/v1.0");
    commands.add(command);
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);
    assertEquals(ReceiveCommand.Result.REJECTED_NODELETE, command.getResult());
    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 32 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("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), 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 33 with ReceiveCommand

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

the class GroovyScriptTest method testBlockPush.

@Test
public void testBlockPush() 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("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    try {
        test("blockpush.groovy", gitblit, logger, clientLogger, commands, repository);
        assertTrue("blockpush should have failed!", false);
    } catch (GitBlitException e) {
        assertTrue(e.getMessage().contains("failed"));
    }
}
Also used : ReceiveCommand(org.eclipse.jgit.transport.ReceiveCommand) ArrayList(java.util.ArrayList) GitBlitException(com.gitblit.GitBlitException) RepositoryModel(com.gitblit.models.RepositoryModel) Date(java.util.Date) Test(org.junit.Test)

Example 34 with ReceiveCommand

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

the class GroovyScriptTest method testProtectRefsCreateBranch.

@Test
public void testProtectRefsCreateBranch() 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.zeroId(), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "refs/heads/master"));
    RepositoryModel repository = new RepositoryModel("ex@mple.git", "", "admin", new Date());
    test("protect-refs.groovy", gitblit, logger, clientLogger, commands, repository);
}
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 35 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("c18877690322dfc6ae3e37bb7f7085a24e94e887"), ObjectId.fromString("3fa7c46d11b11d61f1cbadc6888be5d0eae21969"), "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)

Aggregations

ReceiveCommand (org.eclipse.jgit.transport.ReceiveCommand)55 IOException (java.io.IOException)18 ArrayList (java.util.ArrayList)14 Test (org.junit.Test)14 RepositoryModel (com.gitblit.models.RepositoryModel)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 BatchRefUpdate (org.eclipse.jgit.lib.BatchRefUpdate)12 RevWalk (org.eclipse.jgit.revwalk.RevWalk)12 Repository (org.eclipse.jgit.lib.Repository)9 Date (java.util.Date)8 Ref (org.eclipse.jgit.lib.Ref)7 OrmException (com.google.gwtorm.server.OrmException)6 Map (java.util.Map)6 RestApiException (com.google.gerrit.extensions.restapi.RestApiException)5 Change (com.google.gerrit.reviewdb.client.Change)5 PersonIdent (org.eclipse.jgit.lib.PersonIdent)5 TicketModel (com.gitblit.models.TicketModel)4 Change (com.gitblit.models.TicketModel.Change)4 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)4 Account (com.google.gerrit.reviewdb.client.Account)4