protected FetchResult fetch(Git git, String label) { FetchCommand fetch = git.fetch(); fetch.setRemote("origin"); fetch.setTagOpt(TagOpt.FETCH_TAGS); fetch.setRemoveDeletedRefs(deleteUntrackedBranches); if (this.refreshRate > 0) { this.setLastRefresh(System.currentTimeMillis()); } configureCommand(fetch); try { FetchResult result = fetch.call(); if (result.getTrackingRefUpdates() != null && result.getTrackingRefUpdates().size() > 0) { logger.info("Fetched for remote " + label + " and found " + result.getTrackingRefUpdates().size() + " updates"); } return result; } catch (Exception ex) { String message = "Could not fetch remote for " + label + " remote: " + git .getRepository().getConfig().getString("remote", "origin", "url"); warn(message, ex); return null; } }
.setRemote(REMOTE_NAME) .setCredentialsProvider(getCredentialsProvider()) .setTransportConfigCallback(buildTransportConfigCallback())
command.setRemote(remote.toString());
/** * 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; }
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() + '/') + '*'; boolean fetchAll = cloneAllBranches || branchesToClone == null || branchesToClone.isEmpty(); config.setFetchRefSpecs(calculateRefSpecs(fetchAll, dst)); config.update(clonedRepo.getConfig()); clonedRepo.getConfig().save(); // run the fetch command FetchCommand command = new FetchCommand(clonedRepo); command.setRemote(remote); command.setProgressMonitor(monitor); command.setTagOpt(fetchAll ? TagOpt.FETCH_TAGS : TagOpt.AUTO_FOLLOW); configure(command); return command.call(); }
JGitText.get().pullTaskName)); FetchCommand fetch = new FetchCommand(repo).setRemote(remote) .setProgressMonitor(monitor).setTagOpt(tagOption) .setRecurseSubmodules(submoduleRecurseMode);
@Override public FetchCommand configure(FetchCommand cmd) { return addAuthentication(cmd).setRemote(remote.getShortRef()); }
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(); }
/** * This method fetches data from the 'upstrem' remote. * * @param gitConfig * @throws GitWorkflowException */ public void fetchRemote(GitConfiguration gitConfig) throws GitWorkflowException { try (Git git = Git.open(new File(botConfig.getBotRefactoringDirectory() + gitConfig.getConfigurationId()))) { // Fetch data git.fetch().setRemote("upstream").call(); } catch (Exception e) { logger.error(e.getMessage(), e); throw new GitWorkflowException("Could not fetch data from 'upstream'!"); } }
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); } } }
protected void doFetchIfNeeded(JGitFlowExtension fetchingExtension) throws GitAPIException, JGitFlowGitAPIException, JGitFlowExtensionException { if (fetch) { runExtensionCommands(fetchingExtension.beforeFetch()); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call(); runExtensionCommands(fetchingExtension.afterFetch()); } }
protected void doFetchIfNeeded(JGitFlowExtension fetchingExtension) throws GitAPIException, JGitFlowGitAPIException, JGitFlowExtensionException { if (fetch) { runExtensionCommands(fetchingExtension.beforeFetch()); git.fetch().setRemote(Constants.DEFAULT_REMOTE_NAME).call(); runExtensionCommands(fetchingExtension.afterFetch()); } }
/** {@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); } }
private void gitUpdateFromOrigin() throws GitAPIException { git.fetch().setRemote("origin").call(); git.reset().setMode(ResetCommand.ResetType.HARD).setRef("origin/master").call(); this.contributors = getContributorsFromRepo(); }
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; }
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() + '/') + '*'; boolean fetchAll = cloneAllBranches || branchesToClone == null || branchesToClone.isEmpty(); config.setFetchRefSpecs(calculateRefSpecs(fetchAll, dst)); config.update(clonedRepo.getConfig()); clonedRepo.getConfig().save(); // run the fetch command FetchCommand command = new FetchCommand(clonedRepo); command.setRemote(remote); command.setProgressMonitor(monitor); command.setTagOpt(fetchAll ? TagOpt.FETCH_TAGS : TagOpt.AUTO_FOLLOW); configure(command); return command.call(); }
@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; }
@Override public void switchToVersion(String version) throws Exception { try (Git git = new Git(repository)) { if (version == null) { version = REMOTE_BRANCH; // TODO fetch git.fetch().setRemote(REMOTE).call(); } Log.logDebug(LOGGER, "GIT switchToVersion {0} ", version); git.reset().setMode(ResetType.HARD).call(); git.checkout().setName(version).call(); git.branchDelete().setForce(true).setBranchNames(LOCAL_BRANCH).call(); git.checkout().setCreateBranch(true).setName(LOCAL_BRANCH).setStartPoint(version).call(); } catch (TransportException e) { throw new NetworkException(e); } }