Example usage for org.eclipse.jgit.hooks PostCommitHook NAME

List of usage examples for org.eclipse.jgit.hooks PostCommitHook NAME

Introduction

In this page you can find the example usage for org.eclipse.jgit.hooks PostCommitHook NAME.

Prototype

String NAME

To view the source code for org.eclipse.jgit.hooks PostCommitHook NAME.

Click Source Link

Document

The post-commit hook name.

Usage

From source file:org.uberfire.io.impl.BatchTest.java

License:Apache License

@Test
public void hooksShouldBeCalledOnBatch() throws IOException {

    final File hooksDir = CommonIOServiceDotFileTest.createTempDirectory();
    System.setProperty("org.uberfire.nio.git.hooks", hooksDir.getAbsolutePath());

    writeMockHook(hooksDir, "post-commit");

    JGitFileSystemProvider provider = (JGitFileSystemProvider) FileSystemProviders
            .resolveProvider(URI.create("git://hook-fs/"));

    final AtomicInteger postCommitHookCalled = new AtomicInteger();

    provider.setDetectedFS(new FS_POSIX() {
        @Override/*from w w  w .  j a va2s .c  o m*/
        public ProcessResult runHookIfPresent(Repository repox, String hookName, String[] args)
                throws JGitInternalException {
            if (hookName.equals(PostCommitHook.NAME)) {
                postCommitHookCalled.incrementAndGet();
                return new ProcessResult(1, ProcessResult.Status.OK);
            }
            return new ProcessResult(ProcessResult.Status.NOT_PRESENT);
        }
    });

    ioService.newFileSystem(URI.create("git://hook-fs/"), new HashMap<>());

    Path init = ioService.get(URI.create("git://hook-fs/init.file"));

    ioService.write(init, "setupFS!");

    ioService.startBatch(init.getFileSystem());

    ioService.write(init, "onBatch!");

    ioService.endBatch();

    assertEquals(2, postCommitHookCalled.get());
}

From source file:org.uberfire.java.nio.fs.jgit.JGitCloneTest.java

License:Apache License

@Test
public void testCloneWithHookDir() throws IOException, GitAPIException {
    final File hooksDir = createTempDirectory();

    writeMockHook(hooksDir, PostCommitHook.NAME);
    writeMockHook(hooksDir, PreCommitHook.NAME);

    final File parentFolder = createTempDirectory();

    final File gitSource = new File(parentFolder, SOURCE_GIT + ".git");

    final File gitTarget = new File(parentFolder, TARGET_GIT + ".git");

    final Git origin = setupGitRepo(gitSource, hooksDir);

    final Git cloned = new Clone(gitTarget, gitSource.getAbsolutePath(), false, null,
            CredentialsProvider.getDefault(), null, hooksDir, true).execute().get();

    assertThat(cloned).isNotNull();/*  w  w w  .ja v  a 2  s. c o m*/

    assertThat(new ListRefs(cloned.getRepository()).execute()).hasSize(2);
    assertEquals(new ListRefs(cloned.getRepository()).execute().size(),
            new ListRefs(origin.getRepository()).execute().size());

    assertThat(new ListRefs(cloned.getRepository()).execute().get(0).getName()).isEqualTo("refs/heads/master");
    assertThat(new ListRefs(cloned.getRepository()).execute().get(1).getName())
            .isEqualTo("refs/heads/user_branch");

    boolean foundPreCommitHook = false;
    boolean foundPostCommitHook = false;
    File[] hooks = new File(cloned.getRepository().getDirectory(), "hooks").listFiles();
    assertThat(hooks).isNotEmpty().isNotNull();
    assertThat(hooks.length).isEqualTo(2);
    for (File hook : hooks) {
        if (hook.getName().equals(PreCommitHook.NAME)) {
            foundPreCommitHook = hook.canExecute();
        } else if (hook.getName().equals(PostCommitHook.NAME)) {
            foundPostCommitHook = hook.canExecute();
        }
    }
    assertThat(foundPreCommitHook).isTrue();
    assertThat(foundPostCommitHook).isTrue();
}

From source file:org.uberfire.java.nio.fs.jgit.JGitSubdirectoryCloneTest.java

License:Apache License

@Test
public void cloneSubdirectoryWithHookDir() throws Exception {
    final File hooksDir = createTempDirectory();

    writeMockHook(hooksDir, PostCommitHook.NAME);
    writeMockHook(hooksDir, PreCommitHook.NAME);

    final File parentFolder = createTempDirectory();

    final File sourceDir = new File(parentFolder, SOURCE_GIT + ".git");

    final File targetDir = new File(parentFolder, TARGET_GIT + ".git");

    final Git origin = gitRepo(sourceDir);
    commit(origin, "master", "first", content("dir1/file.txt", "foo"));
    commit(origin, "master", "second", content("dir2/file2.txt", "bar"));
    commit(origin, "master", "third", content("file3.txt", "moogah"));

    final Git cloned = new SubdirectoryClone(targetDir, sourceDir.getAbsoluteFile().toURI().toString(), "dir1",
            singletonList("master"), CredentialsProvider.getDefault(), null, hooksDir).execute();

    assertThat(origin.getRepository().getRemoteNames()).isEmpty();

    assertThat(cloned).isNotNull();/*  w ww .java  2  s. c  om*/
    assertThat(listRefs(cloned)).hasSize(1);

    final List<RevCommit> cloneCommits = getCommits(cloned, "master");
    assertThat(cloneCommits).hasSize(1);

    final RevCommit clonedCommit = cloneCommits.get(0);
    final RevCommit originCommit = getCommits(origin, "master").get(2); // Ordered children first

    assertClonedCommitData(origin, "dir1", clonedCommit, originCommit);

    boolean foundPreCommitHook = false;
    boolean foundPostCommitHook = false;
    File[] hooks = new File(cloned.getRepository().getDirectory(), "hooks").listFiles();
    assertThat(hooks).isNotEmpty().isNotNull();
    assertThat(hooks.length).isEqualTo(2);
    for (File hook : hooks) {
        if (hook.getName().equals(PreCommitHook.NAME)) {
            foundPreCommitHook = hook.canExecute();
        } else if (hook.getName().equals(PostCommitHook.NAME)) {
            foundPostCommitHook = hook.canExecute();
        }
    }
    assertThat(foundPreCommitHook).isTrue();
    assertThat(foundPostCommitHook).isTrue();
}