Example usage for org.eclipse.jgit.util FileUtils IGNORE_ERRORS

List of usage examples for org.eclipse.jgit.util FileUtils IGNORE_ERRORS

Introduction

In this page you can find the example usage for org.eclipse.jgit.util FileUtils IGNORE_ERRORS.

Prototype

int IGNORE_ERRORS

To view the source code for org.eclipse.jgit.util FileUtils IGNORE_ERRORS.

Click Source Link

Document

Option not to throw exceptions when a deletion finally doesn't succeed.

Usage

From source file:bench.MainJgit.java

License:BSD License

/**
 *//*from   w  w  w  .  java 2 s  .  c o m*/
public static void main(final String[] args) throws Exception {

    final File baseDir = new File(".");

    final File folder = new File(baseDir, "target");

    final File workspace = new File(folder, "workspace");

    FileUtils.delete(workspace, FileUtils.IGNORE_ERRORS | FileUtils.RECURSIVE);

    FileUtils.mkdirs(workspace, true);

    final String remoteURI = "git@github.com:barchart/barchart-jenkins-tester.git";
    final String remoteName = "archon";
    final String remoteBranch = "master";

    final String localBranch = "cascade";

    {
        final Git git = PluginScmGit.doClone(workspace, remoteURI, remoteName);
        final Repository repo = git.getRepository();
        System.out.println("repo " + repo);
    }

    {
        final CheckoutResult result = PluginScmGit.doCheckout(workspace, localBranch, remoteName, remoteBranch);
        System.out.println("checkout " + result.getStatus());
    }

    {
        final CheckoutResult result = PluginScmGit.doCheckout(workspace, localBranch, remoteName, remoteBranch);
        System.out.println("checkout " + result.getStatus());
    }

    {
        final RefSpec fetchSpec = PluginScmGit.refFetch(remoteBranch, remoteName, remoteBranch);

        final FetchResult fetchResult = PluginScmGit.doFetch(workspace, remoteName, fetchSpec);
        System.out.println("fetch satus: " + fetchResult.getAdvertisedRefs());

        final String refHead = PluginScmGit.refHeads(remoteBranch);

        final Ref remoteHead = fetchResult.getAdvertisedRef(refHead);

        final ObjectId commit = remoteHead.getObjectId();

        final MergeResult mergeResult = PluginScmGit.doMerge(workspace, commit);

        final MergeStatus mergeStatus = mergeResult.getMergeStatus();
        System.out.println("merge status: " + mergeStatus);

    }

}

From source file:com.barchart.jenkins.cascade.PluginScmGit.java

License:BSD License

/**
 * Destroy workspace and clone from scratch.
 *///from  w  w  w.  j av a2 s  . c  om
public static Git doClone(final File workspace, final String uri, final String remote) {
    try {
        FileUtils.delete(workspace, FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
        FileUtils.mkdirs(workspace, true);
        return Git.cloneRepository().setURI(uri).setRemote(remote).setNoCheckout(true).setDirectory(workspace)
                .call();
    } catch (final Throwable e) {
        throw new RuntimeException(e);
    }
}

From source file:com.gitblit.tests.JGitUtilsTest.java

License:Apache License

@Test
public void testCreateRepositorySharedSgidParent() throws Exception {
    if (!JnaUtils.isWindows()) {
        String repositoryAll = "NewTestRepositoryAll.git";
        String repositoryUmask = "NewTestRepositoryUmask.git";
        String sgidParent = "sgid";

        File parent = new File(GitBlitSuite.REPOSITORIES, sgidParent);
        File folder = null;/*from w ww  .j  a  va2  s.c  o m*/
        boolean parentExisted = parent.exists();
        try {
            if (!parentExisted) {
                assertTrue("Could not create SGID parent folder.", parent.mkdir());
            }
            int mode = JnaUtils.getFilemode(parent);
            assertTrue(mode > 0);
            assertEquals(0, JnaUtils.setFilemode(parent, mode | JnaUtils.S_ISGID | JnaUtils.S_IWGRP));

            Repository repository = JGitUtils.createRepository(parent, repositoryAll, "all");
            folder = FileKey.resolve(new File(parent, repositoryAll), FS.DETECTED);
            assertNotNull(repository);

            assertEquals("2", repository.getConfig().getString("core", null, "sharedRepository"));

            assertTrue(folder.exists());
            mode = JnaUtils.getFilemode(folder);
            assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);

            mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/HEAD");
            assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
            assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO);

            mode = JnaUtils.getFilemode(folder.getAbsolutePath() + "/config");
            assertEquals(JnaUtils.S_IRGRP | JnaUtils.S_IWGRP, mode & JnaUtils.S_IRWXG);
            assertEquals(JnaUtils.S_IROTH, mode & JnaUtils.S_IRWXO);

            repository.close();
            RepositoryCache.close(repository);

            repository = JGitUtils.createRepository(parent, repositoryUmask, "umask");
            folder = FileKey.resolve(new File(parent, repositoryUmask), FS.DETECTED);
            assertNotNull(repository);

            assertEquals(null, repository.getConfig().getString("core", null, "sharedRepository"));

            assertTrue(folder.exists());
            mode = JnaUtils.getFilemode(folder);
            assertEquals(JnaUtils.S_ISGID, mode & JnaUtils.S_ISGID);

            repository.close();
            RepositoryCache.close(repository);
        } finally {
            FileUtils.delete(new File(parent, repositoryAll), FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
            FileUtils.delete(new File(parent, repositoryUmask), FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
            if (!parentExisted) {
                FileUtils.delete(parent, FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
            }
        }
    }
}

From source file:org.eclipse.che.git.impl.jgit.JGitConnection.java

License:Open Source License

private void deleteRepositoryFolder() {
    try {//from ww  w. jav  a 2  s.c  om
        if (repository.getDirectory().exists()) {
            FileUtils.delete(repository.getDirectory(), FileUtils.RECURSIVE | FileUtils.IGNORE_ERRORS);
        }
    } catch (Exception exception) {
        // Ignore the error since we want to throw the original error
        LOG.error("Could not remove .git folder in path " + repository.getDirectory().getPath(), exception);
    }
}