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.setCheckFetchedObjects(settings.valueOfIndex("checkFetchedObjects").toBoolean()); command.setDryRun(settings.valueOfIndex("dryRun").toBoolean()); command.setRemoveDeletedRefs(settings.valueOfIndex("removeDeletedRefs").toBoolean()); command.setThin(settings.valueOfIndex("thin").toBoolean());
.setTagOpt(tagOption) .setCheckFetchedObjects(checkFetchedObjects) .setRemoveDeletedRefs(isRemoveDeletedRefs()) .setThin(thin) .setRefSpecs(applyOptions(refSpecs))
public boolean newRemoteBranch(String branchName) throws Exception { try{ log.info("Purging branches that no longer have remotes."); git.fetch().setRemoveDeletedRefs(true).call(); } catch(Exception e) { log.warn("Tried to fetch from remote when there is no remote."); return false; } boolean branchExists = checkForRemoteBranch(branchName); if(!branchExists) { Ref ref = newLocalBranch(branchName); git.push().add(ref).call(); return true; } else { log.info(branchName + " already exists."); } return false; }
public boolean newEmtpyRemoteBranch(String branchName) throws Exception { try{ log.info("Purging branches that no longer have remotes."); git.fetch().setRemoveDeletedRefs(true).call(); } catch(Exception e) { log.warn("Tried to fetch from remote when there is no remote."); return false; } boolean branchExists = checkForRemoteBranch(branchName); if(!branchExists) { Ref ref = newEmptyLocalBranch(branchName); git.push().add(ref).call(); return true; } else { log.info(branchName + " already exists."); } return false; }
public void fetchRemotes() throws Exception { git.fetch().setTagOpt(TagOpt.FETCH_TAGS).setCheckFetchedObjects(false).setRemoveDeletedRefs(true).call(); }
@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); } }
final FetchResult fetchResult = fetch.setRefSpecs(new RefSpec(refName)) .setCheckFetchedObjects(true) .setRemoveDeletedRefs(true) .setTagOpt(TagOpt.NO_TAGS) .setTimeout(GIT_TIMEOUT_SECS)
final FetchResult fetchResult = fetch.setRefSpecs(new RefSpec(refName)) .setCheckFetchedObjects(true) .setRemoveDeletedRefs(true) .setTagOpt(TagOpt.NO_TAGS) .setTimeout(GIT_TIMEOUT_SECS)
@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; }
final FetchResult fetchResult = fetch.setRefSpecs(new RefSpec(refName)) .setCheckFetchedObjects(true) .setRemoveDeletedRefs(true) .setTagOpt(TagOpt.NO_TAGS) .setTimeout(GIT_TIMEOUT_SECS)
.setTagOpt(tagOption) .setCheckFetchedObjects(checkFetchedObjects) .setRemoveDeletedRefs(isRemoveDeletedRefs()) .setThin(thin) .setRefSpecs(applyOptions(refSpecs))