List of usage examples for org.eclipse.jgit.api Git cloneRepository
public static CloneCommand cloneRepository()
From source file:org.fusesource.fabric.itests.basic.git.GitBridgeTest.java
License:Apache License
public void testWithProfiles() throws Exception { String testProfileNameBase = "mytestprofile-"; System.err.println(executeCommand("fabric:create -n")); Set<Container> containers = ContainerBuilder.create(1, 1).withName("child").assertProvisioningResult() .build();//from www . ja va 2 s .c om String gitRepoUrl = GitUtils.getMasterUrl(getCurator()); GitUtils.waitForBranchUpdate(getCurator(), "1.0"); Git.cloneRepository().setURI(gitRepoUrl).setCloneAllBranches(true).setDirectory(testrepo) .setCredentialsProvider(getCredentialsProvider()).call(); Git git = Git.open(testrepo); GitUtils.configureBranch(git, "origin", gitRepoUrl, "1.0"); git.fetch().setCredentialsProvider(getCredentialsProvider()); GitUtils.checkoutBranch(git, "origin", "1.0"); //Check that the default profile exists assertTrue(new File(testrepo, "default").exists()); //Create test profile for (int i = 1; i <= 3; i++) { String testProfileName = testProfileNameBase + i; System.err.println("Create test profile:" + testProfileName + " in zookeeper"); getFabricService().getVersion("1.0").createProfile(testProfileName); GitUtils.waitForBranchUpdate(getCurator(), "1.0"); git.pull().setRebase(true).setCredentialsProvider(getCredentialsProvider()).call(); //Check that a newly created profile exists assertTrue(new File(testrepo, testProfileName).exists()); //Delete test profile System.err.println("Delete test profile:" + testProfileName + " in git."); git.rm().addFilepattern(testProfileName).call(); git.commit().setMessage("Delete " + testProfileName).call(); git.push().setCredentialsProvider(getCredentialsProvider()).setRemote("origin").call(); GitUtils.waitForBranchUpdate(getCurator(), "1.0"); Thread.sleep(5000); assertFalse(new File(testrepo, testProfileName).exists()); assertNull(getCurator().checkExists() .forPath(ZkPath.CONFIG_VERSIONS_PROFILE.getPath("1.0", testProfileName))); //Create the test profile in git System.err.println("Create test profile:" + testProfileName + " in git."); File testProfileDir = new File(testrepo, testProfileName); testProfileDir.mkdirs(); File testProfileConfig = new File(testProfileDir, "org.fusesource.fabric.agent.properties"); testProfileConfig.createNewFile(); Files.writeToFile(testProfileConfig, "", Charset.defaultCharset()); git.add().addFilepattern(testProfileName).call(); RevCommit commit = git.commit().setMessage("Create " + testProfileName).call(); FileTreeIterator fileTreeItr = new FileTreeIterator(git.getRepository()); IndexDiff indexDiff = new IndexDiff(git.getRepository(), commit.getId(), fileTreeItr); System.out.println(indexDiff.getChanged()); System.out.println(indexDiff.getAdded()); git.push().setCredentialsProvider(getCredentialsProvider()).setRemote("origin").call(); GitUtils.waitForBranchUpdate(getCurator(), "1.0"); //Check that it has been bridged in zookeeper Thread.sleep(15000); assertNotNull(getCurator().checkExists() .forPath(ZkPath.CONFIG_VERSIONS_PROFILE.getPath("1.0", testProfileName))); } }
From source file:org.george.app.rest.GithubResource.java
License:Open Source License
void push(String repo, String username, String accessToken) throws Exception { java.nio.file.Path tmpDir = Files.createTempDirectory("tmpdir"); try (Git git = Git.cloneRepository().setDirectory(tmpDir.toFile()).setURI("https://github.com/" + repo) .call()) {// ww w. ja va2 s . c om git.add().addFilepattern(".").call(); git.commit().setAll(true).setMessage("Initial Commit").call(); Iterable<PushResult> result = git.push().setRemote("https://github.com/" + repo + ".git") .setCredentialsProvider(new UsernamePasswordCredentialsProvider(username, accessToken)) .setPushAll().call(); for (PushResult pushResult : result) { System.out.println(pushResult.getMessages()); } } }
From source file:org.gitcontrib.dataset.GitRepository.java
License:Apache License
public void clon() throws Exception { log.info("Cloning repository: " + url); // prepare a new folder for the cloned repository log.info("Cloning into: " + directory.getAbsolutePath()); directory.delete();//from w w w . j a va 2 s .c o m // then clone Git.cloneRepository().setURI(url).setDirectory(directory).call(); log.info("Cloned successfully: " + url); lastUpdateDate = new Date(); }
From source file:org.gradle.vcs.git.internal.GitVersionControlSystem.java
License:Apache License
private static void cloneRepo(File workingDir, GitVersionControlSpec gitSpec, VersionRef ref) { CloneCommand clone = Git.cloneRepository().setURI(gitSpec.getUrl().toString()).setDirectory(workingDir) .setCloneSubmodules(true);//w ww . j av a 2s .c o m Git git = null; try { git = clone.call(); git.reset().setMode(ResetCommand.ResetType.HARD).setRef(ref.getCanonicalId()).call(); } catch (GitAPIException e) { throw wrapGitCommandException("clone", gitSpec.getUrl(), workingDir, e); } catch (JGitInternalException e) { throw wrapGitCommandException("clone", gitSpec.getUrl(), workingDir, e); } finally { if (git != null) { git.close(); } } }
From source file:org.ihtsdo.ttk.services.sync.Example.java
License:Apache License
/** * Method description//from ww w .j ava 2 s .co m * * * @param args */ public static void main(String[] args) { try { // jGit provides the ability to manage the git repositories from // your code in a very easy manner. For example, to create the new // repository, you just have to indicate the target directory: File targetDir = new File("target/newRepository.git"); Repository repo = new FileRepository(targetDir); repo.create(true); //Cloning the existing git repository is also very easy and nice: Git.cloneRepository().setURI(targetDir.toURI().toString()).setDirectory(new File("target/working-copy")) .setBranch("master").setBare(false).setRemote("origin").setNoCheckout(false).call(); // And here is the way how you can add the changes, // commit and push them to the origin: Git git = new Git(new FileRepository(new File("target/working-copy"))); git.add().addFilepattern(".").call(); git.commit().setMessage("some comment").call(); git.push().setPushAll().setRemote("origin").call(); // http://jzelenkov.com/post/35653947951/diving-into-jgit // http://download.eclipse.org/jgit/docs/jgit-2.0.0.201206130900-r/apidocs/org/eclipse/jgit/api/package-summary.html // http://blogs.atlassian.com/2013/04/git-flow-comes-to-java/ } catch (IOException ex) { Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); } catch (GitAPIException ex) { Logger.getLogger(Example.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:org.impressivecode.depress.scm.git.GitOnlineLogParser.java
License:Open Source License
public static void cloneRepository(final String remoteAddress, final String localPath, final ProgressMonitor monitor) throws InvalidRemoteException, TransportException, GitAPIException { CloneCommand clone = Git.cloneRepository(); clone.setBare(false);//from w w w .ja v a2 s.c om clone.setCloneAllBranches(true); clone.setDirectory(new File(localPath)); clone.setURI(remoteAddress); clone.setProgressMonitor(monitor); clone.call(); }
From source file:org.jabylon.team.git.GitTeamProvider.java
License:Open Source License
@Override public void checkout(ProjectVersion project, IProgressMonitor monitor) throws TeamProviderException { try {//from w w w.j a v a2 s. c om SubMonitor subMon = SubMonitor.convert(monitor, 100); subMon.setTaskName("Checking out"); subMon.worked(20); File repoDir = new File(project.absoluteFilePath().path()); CloneCommand clone = Git.cloneRepository(); clone.setBare(false); clone.setNoCheckout(false); // if(!"master".equals(project.getName())) clone.setBranch("refs/heads/" + project.getName()); // clone.setCloneAllBranches(true); clone.setBranchesToClone(Collections.singletonList("refs/heads/" + project.getName())); clone.setDirectory(repoDir); URI uri = project.getParent().getRepositoryURI(); if (!"https".equals(uri.scheme()) && !"http".equals(uri.scheme())) clone.setTransportConfigCallback(createTransportConfigCallback(project.getParent())); clone.setCredentialsProvider(createCredentialsProvider(project.getParent())); clone.setURI(stripUserInfo(uri).toString()); clone.setProgressMonitor(new ProgressMonitorWrapper(subMon.newChild(70))); clone.call(); subMon.done(); if (monitor != null) monitor.done(); } catch (TransportException e) { throw new TeamProviderException(e); } catch (InvalidRemoteException e) { throw new TeamProviderException(e); } catch (GitAPIException e) { throw new TeamProviderException(e); } }
From source file:org.jboss.arquillian.ce.template.GitAdapter.java
License:Open Source License
public static GitAdapter cloneRepository(File gitDir, String gitRepository) throws Exception { CloneCommand clone = Git.cloneRepository(); clone.setDirectory(gitDir);//from w w w .j a va 2s . co m clone.setURI(gitRepository); return new GitAdapter(clone.call(), gitDir); }
From source file:org.jboss.arquillian.container.openshift.express.OpenShiftRepository.java
License:Apache License
private void initialize() throws IOException { File repository = File.createTempFile("arq-openshift", "express"); repository.delete();//from w w w . j a va 2s. c om repository.mkdirs(); repository.deleteOnExit(); if (log.isLoggable(Level.FINE)) { log.fine("Preparing to clone " + configuration.getRemoteRepositoryUri() + " to " + repository.getAbsolutePath()); } CloneCommand cloneCmd = Git.cloneRepository(); cloneCmd.setDirectory(repository).setURI(configuration.getRemoteRepositoryUri()); cloneCmd.setCredentialsProvider(credentialsProvider); this.git = new GitUtil(cloneCmd.call()); this.markingUtil = new MarkingUtil(git); if (log.isLoggable(Level.FINE)) { log.fine("Cloned remote repository from " + configuration.getRemoteRepositoryUri() + " to " + repository.getAbsolutePath()); } this.identification = new PersonIdent("Arquillian OpenShift Express", "arquillian@jboss.org"); }
From source file:org.jboss.arquillian.container.openshift.OpenShiftRepository.java
License:Apache License
private void initialize() throws IOException, InvalidRemoteException, TransportException, GitAPIException { File repository = File.createTempFile("arq-openshift", null); repository.delete();/*from w w w . j a v a 2 s . c o m*/ repository.mkdirs(); repository.deleteOnExit(); if (log.isLoggable(Level.FINE)) { log.fine("Preparing to clone " + configuration.getRemoteRepositoryUri() + " to " + repository.getAbsolutePath()); } CloneCommand cloneCmd = Git.cloneRepository(); cloneCmd.setDirectory(repository).setURI(configuration.getRemoteRepositoryUri()); cloneCmd.setCredentialsProvider(credentialsProvider); this.git = new GitUtil(cloneCmd.call()); this.markingUtil = new MarkingUtil(git); if (log.isLoggable(Level.FINE)) { log.fine("Cloned remote repository from " + configuration.getRemoteRepositoryUri() + " to " + repository.getAbsolutePath()); } this.identification = new PersonIdent("Arquillian OpenShift Container", "arquillian@jboss.org"); }