public Git cloneInto(File dir, boolean isBare) throws GitAPIException { Preconditions.checkNotNull(dir); Preconditions.checkArgument(dir.exists(),"dir does not exist: "+dir.getAbsolutePath()); CloneCommand cc = Git.cloneRepository().setURI(url).setBare(isBare) .setDirectory(dir).setCloneAllBranches(true); if ((!Strings.isNullOrEmpty(username)) || (!Strings.isNullOrEmpty(password))) { cc = cc.setCredentialsProvider(new UsernamePasswordCredentialsProvider( Strings.nullToEmpty(username), Strings .nullToEmpty(password))); } Git git = cc.call(); return git; }
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey, String remote) { // clone the repo! boolean cloneAll = false; LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath()); CloneCommand command = Git.cloneRepository(); GitHelpers.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey); command = command.setCredentialsProvider(credentialsProvider). setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote); try { command.call(); } catch (Throwable e) { LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e); throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage()); } }
public static GitService cloneRepo(String uri, String dir) throws Exception { if(dir == null || !FileSystemManager.exists(dir)) { log.debug("Cloning \""+uri+"\" to \""+dir+"\""); CloneCommand clone = Git.cloneRepository(); clone.setCloneAllBranches(false); clone.setCloneSubmodules(false); if(dir != null) { clone.setDirectory(new File(dir)); } clone.setURI(uri); try { return new GitService(clone.call()); } catch(Exception e) { if(new File(dir).exists()) { FileUtils.forceDelete(new File(dir)); } throw e; } } return null; }
static private Git cloneRepository(final String name) { return Git.cloneRepository() .setBare( true ) .setCloneAllBranches( true ) .setURI( METHOD + BASE + name + ".git" ) .setDirectory( new File( LOCAL_STORE, name ) ) .call(); }
/** * Clone a git repository. * * @param uri Where from? * @param dest Where to? * @param bare Bare (metadata-only) or full? * @throws GitAPIException */ private void cloneGitRepository(String uri, Path dest, boolean bare) throws GitAPIException { File directory = new File(dest.toString()); if (directory.exists()) throw new RepoDrillerException("Error, destination " + dest.toString() + " already exists"); log.info("Cloning Remote Repository " + uri + " into " + this.path); Git.cloneRepository() .setURI(uri) .setBare(bare) .setDirectory(directory) .setCloneAllBranches(true) .setNoCheckout(false) .call(); }
public static void cloneRepo(File projectFolder, String cloneUrl, CredentialsProvider credentialsProvider, final File sshPrivateKey, final File sshPublicKey, String remote, String tag) { StopWatch watch = new StopWatch(); // clone the repo! boolean cloneAll = true; LOG.info("Cloning git repo " + cloneUrl + " into directory " + projectFolder.getAbsolutePath() + " cloneAllBranches: " + cloneAll); CloneCommand command = Git.cloneRepository(); GitUtils.configureCommand(command, credentialsProvider, sshPrivateKey, sshPublicKey); command = command.setCredentialsProvider(credentialsProvider). setCloneAllBranches(cloneAll).setURI(cloneUrl).setDirectory(projectFolder).setRemote(remote); try { Git git = command.call(); if (tag != null){ git.checkout().setName(tag).call(); } } catch (Throwable e) { LOG.error("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage(), e); throw new RuntimeException("Failed to command remote repo " + cloneUrl + " due: " + e.getMessage()); } finally { LOG.info("cloneRepo took " + watch.taken()); } }
public static Git tempClone(final JGitFileSystem fs, final String uuid) { try { File tempRepoPlace; int i = 0; while (true) { tempRepoPlace = new File(TEMP + uuid + "_" + i, fs.getGit().getRepository().getDirectory().getName().replaceFirst("\\.git", "")); if (tempRepoPlace.exists()) { i++; } else { break; } } return Git.cloneRepository() .setURI(fs.getGit().getRepository().getDirectory().toURI().toString()) .setDirectory(tempRepoPlace) .setBare(false) .setCloneAllBranches(true) .call(); } catch (GitAPIException e) { throw new RuntimeException(e); } } }
private void registerServlet(Path dataPath, String realm, String role) throws Exception { synchronized (gitRemoteUrl) { basePath = dataPath.resolve(Paths.get("git", "servlet")); Path fabricRepoPath = basePath.resolve("fabric"); String servletBase = basePath.toFile().getAbsolutePath(); // Init and clone the local repo. File fabricRoot = fabricRepoPath.toFile(); if (!fabricRoot.exists()) { File localRepo = gitDataStore.get().getGit().getRepository().getDirectory(); git = Git.cloneRepository() .setTimeout(10) .setBare(true) .setNoCheckout(true) .setCloneAllBranches(true) .setDirectory(fabricRoot) .setURI(localRepo.toURI().toString()) .call(); } else { git = Git.open(fabricRoot); } HttpContext base = httpService.get().createDefaultHttpContext(); HttpContext secure = new GitSecureHttpContext(base, curator.get(), realm, role); Dictionary<String, Object> initParams = new Hashtable<String, Object>(); initParams.put("base-path", servletBase); initParams.put("repository-root", servletBase); initParams.put("export-all", "true"); httpService.get().registerServlet("/git", new FabricGitServlet(git, curator.get()), initParams, secure); } }
.setBare(true) .setNoCheckout(true) .setCloneAllBranches(true) .setDirectory(fabricRoot) .setURI(localRepo.toURI().toString())
public synchronized void ensureLocalClone() throws IOException { GitRepository gitRepository = getGitRepository(); try { if (git != null) { return; } File dir = Files.createTempDir(); logger.info("cloning {} into {}", gitRepository.getUrl(), dir); CloneCommand cc = Git.cloneRepository() .setURI(gitRepository.getUrl()).setBare(true) .setDirectory(dir).setCloneAllBranches(true); if ((!Strings.isNullOrEmpty(gitRepository.getUsername())) || (!Strings.isNullOrEmpty(gitRepository.getPassword()))) { cc = cc.setCredentialsProvider(new UsernamePasswordCredentialsProvider( Strings.nullToEmpty(gitRepository.getUsername()), Strings.nullToEmpty(gitRepository.getPassword()))); } git = cc.call(); repo = git.getRepository(); } catch (GitAPIException e) { throw new IOException(e); } }
public static Git cloneRepository(final File repoFolder, final String fromURI, final CredentialsProvider credentialsProvider) { if (!repoFolder.getName().endsWith(DOT_GIT_EXT)) { throw new RuntimeException("Invalid name"); } try { final File gitDir = RepositoryCache.FileKey.resolve(repoFolder, DETECTED); final Repository repository; final Git git; if (gitDir != null && gitDir.exists()) { repository = new FileRepository(gitDir); git = new Git(repository); } else { git = Git.cloneRepository() .setBare(true) .setCloneAllBranches(true) .setURI(fromURI) .setDirectory(repoFolder) .setCredentialsProvider(credentialsProvider) .call(); repository = git.getRepository(); } fetchRepository(git, credentialsProvider); repository.close(); return git; } catch (final Exception ex) { throw new RuntimeException(ex); } }
public Repository cloneRepositoryToTempFolder(boolean checkoutAll) throws GitAPIException, IOException { this.targetFolder = createTempFolder(repositoryName); final Repository repository = Git.cloneRepository() .setURI(repositoryUrl) .setDirectory(targetFolder) .setCloneAllBranches(true) .setBranch("master") .call() .getRepository(); if (checkoutAll) { checkoutAllBranches(repository); } LOGGER.info("Cloned test repository to: " + targetFolder); return repository; }
public static boolean cloneRepo(final String uri, final File cloneTo, final String branch, final GitCloneProgressCallback callback) { Git result = null; try { final CloneCommand clone = Git.cloneRepository() .setURI(uri).setDirectory(cloneTo) .setBare(false).setRemote(REMOTE_NAME).setNoCheckout(false) .setCloneAllBranches(false).setCloneSubmodules(false) .setProgressMonitor(callback); if (!branch.isEmpty()) { if (branch.contains("/")) { clone.setBranch(branch.substring(branch.lastIndexOf('/') + 1)); } else { clone.setBranch(branch); } } result = clone.call(); return true; } catch (GitAPIException e) { e.printStackTrace(); } finally { if (result != null) { result.close(); } } return false; }
@Test public void testRemoteRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final File tempDir = createTempDirectory(); final Git git = new GitImpl(GitImpl._cloneRepository().setNoCheckout(false).setBare(true).setCloneAllBranches(true).setURI(setupGit().getRepository().getDirectory().toString()).setDirectory(tempDir).call()); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
@Test public void testRemoteRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock(JGitFileSystemProvider.class); final File tempDir = createTempDirectory(); final Git git = new GitImpl(GitImpl._cloneRepository().setNoCheckout(false).setBare(true).setCloneAllBranches(true).setURI(setupGit().getRepository().getDirectory().toString()).setDirectory(tempDir).call()); final JGitFileSystemImpl fileSystem = new JGitFileSystemImpl(fsProvider, null, git, createFSLock(git), "my-repo", CredentialsProvider.getDefault(), null, null); assertThat(fileSystem.isReadOnly()).isFalse(); assertThat(fileSystem.getSeparator()).isEqualTo("/"); assertThat(fileSystem.getName()).isEqualTo("my-repo"); assertThat(fileSystem.getRootDirectories()).hasSize(1); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat(root.toString()).isEqualTo("/"); assertThat(root.getRoot().toString()).isEqualTo("/"); }
public static void cloneRepo(String uri, File cloneTo) { Git result = null; try { result = Git.cloneRepository().setURI(uri).setDirectory(cloneTo) .setBranch(MASTER_BRANCH).setBare(false).setRemote(REMOTE_NAME) .setNoCheckout(false).setCloneAllBranches(false).setCloneSubmodules(false).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (result != null) { result.close(); } } }
public static void cloneRepo(String uri, File cloneTo, String branch) { Git result = null; try { result = Git.cloneRepository().setURI(uri).setDirectory(cloneTo) .setBranch(branch).setBare(false).setRemote(REMOTE_NAME) .setNoCheckout(false).setCloneAllBranches(false).setCloneSubmodules(false).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (result != null) { result.close(); } } }
public static void cloneRepo(String uri, File cloneTo, String branch, GitUser user) { Git result = null; try { result = Git.cloneRepository().setURI(uri).setDirectory(cloneTo) .setBranch(branch).setBare(false).setRemote(REMOTE_NAME) .setNoCheckout(false).setCloneAllBranches(false).setCloneSubmodules(false) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(user.getUsername(), user.getPassword())).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } finally { if (result != null) { result.close(); } } }
@Test public void testRemoteRoot() throws IOException, GitAPIException { final JGitFileSystemProvider fsProvider = mock( JGitFileSystemProvider.class ); final File tempDir = createTempDirectory(); final Git git = Git.cloneRepository().setNoCheckout( false ).setBare( true ).setCloneAllBranches( true ).setURI( setupGit().getRepository().getDirectory().toString() ).setDirectory( tempDir ).call(); final JGitFileSystem fileSystem = new JGitFileSystem( fsProvider, null, git, "my-repo", CredentialsProvider.getDefault() ); assertThat( fileSystem.isReadOnly() ).isFalse(); assertThat( fileSystem.getSeparator() ).isEqualTo( "/" ); assertThat( fileSystem.getName() ).isEqualTo( "my-repo" ); assertThat( fileSystem.getRootDirectories() ).hasSize( 1 ); final Path root = fileSystem.getRootDirectories().iterator().next(); assertThat( root.toString() ).isEqualTo( "/" ); assertThat( root.getRoot().toString() ).isEqualTo( "/" ); }
public boolean cloneRepo() { File localRepo = mRepo.getDir(); CloneCommand cloneCommand = Git.cloneRepository() .setURI(mRepo.getRemoteURL()).setCloneAllBranches(true) .setProgressMonitor(new RepoCloneMonitor()) .setTransportConfigCallback(new SgitTransportCallback())