.setBranchesToClone(singleton("refs/heads/" + branch)) .setBranch("refs/heads/" + branch) .setDirectory(directory.toFile()); Git cloneResult = recordGit(cloneCommand.call()); LOGGER.log(Level.CONFIG, () -> String.format("git clone result: %s", cloneResult.toString()));
private Git cloneToBasedir() throws GitAPIException { CloneCommand clone = this.gitFactory.getCloneCommandByCloneRepository() .setURI(getUri()).setDirectory(getBasedir()); configureCommand(clone); try { return clone.call(); } catch (GitAPIException e) { logger.warn("Error occured cloning to base directory.", e); deleteBaseDirIfExists(); throw e; } }
fileKey.open(false).create(true); this.gitForPush = Git.cloneRepository().setURI(GIT_REMOTE_REPO_DIR).setDirectory(new File(GIT_CLONE_DIR)).call();
.setDirectory(repoDirFile) .setURI(this.repoUri) .setBranch(this.branchName)
this.remoteRepo.create(true); this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();
remoteRepo.create(true); Git gitForPush = Git.cloneRepository().setURI(remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call();
@BeforeClass public void setup() throws Exception { cleanUpDir(TEST_DIR); // Create a bare repository RepositoryCache.FileKey fileKey = RepositoryCache.FileKey.exact(remoteDir, FS.DETECTED); this.remoteRepo = fileKey.open(false); this.remoteRepo.create(true); this.gitForPush = Git.cloneRepository().setURI(this.remoteRepo.getDirectory().getAbsolutePath()).setDirectory(cloneDir).call(); // push an empty commit as a base for detecting changes this.gitForPush.commit().setMessage("First commit").call(); this.gitForPush.push().setRemote("origin").setRefSpecs(this.masterRefSpec).call(); this.config = ConfigBuilder.create() .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_URI, this.remoteRepo.getDirectory().getAbsolutePath()) .addPrimitive(GitConfigMonitor.GIT_CONFIG_MONITOR_PREFIX + "." + ConfigurationKeys.GIT_MONITOR_REPO_DIR, TEST_DIR + "/jobConfig") .addPrimitive(ConfigurationKeys.FLOWSPEC_STORE_DIR_KEY, TEST_DIR + "flowCatalog") .addPrimitive(ConfigurationKeys.GIT_MONITOR_POLLING_INTERVAL, 5) .build(); this.flowCatalog = new FlowCatalog(config); this.flowCatalog.startAsync().awaitRunning(); this.gitConfigMonitor = new GitConfigMonitor(this.config, this.flowCatalog); this.gitConfigMonitor.setActive(true); }
private static Repository cloneRepository() throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! return result.getRepository(); } } }
private static Repository cloneRepository() throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! return result.getRepository(); } } }
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! System.out.println("Having repository: " + result.getRepository().getDirectory()); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! System.out.println("Having repository: " + result.getRepository().getDirectory()); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
/** * Clone code to folder * * @param gitUrl * @param targetDir * @return * @throws GitException */ public static Path clone(String gitUrl, Path targetDir) throws GitException { CloneCommand cloneCommand = Git.cloneRepository() .setURI(gitUrl) .setDirectory(targetDir.toFile()); try (Git ignored = cloneCommand.call()) { return targetDir; } catch (GitAPIException e) { throw new GitException("Fail to clone git repo", e); } }
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! System.out.println("Having repository: " + result.getRepository().getDirectory()); try (Git git = new Git(result.getRepository())) { git.pull() .call(); } System.out.println("Pulled from remote repository to local repository at " + result.getRepository().getDirectory()); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
public static void main(String[] args) throws IOException, GitAPIException { // prepare a new folder for the cloned repository File localPath = File.createTempFile("TestGitRepository", ""); if(!localPath.delete()) { throw new IOException("Could not delete temporary file " + localPath); } // then clone System.out.println("Cloning from " + REMOTE_URL + " to " + localPath); try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { // Note: the call() returns an opened repository already which needs to be closed to avoid file handle leaks! System.out.println("Having repository: " + result.getRepository().getDirectory()); try (Git git = new Git(result.getRepository())) { git.pull() .call(); } System.out.println("Pulled from remote repository to local repository at " + result.getRepository().getDirectory()); } // clean up here to not keep using more and more disk-space for these samples FileUtils.deleteDirectory(localPath); } }
try (Git git = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) {
try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { System.out.println("Result: " + result);
try (Git result = Git.cloneRepository() .setURI(REMOTE_URL) .setDirectory(localPath) .call()) { System.out.println("Result: " + result);
@Override public File clone(String branch, boolean noCheckout) throws GitException { checkGitUrl(); CloneCommand cloneCommand = Git.cloneRepository() .setURI(gitUrl) .setNoCheckout(noCheckout) .setBranch(branch) .setDirectory(targetDir.toFile()); try (Git git = buildCommand(cloneCommand).call()) { return git.getRepository().getDirectory(); } catch (GitAPIException e) { throw new GitException("Fail to clone git repo", e); } }
configure(clone); clone.setURI(url); clone.setDirectory(generator.getDirectory()); clone.setGitDir( new File(new File(repo.getDirectory(), Constants.MODULES),
@Override public RemoteFile readFileWithMode(String uri, String ref, String path) throws GitAPIException, IOException { File dir = FileUtils.createTempDir("jgit_", ".git", null); //$NON-NLS-1$ //$NON-NLS-2$ try (Git git = Git.cloneRepository().setBare(true).setDirectory(dir) .setURI(uri).call()) { Repository repo = git.getRepository(); ObjectId refCommitId = sha1(uri, ref); if (refCommitId == null) { throw new InvalidRefNameException(MessageFormat .format(JGitText.get().refNotResolved, ref)); } RevCommit commit = repo.parseCommit(refCommitId); TreeWalk tw = TreeWalk.forPath(repo, path, commit.getTree()); // TODO(ifrade): Cope better with big files (e.g. using // InputStream instead of byte[]) return new RemoteFile( tw.getObjectReader().open(tw.getObjectId(0)) .getCachedBytes(Integer.MAX_VALUE), tw.getFileMode(0)); } finally { FileUtils.delete(dir, FileUtils.RECURSIVE); } } }