Search in sources :

Example 1 with CannotRunGeogigOperationException

use of org.locationtech.geogig.api.hooks.CannotRunGeogigOperationException in project GeoGig by boundlessgeo.

the class HooksTest method testExecutableScriptFileHook.

@Test
public void testExecutableScriptFileHook() throws Exception {
    File hooksFolder = new File(geogig.getPlatform().pwd(), ".geogig/hooks");
    File commitPreHookFile;
    String commitPreHookCode;
    // a hook that returns non-zero
    if (Scripting.isWindows()) {
        commitPreHookCode = "exit 1";
    } else {
        commitPreHookCode = "#!/bin/sh\nexit 1";
    }
    commitPreHookFile = new File(hooksFolder, "pre_commit.bat");
    Files.write(commitPreHookCode, commitPreHookFile, Charsets.UTF_8);
    commitPreHookFile.setExecutable(true);
    insertAndAdd(points1);
    try {
        geogig.command(CommitOp.class).setMessage("Message").call();
        fail();
    } catch (Exception e) {
        assertTrue(e instanceof CannotRunGeogigOperationException);
    }
    // a hook that returns zero
    if (Scripting.isWindows()) {
        commitPreHookCode = "exit 0";
    } else {
        commitPreHookCode = "#!/bin/sh\nexit 0";
    }
    commitPreHookFile = new File(hooksFolder, "pre_commit.bat");
    Files.write(commitPreHookCode, commitPreHookFile, Charsets.UTF_8);
    commitPreHookFile.setExecutable(true);
    geogig.command(CommitOp.class).setMessage("Message").call();
}
Also used : File(java.io.File) CannotRunGeogigOperationException(org.locationtech.geogig.api.hooks.CannotRunGeogigOperationException) CannotRunGeogigOperationException(org.locationtech.geogig.api.hooks.CannotRunGeogigOperationException) Test(org.junit.Test)

Aggregations

File (java.io.File)1 Test (org.junit.Test)1 CannotRunGeogigOperationException (org.locationtech.geogig.api.hooks.CannotRunGeogigOperationException)1