Example usage for org.eclipse.jgit.api InitCommand InitCommand

List of usage examples for org.eclipse.jgit.api InitCommand InitCommand

Introduction

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

Prototype

InitCommand

Source Link

Usage

From source file:com.athomas.androidkickstartr.util.GitHubber.java

License:Apache License

public Repository createCommit(File srcFolder, String applicationName) throws IOException, GitAPIException {
    Repository repository = repositoryService.createRepository(new Repository().setName(applicationName));

    String cloneUrl = repository.getCloneUrl();

    InitCommand init = new InitCommand();
    init.setDirectory(srcFolder);/*  w  w  w  .  ja  v  a  2s .  c o  m*/
    init.setBare(false);
    Git git = init.call();

    StoredConfig config = git.getRepository().getConfig();
    config.setString("remote", "origin", "url", cloneUrl);
    config.save();

    UsernamePasswordCredentialsProvider user = new UsernamePasswordCredentialsProvider(accessToken, "");
    git.add().addFilepattern(".").call();
    git.commit().setMessage(COMMIT_MESSAGE).call();
    git.push().setCredentialsProvider(user).call();

    return repository;
}

From source file:com.denimgroup.threadfix.service.repository.GitServiceImpl.java

License:Mozilla Public License

@Override
public boolean testConfiguration(Application application, String repo, String branch) throws GitAPIException {
    InitCommand initCommand = new InitCommand();
    File applicationDirectory = DiskUtils.getScratchFile(baseDirectory + application.getId() + "-test");
    initCommand.setDirectory(applicationDirectory);

    Git otherGit = initCommand.call();//from ww w  . j ava  2 s  .c o m

    otherGit.getRepository().getConfig().setString("remote", "origin", "url", repo);

    String targetRefSpec = branch == null || branch.isEmpty() ? Constants.R_HEADS + "*:refs/remotes/origin/*"
            : Constants.R_HEADS + branch;

    FetchCommand fetchCommand = otherGit.fetch()
            .setCredentialsProvider(getUnencryptedApplicationCredentials(application)).setDryRun(true)
            .setRefSpecs(new RefSpec(targetRefSpec)).setRemote("origin");

    fetchCommand.call();

    return true;
}

From source file:com.gmail.cjbooms.thesis.pythonappengine.server.git.GitCommandsServiceImpl.java

License:Open Source License

/**
 * Initialize a new empty GIT repository
 *
 * @param pathToNewRepository Location to build new Repo
 * @throws IOException, JGitInternalException
 *//* w w  w.j  a v a2 s . co m*/
public void initializeNewRepository(String pathToNewRepository) throws IOException, JGitInternalException {
    File directory = new File(pathToNewRepository);
    InitCommand command = new InitCommand();
    command.setDirectory(directory);
    command.call();
}

From source file:com.mortardata.project.TestEmbeddedMortarProject.java

License:Apache License

@Before
public void setUp() throws Exception {
    super.setUp();

    // setup a blank existing project
    this.rootPath = Files.createTempDirectory();

    this.controlscripts = new File(this.rootPath, "controlscripts");
    this.pigscripts = new File(this.rootPath, "pigscripts");
    this.macros = new File(this.rootPath, "macros");
    this.udfs = new File(this.rootPath, "udfs");
    this.fixtures = new File(this.rootPath, "fixtures");

    // write the .mortar-project-remote
    this.remoteURLGit = "git@github.com:mortardata/mortar-api-java.git";
    this.remoteURLHttps = "https://github.com/mortardata/mortar-api-java.git";
    this.write(new File(this.rootPath, EmbeddedMortarProject.MORTAR_PROJECT_REMOTE_FILENAME),
            this.remoteURLGit);

    File[] dirs = { this.pigscripts, this.controlscripts, this.macros, this.udfs, this.fixtures };
    for (File dir : dirs) {
        FileUtils.mkdir(dir);/* w w w  .  ja va2 s.  co m*/
    }

    // setup an empty git repo
    this.mirrorPath = Files.createTempDirectory();
    this.git = new InitCommand().setBare(false).setDirectory(this.mirrorPath).call();

    // do a commit
    this.write(new File(this.mirrorPath, ".gitkeeptest"), "");
    this.git.add().addFilepattern(".gitkeeptest").call();
    this.git.commit().setMessage("initial commit").setAuthor("unitest", "unittest").call();

    this.fakeCP = new UsernamePasswordCredentialsProvider("foo", "bar");
}

From source file:org.ajoberstar.gradle.git.tasks.GitInit.java

License:Apache License

/**
 * Initializes a new local Git repository as configured.
 *///ww  w . ja v a2s  .c o m
@TaskAction
public void initRepo() {
    InitCommand cmd = new InitCommand();
    cmd.setBare(getBare());
    cmd.setDirectory(getDestinationDir());
    try {
        cmd.call();
    } catch (GitAPIException e) {
        throw new GradleException("Problem with initializing new Git repo.", e);
    }
}

From source file:org.eclipse.orion.server.git.jobs.InitJob.java

License:Open Source License

