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

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

Introduction

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

Prototype

public AddCommand add() 

Source Link

Document

Return a command object to execute a Add command

Usage

From source file:org.jboss.forge.addon.git.GitUtilsImpl.java

License:Open Source License

@Override
public void add(final Git repo, String filepattern) throws GitAPIException {
    repo.add().addFilepattern(filepattern).call();
}

From source file:org.jboss.forge.addon.git.GitUtilsImpl.java

License:Open Source License

@Override
public void addAll(final Git repo) throws GitAPIException {
    repo.add().addFilepattern(".").call();
}

From source file:org.jboss.forge.git.GitUtils.java

License:Open Source License

public static void add(final Git repo, String filepattern) throws GitAPIException {
    repo.add().addFilepattern(filepattern).call();
}

From source file:org.jboss.forge.git.GitUtils.java

License:Open Source License

public static void addAll(final Git repo) throws GitAPIException {
    repo.add().addFilepattern(".").call();
}

From source file:org.jboss.forge.rest.main.GitCommandCompletePostProcessor.java

License:Apache License

protected void doAddCommitAndPushFiles(Git git, CredentialsProvider credentials, PersonIdent personIdent,
        String remote, String branch) throws IOException, GitAPIException {
    /*//from  w w  w  .  j  av a2s  . co  m
            File rootDir = GitHelpers.getRootGitDirectory(git);
            File[] files = rootDir.listFiles();
            if (files != null) {
    for (File file : files) {
        if (!ignoreRootFile(file)) {
            String relativePath = getFilePattern(rootDir, file);
            git.add().addFilepattern(relativePath).call();
        }
    }
            }
    */
    git.add().addFilepattern(".").call();
    doCommitAndPush(git, "Initial import", credentials, personIdent, remote, branch);
}

From source file:org.jboss.tools.openshift.ui.bot.test.application.v3.adapter.ImportApplicationWizardGitTest.java

License:Open Source License

private void performCommit(Git repo) {
    try {/* w  w w. ja v a  2s .  co m*/
        File commitFile = new File(projectFolder, "commitFile.txt");
        boolean fileCreated = commitFile.createNewFile();
        assertTrue("Failed to create commit file!", fileCreated);

        repo.add().addFilepattern(".").call();
        repo.commit().setMessage("Init commit. Required for master creation.").call();
    } catch (IOException | GitAPIException e) {
        e.printStackTrace();
        fail();
    }
}

From source file:org.jenkinsci.git.GitHelper.java

License:Open Source License

/**
 * Add files to test repository/*from  ww  w.  ja  va2  s  .  c  o m*/
 * 
 * @param repo
 * @param paths
 * @param contents
 * @param message
 * @return commit
 * @throws Exception
 */
public RevCommit add(File repo, List<String> paths, List<String> contents, String message) throws Exception {
    Git git = Git.open(repo);
    for (int i = 0; i < paths.size(); i++) {
        String path = paths.get(i);
        String content = contents.get(i);
        File file = new File(repo.getParentFile(), path);
        if (!file.getParentFile().exists())
            assertTrue(file.getParentFile().mkdirs());
        if (!file.exists())
            assertTrue(file.createNewFile());
        PrintWriter writer = new PrintWriter(file);
        if (content == null)
            content = "";
        try {
            writer.print(content);
        } finally {
            writer.close();
        }
        git.add().addFilepattern(path).call();
    }
    RevCommit commit = git.commit().setMessage(message).setAuthor(author).setCommitter(committer).call();
    assertNotNull(commit);
    return commit;
}

From source file:org.kaazing.bower.dependency.maven.plugin.UploadBowerArtifactMojo.java

License:Open Source License

