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; } }
command.setTagOpt(TagOpt.valueOf(tagOpt.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(); }
.setProgressMonitor(monitor).setTagOpt(tagOption) .setRecurseSubmodules(submoduleRecurseMode); configure(fetch);
FetchCommand f = new FetchCommand(submoduleRepo) .setProgressMonitor(monitor) .setTagOpt(tagOption) .setCheckFetchedObjects(checkFetchedObjects) .setRemoveDeletedRefs(isRemoveDeletedRefs())
public void fetchRemotes() throws Exception { git.fetch().setTagOpt(TagOpt.FETCH_TAGS).setCheckFetchedObjects(false).setRemoveDeletedRefs(true).call(); }
public boolean tag(String tagname, String comment) throws Exception { try{ git.fetch().setTagOpt(TagOpt.FETCH_TAGS).call(); } catch(Exception e) { log.debug("Fetch from origin failed.", e); } List<RevTag> tags = git.tagList().call(); if(tags != null && tags.size() > 0) { for(RevTag tag : tags) { if(tag.getTagName().equals(tagname)) { throw new Exception("Tag already exists."); } } } boolean success = git.tag().setMessage(comment).setName(tagname).call() != null; try{ git.push().setPushTags().call(); } catch(Exception e){ log.debug("Failed to push changes.", e); } return success; }
/** {@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 public void execute() throws GitException, InterruptedException { try (Repository repo = getRepository()) { Git git = git(repo); List<RefSpec> allRefSpecs = new ArrayList<>(); if (refspecs != null) for (RefSpec rs: refspecs) if (rs != null) allRefSpecs.add(rs); FetchCommand fetch = git.fetch(); fetch.setTagOpt(tags ? TagOpt.FETCH_TAGS : TagOpt.NO_TAGS); /* JGit 4.5 required a work around that the tags refspec had to be passed in addition to setting * the FETCH_TAGS tagOpt. JGit 4.9.0 fixed that bug. * However, JGit 4.9 and later will not accept an empty refspec. * If the refspec is empty and tag fetch is requested, must add the tags refspec to fetch. */ if (allRefSpecs.isEmpty() && tags) { allRefSpecs.add(new RefSpec("+refs/tags/*:refs/tags/*")); } fetch.setRemote(url.toString()); fetch.setCredentialsProvider(getProvider()); fetch.setRefSpecs(allRefSpecs); fetch.setRemoveDeletedRefs(shouldPrune); 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 FetchResult fetch(Git git, String branch) { FetchCommand fetch = git.fetch(); fetch.setRemote("origin"); fetch.setTagOpt(TagOpt.FETCH_TAGS); setTimeout(fetch); try { setCredentialsProvider(fetch); FetchResult result = fetch.call(); if (result.getTrackingRefUpdates() != null && result.getTrackingRefUpdates().size() > 0) { logger.info("Fetched for remote " + branch + " and found " + result.getTrackingRefUpdates().size() + " updates"); } return result; } catch (Exception ex) { String message = "Could not fetch remote for " + branch + " remote: " + git.getRepository().getConfig() .getString("remote", "origin", "url"); warn(message, ex); return null; } }
.setRefSpecs(new RefSpec(REF_SPEC)) .setRemote(url.toExternalForm()) .setTagOpt(TagOpt.FETCH_TAGS) .call();
@Override public Git cloneRepository(Git git, boolean fetchAndCheckout) throws GitAPIException, IOException { File tmpLocation = new File(tmpPatchManagement, TS.format(new Date())); Git fork = Git.init().setBare(false) .setGitDir(new File(tmpLocation, Constants.DOT_GIT)) .setDirectory(tmpLocation).call(); StoredConfig config = fork.getRepository().getConfig(); config.setString("remote", "origin", "url", git.getRepository().getDirectory().getCanonicalPath()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); if (fetchAndCheckout) { fork.fetch() .setRemote("origin") .setTagOpt(TagOpt.FETCH_TAGS) .call(); fork.checkout() .setCreateBranch(true) .setName(getMainBranchName()) .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) .setStartPoint("origin/" + getMainBranchName()) .call(); } return fork; }
/** * Fetches all refs from "fabric git repo" to "patch git repo" - very important operation that keeps * both repositories synchronized. * @param mainRepository * @throws GitAPIException */ private void fetchFabricPatchData(Git mainRepository) throws GitAPIException { if (mainRepository.getRepository().getConfig() != null) { String url = mainRepository.getRepository().getConfig().getString("remote", "origin", "url"); if (url != null) { Activator.log(LogService.LOG_INFO, "Fetching data from " + url); // let's fetch from origin to check if someone else already does fabric patch management FetchResult result = mainRepository.fetch() .setRemote("origin") .setRefSpecs(new RefSpec("+refs/heads/*:refs/remotes/origin/*")) .setTagOpt(TagOpt.FETCH_TAGS) .call(); Set<String> tags = new TreeSet<>(); for (Ref ref : result.getAdvertisedRefs()) { if (ref.getName().startsWith("refs/tags/baseline")) { tags.add(ref.getName().substring("refs/tags/".length())); } } Activator.log(LogService.LOG_INFO, "Available tags: " + tags); } else { Activator.log(LogService.LOG_WARNING, "Repository " + mainRepository.getRepository().getWorkTree() + " is not connected with Fabric git repository"); } } }
/** * Fetches all refs from "fabric git repo" to "patch git repo" - very important operation that keeps * both repositories synchronized. * @param mainRepository * @throws GitAPIException */ private void fetchFabricPatchData(Git mainRepository) throws GitAPIException { if (mainRepository.getRepository().getConfig() != null) { String url = mainRepository.getRepository().getConfig().getString("remote", "origin", "url"); if (url != null) { Activator.log(LogService.LOG_INFO, "Fetching data from " + url); // let's fetch from origin to check if someone else already does fabric patch management FetchResult result = mainRepository.fetch() .setRemote("origin") .setRefSpecs(new RefSpec("+refs/heads/*:refs/remotes/origin/*")) .setTagOpt(TagOpt.FETCH_TAGS) .call(); Set<String> tags = new TreeSet<>(); for (Ref ref : result.getAdvertisedRefs()) { if (ref.getName().startsWith("refs/tags/baseline")) { tags.add(ref.getName().substring("refs/tags/".length())); } } Activator.log(LogService.LOG_INFO, "Available tags: " + tags); } else { Activator.log(LogService.LOG_WARNING, "Repository " + mainRepository.getRepository().getWorkTree() + " is not connected with Fabric git repository"); } } }
@Override public Git cloneRepository(Git git, boolean fetchAndCheckout) throws GitAPIException, IOException { File tmpLocation = new File(tmpPatchManagement, TS.format(new Date())); Git fork = Git.init().setBare(false) .setGitDir(new File(tmpLocation, Constants.DOT_GIT)) .setDirectory(tmpLocation).call(); StoredConfig config = fork.getRepository().getConfig(); config.setString("remote", "origin", "url", git.getRepository().getDirectory().getCanonicalPath()); config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*"); config.save(); if (fetchAndCheckout) { fork.fetch() .setRemote("origin") .setTagOpt(TagOpt.FETCH_TAGS) .call(); fork.checkout() .setCreateBranch(true) .setName(getMainBranchName()) .setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) .setStartPoint("origin/" + getMainBranchName()) .call(); } return fork; }
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(); }
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(); }
FetchCommand f = new FetchCommand(submoduleRepo) .setProgressMonitor(monitor) .setTagOpt(tagOption) .setCheckFetchedObjects(checkFetchedObjects) .setRemoveDeletedRefs(isRemoveDeletedRefs())