public IStatus performJob() {
    try {/*from  w  ww  . jav a2  s  . co m*/
        InitCommand command = new InitCommand();
        File directory = new File(clone.getContentLocation());
        command.setDirectory(directory);
        Repository repository = command.call().getRepository();
        Git git = new Git(repository);

        // configure the repo
        GitCloneHandlerV1.doConfigureClone(git, user);

        // we need to perform an initial commit to workaround JGit bug 339610
        git.commit().setMessage("Initial commit").call();
    } catch (CoreException e) {
        return e.getStatus();
    } catch (GitAPIException e) {
        return getGitAPIExceptionStatus(e, "Error initializing git repository");
    } catch (JGitInternalException e) {
        return getJGitInternalExceptionStatus(e, "Error initializing git repository");
    } catch (Exception e) {
        return new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error initializing git repository", e);
    }
    JSONObject jsonData = new JSONObject();
    try {
        jsonData.put(ProtocolConstants.KEY_LOCATION, URI.create(this.cloneLocation));
    } catch (JSONException e) {
        // Should not happen
    }
    return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, jsonData);
}

From source file:org.eclipse.orion.server.git.servlets.InitJob.java

License:Open Source License

private IStatus doInit() {
    try {//from   ww  w . ja  va  2 s  . c  o m
        InitCommand command = new InitCommand();
        File directory = new File(clone.getContentLocation());
        command.setDirectory(directory);
        Repository repository = command.call().getRepository();
        Git git = new Git(repository);

        // configure the repo
        GitCloneHandlerV1.doConfigureClone(git, user);

        // we need to perform an initial commit to workaround JGit bug 339610
        git.commit().setMessage("Initial commit").call();
    } catch (CoreException e) {
        return e.getStatus();
    } catch (JGitInternalException e) {
        return getJGitInternalExceptionStatus(e, "An internal git error initializing git repository.");
    } catch (Exception e) {
        return new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error initializing git repository", e);
    }
    return Status.OK_STATUS;
}

From source file:org.eclipse.orion.server.tests.servlets.git.GitUtilsTest.java

License:Open Source License

@Test
public void testGetGitDirWorkspaceIsInRepo() throws Exception {
    InitCommand command = new InitCommand();
    File workspace = getWorkspaceRoot();
    File parent = workspace.getParentFile();
    command.setDirectory(parent);/*ww w  . j  a v a  2s .  c o m*/
    Repository repository = command.call().getRepository();
    assertNotNull(repository);
    testGitDirPathNoGit();
    File[] parentChildren = parent.listFiles();
    for (int i = 0; i < parentChildren.length; i++) {
        if (parentChildren[i].getName().equals(".git")) {
            assertTrue(deleteDir(parentChildren[i]));
        }
    }
}

From source file:org.fedoraproject.eclipse.packager.api.LocalFedoraPackagerProjectCreator.java

License:Open Source License

/**
 * Creates project structure inside the base project
 *
 * @throws CoreException/*ww  w .j  ava  2  s.c o  m*/
 * @throws IOException
 * @throws WrongRepositoryStateException
 * @throws JGitInternalException
 * @throws ConcurrentRefUpdateException
 * @throws NoMessageException
 * @throws NoHeadException
 * @throws NoFilepatternException
 *
 */
public void createProjectStructure()
        throws NoFilepatternException, NoHeadException, NoMessageException, ConcurrentRefUpdateException,
        JGitInternalException, WrongRepositoryStateException, IOException, CoreException {

    File directory = new File(project.getLocation().toString());
    FileUtils.mkdirs(directory, true);
    directory.getCanonicalFile();

    InitCommand command = new InitCommand();
    command.setDirectory(directory);
    command.setBare(false);
    repository = command.call().getRepository();

    git = new Git(repository);

    for (File file : directory.listFiles()) {
        String name = file.getName();

        if (name.contains(".spec")) { //$NON-NLS-1$
            git.add().addFilepattern(name).call();
        }

        if (name.equals(".gitignore")) { //$NON-NLS-1$
            git.add().addFilepattern(name).call();
        }
    }

    // do the first commit
    git.commit().setMessage(FedoraPackagerText.LocalFedoraPackagerProjectCreator_FirstCommit).call();

    // Add created repository to the list of Git repositories so that it
    // shows up in the Git repositories view.
    final RepositoryUtil config = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
    config.addConfiguredRepository(repository.getDirectory());
}

From source file:org.fedoraproject.eclipse.packager.local.api.LocalFedoraPackagerProjectCreator.java

License:Open Source License

/**
 * Initialize a local git repository in project location
 *
 * @throws IOException/*from  w ww.  j  a v a2s.c o  m*/
 * @return File directory of the git repository
 */
private File createLocalGitRepo() throws IOException {
    File directory = new File(project.getLocation().toString());
    FileUtils.mkdirs(directory, true);
    directory.getCanonicalFile();

    InitCommand command = new InitCommand();
    command.setDirectory(directory);
    command.setBare(false);
    repository = command.call().getRepository();

    git = new Git(repository);
    return directory;
}