@Override
public void execute() throws MojoExecutionException, MojoFailureException {

    CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider(username, password);
    File repoDir = new File(outputDir);
    Git repo = checkoutGitRepo(repoDir, gitBowerUrl, credentialsProvider);
    if (preserveFiles == null || preserveFiles.isEmpty()) {
        preserveFiles = new ArrayList<String>();
        preserveFiles.add("README.md");
        preserveFiles.add("bower.json");
        preserveFiles.add("package.json");
        preserveFiles.add(".git");

    }/*from  w ww. j a v  a  2 s.  co  m*/
    for (File file : repoDir.listFiles()) {
        if (!preserveFiles.contains(file.getName())) {
            file.delete();
            try {
                repo.rm().addFilepattern(file.getName()).call();
            } catch (GitAPIException e) {
                throw new MojoExecutionException("Failed to reset repo", e);
            }
        }
    }

    for (String include : includes) {
        File includedFile = new File(includeBaseDir, include);
        if (!includedFile.exists()) {
            throw new MojoExecutionException("Included file \"" + include
                    + "\" does not exist at includeBaseDir/{name}: " + includedFile.getAbsolutePath());
        }
        if (includedFile.isDirectory()) {
            throw new MojoExecutionException("Included files can not be directory: " + includedFile);
        }
        try {
            Files.copy(includedFile.toPath(), new File(outputDir, include).toPath());
        } catch (IOException e) {
            throw new MojoExecutionException("Failed to copy included resource", e);
        }
        try {
            repo.add().addFilepattern(include).call();
        } catch (GitAPIException e) {
            throw new MojoExecutionException("Failed to add included file", e);
        }
    }

    if (directoryToInclude != null && !directoryToInclude.equals("")) {
        File includedDir = new File(directoryToInclude);
        if (!includedDir.exists() && includedDir.isDirectory()) {
            throw new MojoExecutionException(
                    "Included directory \"" + directoryToInclude + "\" does not exist");
        }
        for (File includedFile : includedDir.listFiles()) {
            String include = includedFile.getName();
            if (includedFile.isDirectory()) {
                throw new MojoExecutionException("Included files can not be directory: " + includedFile);
            }
            try {
                Files.copy(includedFile.toPath(), new File(outputDir, include).toPath());
            } catch (IOException e) {
                throw new MojoExecutionException("Failed to copy included resource", e);
            }
            try {
                repo.add().addFilepattern(include).call();
            } catch (GitAPIException e) {
                throw new MojoExecutionException("Failed to add included file", e);
            }
        }
    }

    try {
        repo.commit().setMessage("Added files for next release of " + version).call();
    } catch (GitAPIException e) {
        throw new MojoExecutionException("Failed to commit to repo with changes", e);
    }
    try {
        repo.tag().setName(version).setMessage("Releasing version: " + version).call();
    } catch (GitAPIException e) {
        throw new MojoExecutionException("Failed to tag release", e);
    }
    try {
        repo.push().setPushTags().setCredentialsProvider(credentialsProvider).call();
        repo.push().setPushAll().setCredentialsProvider(credentialsProvider).call();
    } catch (GitAPIException e) {
        throw new MojoExecutionException("Failed to push changes", e);
    }
}

From source file:org.kantega.reststop.maven.CreatePluginMojo.java

License:Apache License

private void addNewFilesToGit(File pluginsDir, File pluginPomFile, File pluginClassFile) throws IOException {
    File gitDir = new File(new File(pluginsDir.getParent()), ".git");
    if (gitDir.exists()) {
        File workDir = new File(gitDir.getParent());
        Git git = null;

        try {//ww  w .  j av a  2s .  c om
            git = Git.open(workDir);
            git.add().addFilepattern(getRelativeTo(pluginPomFile, workDir)).call();
            git.add().addFilepattern(getRelativeTo(pluginClassFile, workDir)).call();
        } catch (GitAPIException e) {
            // ignore
        } finally {
            if (git != null) {
                git.close();
            }

        }
    }
}

From source file:org.kie.wb.test.rest.RestTestBase.java

License:Apache License

@BeforeClass
public static void createGitRepository() throws GitAPIException, IOException {
    gitRepository = new File(System.getProperty("user.dir"), "target/git-repository/");
    Git git = Git.init().setDirectory(gitRepository).call();

    URL pomUrl = RestTestBase.class.getResource("/pom.xml");
    File pomFile = new File(gitRepository, "pom.xml");
    FileUtils.copyURLToFile(pomUrl, pomFile);

    git.add().addFilepattern("pom.xml").call();
    git.commit().setMessage("Add pom.xml").call();
}