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

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

Introduction

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

Prototype

public static InitCommand init() 

Source Link

Document

Return a command object to execute a init command

Usage

From source file:org.ocpsoft.redoculous.tests.git.DeleteAndReinitializeRepositoryTest.java

License:Apache License

@Before
public void before() throws IOException, GitAPIException {
    repository = File.createTempFile("redoc", "ulous-test");
    repository.delete();/*  ww  w . j  a  v a 2s.  c o  m*/
    repository.mkdirs();
    document = new File(repository, "document.asciidoc");
    document.createNewFile();

    Files.write(document, getClass().getClassLoader().getResourceAsStream("asciidoc/toc.asciidoc"));

    repo = Git.init().setDirectory(repository).call();
    repo.add().addFilepattern("document.asciidoc").call();
    repo.commit().setMessage("Initial commit.").call();
}

From source file:org.ocpsoft.redoculous.tests.git.InitializeRepositoryTest.java

License:Apache License

@Before
public void before() throws IOException, GitAPIException {
    repository = File.createTempFile("redoc", "ulous-test");
    repository.delete();/* w  ww.j a v a 2  s  .com*/
    repository.mkdirs();
    File document = new File(repository, "document.asciidoc");
    document.createNewFile();

    Files.write(document, getClass().getClassLoader().getResourceAsStream("asciidoc/toc.asciidoc"));

    Git repo = Git.init().setDirectory(repository).call();
    repo.add().addFilepattern("document.asciidoc").call();
    repo.commit().setMessage("Initial commit.").call();
}

From source file:org.ocpsoft.redoculous.tests.markdown.MarkdownRenderTest.java

License:Apache License

@Before
public void before() throws IOException, GitAPIException {
    repository = File.createTempFile("redoc", "ulous-test");
    repository.delete();//w w w . j a  va2  s.c o m
    repository.mkdirs();
    File document = new File(repository, "document.markdown");
    document.createNewFile();

    Files.write(document, getClass().getClassLoader().getResourceAsStream("markdown/document.markdown"));

    Git repo = Git.init().setDirectory(repository).call();
    repo.add().addFilepattern("document.markdown").call();
    repo.commit().setMessage("Initial commit.").call();
}

From source file:org.ocsoft.olivia.models.project.GitManager.java

License:Mozilla Public License

/**
 * 
 * @throws GitAPIException
 */
public void init() throws GitAPIException {
    Git.init().setDirectory(project.getProjectDir().getOrigin().getFile()).call();
}

From source file:org.oneandone.gitter.integration.Integration.java

License:Apache License

@Before
public void setup() throws IOException, GitAPIException {
    tmpRepo = Files.createTempDirectory("gitter-int");
    git = Git.init().setDirectory(tmpRepo.toFile()).call();
    tmpOutput = Files.createTempFile("gitter-int", "txt");
}

From source file:org.openflexo.hannah.IterativeFileGenerator.java

License:Open Source License

/**
 * <p>Prepares the next generation. It collects the modifications made 
 * since last generation. By default all modifications are kept and merged
 * with the next generation, but the callback allows to cancel 
 * modifications (for example if's pushed back to the model)..</p>
 * //from   w ww . ja  v  a2s .  c  o m
 * @param callback called for each user modification.
 * 
 * @throws IOException for any file manipulation gone wrong.
 * @throws GitAPIException  if Git can't manipulate the repository.
 */
