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

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

Introduction

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

Prototype

public InitCommand setBare(boolean bare) 

Source Link

Document

Set whether the repository is bare or not

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 ww . j a 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.meltmedia.cadmium.blackbox.test.GitBareRepoInitializer.java

License:Apache License

public void init(String repoPath, String sourceDir, String sourceConfigDir) throws Exception {
    File repoDir = new File(repoPath);
    if (repoDir.exists()) {
        FileUtils.forceDelete(repoDir);//from  ww  w  .  ja v a 2 s.com
    }

    File checkoutDir = new File(repoDir.getAbsoluteFile().getParent(), repoDir.getName() + ".checkout");
    if (checkoutDir.exists()) {
        FileUtils.forceDelete(checkoutDir);
    }
    checkoutPath = checkoutDir.getAbsolutePath();

    InitCommand init = Git.init();
    init.setBare(true);
    init.setDirectory(repoDir);
    bareRepo = init.call();

    clonedGit = GitService.cloneRepo(repoPath, checkoutPath);
    clonedGit.checkinNewContent(sourceConfigDir, "Initial commit");
    clonedGit.push(false);
    clonedGit.newEmtpyRemoteBranch("cd-master");
    clonedGit.switchBranch("cd-master");
    clonedGit.checkinNewContent(sourceDir, "Initial commit");
    clonedGit.push(false);
    clonedGit.newEmtpyRemoteBranch("cfg-master");
    clonedGit.switchBranch("cfg-master");
    clonedGit.checkinNewContent(sourceConfigDir, "Initial commit");
    clonedGit.push(false);
}

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

License:Apache License

/**
 * Initializes a new local Git repository as configured.
 *///  w w  w . j  a  va 2  s  . com
@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.recommenders.snipmatch.GitSnippetRepository.java

License:Open Source License

private void initializeSnippetsRepo() throws GitAPIException {
    InitCommand init = Git.init();
    init.setBare(false);
    init.setDirectory(basedir);//  w w w.j a v a  2 s  . c o  m
    init.call();
}

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

License:Open Source License

/**
 * Creates project structure inside the base project
 *
 * @throws CoreException//  w w w  .ja  v  a 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// w w  w .  j  a  v  a2  s. co 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;
}

From source file:org.fedoraproject.eclipse.packager.tests.commands.SRPMImportCommandTest.java

License:Open Source License

@Before
public void setup() throws Exception {
    String uploadURL = System.getProperty(UPLOAD_URL_PROP);
    if (uploadURL == null) {
        fail(UPLOAD_URL_PROP + " not set");
    }/*from  w  w w .  j  av  a2s  . c o  m*/
    srpmPath = FileLocator.toFileURL(FileLocator.find(TestsPlugin.getDefault().getBundle(),
            new Path("resources/eclipse-3.7.0-new.fc17.src.rpm"), null)).getFile();
    this.uploadURLForTesting = uploadURL;
    testProject = ResourcesPlugin.getWorkspace().getRoot().getProject("eclipse");
    testProject.create(null);
    testProject.open(null);
    testProject.setPersistentProperty(PackagerPlugin.PROJECT_PROP, "true" /* unused value */); //$NON-NLS-1$
    InitCommand ic = new InitCommand();
    ic.setDirectory(testProject.getLocation().toFile());
    ic.setBare(false);
    Repository repository = ic.call().getRepository();
    git = new Git(repository);
    ConnectProviderOperation connect = new ConnectProviderOperation(testProject);
    connect.execute(null);
}

From source file:org.jboss.tools.feedhenry.ui.internal.util.GitUtil.java

License:Open Source License

public static Repository createRepository(IProject project, IProgressMonitor monitor) throws CoreException {
    try {//  w  w w  .ja va 2s.c o m
        InitCommand init = Git.init();
        init.setBare(false).setDirectory(project.getLocation().toFile());
        Git git = init.call();
        return git.getRepository();
    } catch (JGitInternalException | GitAPIException e) {
        throw new CoreException(new Status(IStatus.ERROR, FHPlugin.PLUGIN_ID,
                NLS.bind("Could not initialize a git repository at {0}: {1}", getRepositoryPathFor(project),
                        e.getMessage()),
                e));
    }
}

From source file:org.jboss.tools.openshift.egit.core.EGitUtils.java

License:Open Source License

/**
 * Creates a repository for the given project. The repository is created in
 * the .git directory within the given project. The project is not connected
 * with the new repository/*  ww  w  .  j  av a 2 s.c  o  m*/
 * 
 * @param project
 *            the project to create the repository for.
 * @param monitor
 *            the monitor to report the progress to
 * @return
 * @throws CoreException
 * 
 * @see #connect(IProject, Repository, IProgressMonitor)
 */
public static Repository createRepository(IProject project, IProgressMonitor monitor) throws CoreException {
    try {
        InitCommand init = Git.init();
        init.setBare(false).setDirectory(project.getLocation().toFile());
        Git git = init.call();
        return git.getRepository();
    } catch (JGitInternalException e) {
        throw new CoreException(EGitCoreActivator
                .createErrorStatus(NLS.bind("Could not initialize a git repository at {0}: {1}",
                        getRepositoryPathFor(project), e.getMessage()), e));
    } catch (GitAPIException e) {
        throw new CoreException(EGitCoreActivator
                .createErrorStatus(NLS.bind("Could not initialize a git repository at {0}: {1}",
                        getRepositoryPathFor(project), e.getMessage()), e));
    }
}

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

License:Open Source License

public Repository invoke(File file, VirtualChannel channel) throws IOException {
    String directory = repo.getDirectory();
    File gitDir;/*from  w ww  . j  a va 2 s  .  c  o  m*/
    if (directory == null || directory.length() == 0 || ".".equals(directory))
        gitDir = file;
    else
        gitDir = new File(file, directory);
    if (Constants.DOT_GIT.equals(gitDir.getName()))
        gitDir = new File(gitDir, Constants.DOT_GIT);
    InitCommand init = Git.init();
    init.setBare(false);
    init.setDirectory(gitDir);
    return init.call().getRepository();
}