/** * The ref specs to be used in the fetch operation * * @param specs * one or multiple {@link org.eclipse.jgit.transport.RefSpec}s * @return {@code this} */ public FetchCommand setRefSpecs(RefSpec... specs) { return setRefSpecs(Arrays.asList(specs)); }
/** * The ref specs to be used in the fetch operation * * @param specs * String representation of {@code RefSpec}s * @return {@code this} * @since 4.9 */ public FetchCommand setRefSpecs(String... specs) { return setRefSpecs( Arrays.stream(specs).map(RefSpec::new).collect(toList())); }
/** * fetch tags from remote * @param path * @param remoteName * @return * @throws GitException */ public static Path fetchTags(Path path, String remoteName) throws GitException { try (Git git = Git.open(path.toFile())) { git.fetch() .setRemote(remoteName) .setRefSpecs(new RefSpec("refs/tags/*:refs/tags/*")) .setTagOpt(TagOpt.FETCH_TAGS) .call(); } catch (Throwable throwable) { throw new GitException("fetch tags error", throwable); } return path; }
/** * The ref specs to be used in the fetch operation * * @param specs * one or multiple {@link org.eclipse.jgit.transport.RefSpec}s * @return {@code this} */ public FetchCommand setRefSpecs(RefSpec... specs) { return setRefSpecs(Arrays.asList(specs)); }
/** * The ref specs to be used in the fetch operation * * @param specs * String representation of {@code RefSpec}s * @return {@code this} * @since 4.9 */ public FetchCommand setRefSpecs(String... specs) { return setRefSpecs( Arrays.stream(specs).map(RefSpec::new).collect(toList())); }
public static void fetchRepository( final Git git, final CredentialsProvider credentialsProvider, final RefSpec... refSpecs ) throws InvalidRemoteException { final List<RefSpec> specs = new ArrayList<RefSpec>(); if ( refSpecs == null || refSpecs.length == 0 ) { specs.add( new RefSpec( "+refs/heads/*:refs/remotes/origin/*" ) ); specs.add( new RefSpec( "+refs/tags/*:refs/tags/*" ) ); specs.add( new RefSpec( "+refs/notes/*:refs/notes/*" ) ); } else { specs.addAll( Arrays.asList( refSpecs ) ); } try { git.fetch() .setCredentialsProvider( credentialsProvider ) .setRefSpecs( specs ) .call(); } catch ( final InvalidRemoteException e ) { throw e; } catch ( final Exception ex ) { throw new RuntimeException( ex ); } }
.setRemoveDeletedRefs(isRemoveDeletedRefs()) .setThin(thin) .setRefSpecs(applyOptions(refSpecs)) .setDryRun(dryRun) .setRecurseSubmodules(recurseMode);
public static void fetchRepository(final Git git, final CredentialsProvider credentialsProvider, final RefSpec... refSpecs) { final List<RefSpec> specs = new ArrayList<RefSpec>(); if (refSpecs == null || refSpecs.length == 0) { specs.add(new RefSpec("+refs/heads/*:refs/remotes/origin/*")); specs.add(new RefSpec("+refs/tags/*:refs/tags/*")); specs.add(new RefSpec("+refs/notes/*:refs/notes/*")); } else { specs.addAll(Arrays.asList(refSpecs)); } try { git.fetch() .setCredentialsProvider(credentialsProvider) .setRefSpecs(specs) .call(); } catch (final Exception ex) { throw new RuntimeException(ex); } }
private void fetch(String branchName) throws GitAPIException { logger.info("Fetching branch " + branchName); if (!branchName.startsWith(REFS_REMOTES)) { throw new IllegalArgumentException("Branch name '" + branchName + "' is not tracking branch name since it does not start " + REFS_REMOTES); } String remoteName = extractRemoteName(branchName); String shortName = extractShortName(remoteName, branchName); git.fetch().setRemote(remoteName).setRefSpecs(new RefSpec(REFS_HEADS + shortName + ":" + branchName)).call(); }
@Override public String fetch(String localBranchName, String remoteBranchName) { RefSpec spec = new RefSpec().setSourceDestination(localBranchName, remoteBranchName); FetchCommand command = _git.fetch(); command.setRefSpecs(spec); FetchResult result = null; try { if(_cp != null) command.setCredentialsProvider(_cp); result = command.call(); } catch (Throwable e) { throw new RuntimeException(String.format( "Failed to fetch from [%s] to [%s]", remoteBranchName, localBranchName), e); } return result.getMessages(); }
public void execute() throws InvalidRemoteException { try { final List<RefSpec> specs = git.updateRemoteConfig(remote, refSpecs); git._fetch() .setCredentialsProvider(credentialsProvider) .setRemote(remote.getK1()) .setRefSpecs(specs) .call(); } catch (final InvalidRemoteException e) { throw e; } catch (final Exception ex) { throw new RuntimeException(ex); } } }
/** {@inheritDoc} */ @Override public void fetch(String remoteName, RefSpec... refspec) throws GitException { try (Repository repo = getRepository()) { FetchCommand fetch = git(repo).fetch().setTagOpt(TagOpt.FETCH_TAGS); if (remoteName != null) fetch.setRemote(remoteName); fetch.setCredentialsProvider(getProvider()); List<RefSpec> refSpecs = new ArrayList<>(); if (refspec != null && refspec.length > 0) for (RefSpec rs: refspec) if (rs != null) refSpecs.add(rs); fetch.setRefSpecs(refSpecs); fetch.call(); } catch (GitAPIException e) { throw new GitException(e); } }
@Override protected void run() throws Exception { Git git = new Git(db); FetchCommand fetch = git.fetch(); if (fsck != null) fetch.setCheckFetchedObjects(fsck.booleanValue()); if (prune != null) fetch.setRemoveDeletedRefs(prune.booleanValue()); if (toget != null) fetch.setRefSpecs(toget); if (tags != null) { fetch.setTagOpt(tags.booleanValue() ? TagOpt.FETCH_TAGS : TagOpt.NO_TAGS); } if (0 <= timeout) fetch.setTimeout(timeout); fetch.setDryRun(dryRun); fetch.setRemote(remote); if (thin != null) fetch.setThin(thin.booleanValue()); if (quiet == null || !quiet.booleanValue()) fetch.setProgressMonitor(new TextProgressMonitor()); FetchResult result = fetch.call(); if (result.getTrackingRefUpdates().isEmpty()) return; showFetchResult(result); } }
private static void loadGitRepositoryData() throws Exception { try (Git git = Git.open(new File("../.."))) { // the tests expect a series of remote branches and tags from origin, so if they're not present in the clone // where the test is running, we need to load them... List<RefSpec> refsToFetch = new ArrayList<>(); List<String> tagNames = git.tagList().call().stream() .map(ref -> ref.getName().replace("refs/tags/", "")) .collect(Collectors.toList()); Arrays.stream(expectedTagNames()) .filter(tagName -> !tagNames.contains(tagName)) .map(tagName -> new RefSpec("+refs/tags/" + tagName + ":refs/remotes/origin/" + tagName)) .forEach(refsToFetch::add); List<String> branchNames = git.branchList().setListMode(ListBranchCommand.ListMode.ALL).call() .stream() .map(ref -> ref.getName() .replace("refs/heads/", "") .replace("refs/remotes/origin/", "")) .collect(Collectors.toList()); Arrays.stream(expectedRemoteBranchNames()) .filter(branchName -> !branchNames.contains(branchName)) .map(branchName -> new RefSpec("+refs/heads/" + branchName + ":refs/remotes/origin/" + branchName)) .forEach(refsToFetch::add); if (!refsToFetch.isEmpty()) { // next fetch all the remote refs which we need for the test git.fetch().setRefSpecs(refsToFetch).call(); } } }
public Ref fetchNotesRef(Git git) throws IOException, GitAPIException { Ref ref = git.getRepository().findRef(GIT_NOTES_REF); if (areNotesInRemote(git)) { git.fetch().setRemote("origin") .setDryRun(false) .setRefSpecs(new RefSpec(GIT_NOTES_REF + ":" + GIT_NOTES_REF)) .call(); } return ref; }
private void fetch() throws GitAPIException { for (SubtreeConfig config : subtreeConfigs) { RefSpec branchesSpec = new RefSpec( "refs/heads/*:refs/heads/original/" + config.getRemoteName() + "/*"); RefSpec tagsSpec = new RefSpec("refs/tags/*:refs/tags/original/" + config.getRemoteName() + "/*"); Git git = new Git(repository); git.fetch().setRemote(config.getFetchUri().toPrivateString()) .setRefSpecs(branchesSpec, tagsSpec).call(); } }
@Override protected Git getGitRepo() throws Exception { if (stagingDirectory.exists() && new File(stagingDirectory, "HEAD").exists()) { Git git = Git.open(stagingDirectory); git.fetch().setRemote(getRemoteUrl(null, null)).setProgressMonitor(new TextProgressMonitor()).setRefSpecs(new RefSpec("refs/heads/master")).call(); } else { Git.cloneRepository() .setURI(getRemoteUrl(null, null)) .setProgressMonitor(new TextProgressMonitor()) .setDirectory(stagingDirectory) .setNoCheckout(true) .setBare(true) .call(); } Repository r = null; RepositoryBuilder b = new RepositoryBuilder().setGitDir(stagingDirectory).setWorkTree(sourceDirectory); r = b.build(); final Git git = Git.wrap(r); return git; }
/** * Fetches review and comment git notes and updates the local refs, performing * merges if necessary. */ public void syncCommentsAndReviews() throws GitClientException { RevWalk revWalk = null; try (Git git = new Git(repo)) { revWalk = new RevWalk(repo); // Fetch the latest. RefSpec spec = new RefSpec(DEVTOOLS_PULL_REFSPEC); git.fetch().setRefSpecs(spec).call(); syncNotes(revWalk, COMMENTS_REF, COMMENTS_ORIGIN_REF); revWalk.reset(); syncNotes(revWalk, REVIEWS_REF, REVIEWS_ORIGIN_REF); } catch (Exception e) { throw new GitClientException("Error syncing notes", e); } finally { if (revWalk != null) { revWalk.close(); } } }
@Override public FetchResult fetch(final Git git, final String remote, final String refSpec, final int timeout, final boolean fsck, final boolean dryRun, final boolean thin, final boolean prune) throws GitAPIException { FetchCommand fetch = git.fetch(); fetch.setCheckFetchedObjects(fsck); fetch.setRemoveDeletedRefs(prune); if (refSpec != null) fetch.setRefSpecs(new RefSpec(refSpec)); if (timeout >= 0) fetch.setTimeout(timeout); fetch.setDryRun(dryRun); fetch.setRemote(remote); fetch.setThin(thin); fetch.setProgressMonitor(new TextProgressMonitor()); FetchResult result = fetch.call(); return result; }
private FetchResult fetch(Repository clonedRepo, URIish u) throws URISyntaxException, org.eclipse.jgit.api.errors.TransportException, IOException, GitAPIException { // create the remote config and save it RemoteConfig config = new RemoteConfig(clonedRepo.getConfig(), remote); config.addURI(u); final String dst = (bare ? Constants.R_HEADS : Constants.R_REMOTES + config.getName() + "/") + "*"; //$NON-NLS-1$//$NON-NLS-2$ RefSpec refSpec = new RefSpec(); refSpec = refSpec.setForceUpdate(true); refSpec = refSpec.setSourceDestination(Constants.R_HEADS + "*", dst); //$NON-NLS-1$ config.addFetchRefSpec(refSpec); config.update(clonedRepo.getConfig()); clonedRepo.getConfig().save(); // run the fetch command FetchCommand command = new FetchCommand(clonedRepo); command.setRemote(remote); command.setProgressMonitor(monitor); command.setTagOpt(TagOpt.FETCH_TAGS); configure(command); List<RefSpec> specs = calculateRefSpecs(dst); command.setRefSpecs(specs); return command.call(); }