Example usage for org.eclipse.jgit.api Git close

List of usage examples for org.eclipse.jgit.api Git close

Introduction

In this page you can find the example usage for org.eclipse.jgit.api Git close.

Prototype

@Override
public void close() 

Source Link

Document

Free resources associated with this instance.

Usage

From source file:org.cicomponents.test.GitEmitterTest.java

License:Mozilla Public License

@Test
@SneakyThrows//  w w  w . ja v a  2  s.  co m
public void listenerDiscovery() {
    try (WorkingDirectory directory = workingDirectoryProvider.getDirectory()) {
        Git git = Git.init().setDirectory(new File(directory.getDirectory())).call();
        RevCommit commit = git.commit().setAllowEmpty(true).setMessage("Test").call();

        Hashtable<String, Object> properties = new Hashtable<>();
        properties.put("repository", "file://" + git.getRepository().getDirectory().getAbsolutePath());
        properties.put("type", "latest");
        Listener listener = new Listener();
        ServiceRegistration<ResourceListener> registration = bundleContext
                .registerService(ResourceListener.class, listener, properties);

        Collection<ServiceReference<GitRevisionEmitter>> references = bundleContext.getServiceReferences(
                GitRevisionEmitter.class, "(objectClass=" + GitRevisionEmitter.class.getName() + ")");
        assertFalse(references.isEmpty());

        registration.unregister();

        git.close();
    }
}

From source file:org.cicomponents.test.GitEmitterTest.java

License:Mozilla Public License

@Test
@SneakyThrows//from  www. j  a v a 2  s .  c  om
public void listenerRemoval() {
    try (WorkingDirectory directory = workingDirectoryProvider.getDirectory()) {
        Git git = Git.init().setDirectory(new File(directory.getDirectory())).call();
        RevCommit commit = git.commit().setAllowEmpty(true).setMessage("Test").call();

        Hashtable<String, Object> properties = new Hashtable<>();
        properties.put("repository", "file://" + git.getRepository().getDirectory().getAbsolutePath());
        properties.put("type", "latest");
        Listener listener = new Listener();
        ServiceRegistration<ResourceListener> registration = bundleContext
                .registerService(ResourceListener.class, listener, properties);

        Collection<ServiceReference<GitRevisionEmitter>> references = bundleContext.getServiceReferences(
                GitRevisionEmitter.class, "(objectClass=" + GitRevisionEmitter.class.getName() + ")");
        assertFalse(references.isEmpty());

        ObjectId objectId = listener.getFuture().get();
        assertEquals(commit.toObjectId(), objectId);
        listener.reset();

        registration.unregister();

        git.commit().setAllowEmpty(true).setMessage("Test #1").call();

        try {
            listener.getFuture().get(11, TimeUnit.SECONDS);
            fail("Listener was not removed");
        } catch (TimeoutException e) {
            // this is what should happen
        }

        git.close();
    }
}

From source file:org.cicomponents.test.GitEmitterTest.java

License:Mozilla Public License

@Test
@SneakyThrows//  www  . ja  va2  s  .  c o  m
public void listener() {
    try (WorkingDirectory directory = workingDirectoryProvider.getDirectory()) {
        Git git = Git.init().setDirectory(new File(directory.getDirectory())).call();
        RevCommit commit = git.commit().setAllowEmpty(true).setMessage("Test").call();

        Hashtable<String, Object> properties = new Hashtable<>();
        properties.put("repository", "file://" + git.getRepository().getDirectory().getAbsolutePath());
        properties.put("type", "latest");
        Listener listener = new Listener();
        ServiceRegistration<ResourceListener> registration = bundleContext
                .registerService(ResourceListener.class, listener, properties);

        Collection<ServiceReference<GitRevisionEmitter>> references = bundleContext.getServiceReferences(
                GitRevisionEmitter.class, "(objectClass=" + GitRevisionEmitter.class.getName() + ")");

        ObjectId objectId = listener.getFuture().get();
        assertEquals(commit.toObjectId(), objectId);
        listener.reset();

        // Test ongoing commits
        commit = git.commit().setAllowEmpty(true).setMessage("Test #1").call();

        objectId = listener.getFuture().get();
        assertEquals(commit.toObjectId(), objectId);

        git.close();
        registration.unregister();
    }
}