public void start(ModificationHandler callback) throws IOException, GitAPIException {
    // creates output folder if needed.
    if (outputFolder.exists() == false) {
        outputFolder.mkdirs();
    }

    // checks that output folder is a folder and accessible.
    if (outputFolder.isDirectory() == false || outputFolder.canRead() == false
            || outputFolder.canWrite() == false) {
        throw new IOException("Folder '" + outputFolder + "' isn't accessible.");
    }

    if (gitFolder.exists()) {
        throw new IOException("Output folder is already a Git working copy.");
    }

    // is the folder already a generation folder, checks the git file.
    if (hannahFolder.exists() == false) {
        // no repository, creates the repository.
        git = Git.init().setDirectory(outputFolder).setBare(false).call();

        final String[] children = outputFolder.list();
        if (children == null || children.length <= 1) {
            // if folder only contains '.git' creates a dummy file.
            FileUtil.writeFile(new File(outputFolder, DUMMY_FILENAME), "For master branch creation\n", "UTF-8");
        }

        // creates the master branch
        git.add().addFilepattern(".").call();
        git.commit().setMessage("Creates master branch.").call();

        // create the generation branch
        git.branchCreate().setName(GENERATION).call();

    } else {
        // repository exists, renames it and opens it.
        hannahFolder.renameTo(gitFolder);
        git = Git.open(outputFolder);
    }

    // retrieves diffs
    final List<DiffEntry> diffEntries = git.diff().call();
    if (diffEntries.size() > 0) {
        // creates modifications and calls the handler.
        final List<Modification> modifications = createModificationList(diffEntries);
        if (callback != null) {
            callback.modifications(modifications);
        }

        // checks which modifications should be committed
        boolean somethingAccepted = false;
        final AddCommand add = git.add();
        for (Modification modification : modifications) {
            if (modification.isAccept()) {
                somethingAccepted = true;
                add.addFilepattern(modification.getDiff().getNewPath());
            }
        }

        // calls add on accepted modifications
        if (somethingAccepted) {
            add.call();
            git.commit().setMessage("User modifications").call();
        }

        // reverts un-commited diffs
        git.revert().call();

    }

    // checkouts generation branch
    git.checkout().setName(GENERATION).call();

    // clear files before new generation
    final File[] children = outputFolder.listFiles();
    if (children != null) {
        for (File child : children) {
            if (NOT_DELETED_FILES.contains(child.getName()) == false) {
                FileUtil.delete(child);
            }
        }
    }
}

From source file:org.sourcepit.b2.its.util.GitSCM.java

License:Apache License

private static Git create(File repoDir)
        throws GitAPIException, NoFilepatternException, NoHeadException, NoMessageException,
        UnmergedPathsException, ConcurrentRefUpdateException, WrongRepositoryStateException {
    final Git git = Git.init().setDirectory(repoDir).call();
    git.add().addFilepattern(".").call();
    git.commit().setAll(true).setMessage("Initial commit").call();
    return git;/*from   w ww. j  a  v  a2  s  .c  o  m*/
}

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

License:Apache License

protected Git setupGit(final File tempDir) throws IOException, GitAPIException {

    final Git git = Git.init().setBare(true).setDirectory(tempDir).call();

    commit(git, "master", "name", "name@example.com", "cool1", null, null, false, new HashMap<String, File>() {
        {//www  .  j a va 2s  .c  o  m
            put("file1.txt", tempFile("content"));
            put("file2.txt", tempFile("content2"));
        }
    });

    return git;
}

From source file:org.uberfire.provisioning.source.git.CloneTestJUnitTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    tempPath = Files.createTempDirectory("xxx").toFile();
    File repo = new File(tempPath, "repo");
    Files.createDirectory(repo.toPath());
    Git.init().setDirectory(repo).call();
    gitUrl = "file://" + repo.getAbsolutePath();
}

From source file:org.wandora.application.tools.git.Init.java

License:Open Source License

@Override
public void execute(Wandora wandora, Context context) {

    try {/*  ww  w  . jav a 2 s.c  om*/
        Git git = getGit();
        if (git == null) {

            File projectDir = getCurrentProjectFile();

            if (projectDir == null || !projectDir.isDirectory()) {
                SimpleFileChooser chooser = UIConstants.getWandoraProjectFileChooser();
                chooser.setDialogTitle("Select directory for Wandora project git repository");
                if (chooser.open(wandora, SimpleFileChooser.SAVE_DIALOG) == SimpleFileChooser.APPROVE_OPTION) {
                    File f = chooser.getSelectedFile();
                    if (f.exists() && f.isDirectory()) {
                        projectDir = f;
                    }
                }
            }

            setDefaultLogger();
            setLogTitle("Git init");
            if (projectDir != null && projectDir.exists() && projectDir.isDirectory()) {

                wandora.setCurrentProjectFileName(projectDir.getAbsolutePath());

                saveWandoraProject();

                Git.init().setDirectory(projectDir).call();

                log("Created a new repository at " + projectDir.getAbsolutePath());
                log("Ready.");
            } else {
                log("No repository directory found.");
                log("Try again and select directory for the repository.");
                log("Ready.");
            }
        } else {
            setDefaultLogger();
            setLogTitle("Git init");
            log("Current project directory has already been initialized.");
            log("To create new git repository save project to a fresh directory.");
            log("Ready.");
        }
    } catch (GitAPIException gae) {
        log(gae.toString());
    } catch (IOException ioe) {
        log(ioe.toString());
    } catch (TopicMapException tme) {
        log(tme.toString());
    } catch (Exception e) {
        log(e);
    }
    setState(WAIT);
}