From source file:org.craftercms.deployer.impl.processors.GitPullProcessor.java

License:Open Source License

protected ChangeSet doPull() {
    Git git = openLocalRepository();
    try {/*w  w  w.  j  av a  2 s. c o  m*/
        return pullChanges(git);
    } finally {
        git.close();
    }
}

From source file:org.craftercms.deployer.impl.processors.GitPullProcessor.java

License:Open Source License

protected ChangeSet doClone() {
    Git git = cloneRemoteRepository();
    try {//from ww  w.jav a 2  s. c  o  m
        return resolveChangesFromClone(git);
    } finally {
        git.close();
    }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Adds all changes and creates a commit.
 * //  www. j  a va 2s.c om
 * @param commitMessage
 *            The commit message.
 * @param addDeleted
 *            Specifies whether missing or deleted files should added to
 *            index, too.
 * @return The reference to the created commit.
 * @throws Exception
 *             if anything goes wrong.
 */
public RevCommit addAllAndCommit(String commitMessage, boolean addDeleted) throws Exception {
    Git git = new Git(repository);
    try {
        git.add().addFilepattern(".").call();
        if (addDeleted) {
            addDeletedFiles();
        }
        return commit(commitMessage);
    } finally {
        git.close();
    }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Adds all missing or deleted files to the index.
 * //w ww.j a v a2s.c o  m
 * @throws Exception
 *             if anything goes wrong.
 */
public void addDeletedFiles() throws Exception {
    Git git = new Git(repository);
    try {
        Status status = git.status().call();
        if (!status.getMissing().isEmpty() || !status.getRemoved().isEmpty()) {
            RmCommand rm = git.rm();
            for (String deletedFile : Iterables.concat(status.getMissing(), status.getRemoved())) {
                rm.addFilepattern(deletedFile);
            }
            rm.call();
        }
    } finally {
        git.close();
    }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Adds all changes and amends the latest commit, also changing its message to the given message.
 * /* w w w . j a va 2 s.  c  o  m*/
 * @param message
 *            the amended commit message, must not be null
 * @return The RevCommit of the amended commit.
 * @throws Exception
 *             if anything goes wrong.
 */
public RevCommit addAllAndAmend(String message) throws Exception {
    Git git = new Git(repository);
    try {
        git.add().addFilepattern(".").call();
        return git.commit().setAmend(true).setMessage(message).call();
    } finally {
        git.close();
    }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Adds the given resource to the index/*from  w  w  w .  j a v  a 2 s .  co  m*/
 *
 * @param resource
 * @throws CoreException
 * @throws IOException
 * @throws GitAPIException
 * @throws NoFilepatternException
 */
public void addToIndex(IResource resource)
        throws CoreException, IOException, NoFilepatternException, GitAPIException {
    String repoPath = getRepoRelativePath(resource.getLocation().toString());
    Git git = new Git(repository);
    try {
        git.add().addFilepattern(repoPath).call();
    } finally {
        git.close();
    }
}

From source file:org.eclipse.emf.compare.diagram.papyrus.tests.egit.fixture.GitTestRepository.java

License:Open Source License

/**
 * Adds the given resources to the index
 * //from ww w. j  av  a  2s . co  m
 * @param resources
 *            Resources to add to the index.
 */
public void addToIndex(IResource... resources)
        throws CoreException, IOException, NoFilepatternException, GitAPIException {
    Git git = new Git(repository);
    try {
        for (IResource resource : resources) {
            String repoPath = getRepoRelativePath(resource.getLocation().toString());
            git.add().addFilepattern(repoPath).call();
        }
    } finally {
        git.close();
    }
}