private Ref findBranchToCheckout(FetchResult result) { final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD); ObjectId headId = idHEAD != null ? idHEAD.getObjectId() : null; if (headId == null) { return null; } Ref master = result.getAdvertisedRef(Constants.R_HEADS + Constants.MASTER); ObjectId objectId = master != null ? master.getObjectId() : null; if (headId.equals(objectId)) { return master; } Ref foundBranch = null; for (Ref r : result.getAdvertisedRefs()) { final String n = r.getName(); if (!n.startsWith(Constants.R_HEADS)) continue; if (headId.equals(r.getObjectId())) { foundBranch = r; break; } } return foundBranch; }
@Override public List<Ref> getRemoteBranches(final Git repo) throws GitAPIException { List<Ref> results = new ArrayList<>(); try { FetchResult fetch = repo.fetch().setRemote(GIT_REMOTE_ORIGIN).call(); Collection<Ref> refs = fetch.getAdvertisedRefs(); for (Ref ref : refs) { if (ref.getName().startsWith(GIT_REFS_HEADS)) { results.add(ref); } } } catch (InvalidRemoteException e) { e.printStackTrace(); } return results; }
Ref head = null; for (final Ref r : result.getAdvertisedRefs())
private Collection<Ref> fetch(final Repository repository, final RemoteConfig remoteConfig, final CharSequence repoBranch) { try (Transport transport = Transport.open(repository, remoteConfig)) { configure(transport); transport.setCheckFetchedObjects(false); transport.setRemoveDeletedRefs(false); transport.setDryRun(false); transport.setTagOpt(TagOpt.FETCH_TAGS); transport.setFetchThin(false); final ProgressMonitor monitor = new EmptyProgressMonitor() { }; FetchResult result = transport.fetch(monitor, Arrays.asList( new RefSpec("refs/heads/" + repoBranch) )); logger.debug(String.format("Fetched %s: %s", result.getURI(), result.getMessages())); result.getAdvertisedRefs().stream().forEach(ref -> { logger.debug(String.format("Remote Ref: %s = %s", ref.getName(), ref.getObjectId())); }); return result.getAdvertisedRefs(); } catch (Throwable e) { throw new RuntimeException(e); } }
private static Ref guessHEAD(final FetchResult result) { final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD); Ref head = null; for (final Ref r : result.getAdvertisedRefs()) { final String n = r.getName(); if (!n.startsWith(Constants.R_HEADS)) continue; if (idHEAD == null || head != null) continue; if (r.getObjectId().equals(idHEAD.getObjectId())) head = r; } if (idHEAD != null && head == null) head = idHEAD; return head; }
private Ref findBranchToCheckout(FetchResult result) { final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD); ObjectId headId = idHEAD != null ? idHEAD.getObjectId() : null; if (headId == null) { return null; } Ref master = result.getAdvertisedRef(Constants.R_HEADS + Constants.MASTER); ObjectId objectId = master != null ? master.getObjectId() : null; if (headId.equals(objectId)) { return master; } Ref foundBranch = null; for (Ref r : result.getAdvertisedRefs()) { final String n = r.getName(); if (!n.startsWith(Constants.R_HEADS)) continue; if (headId.equals(r.getObjectId())) { foundBranch = r; break; } } return foundBranch; }
private Ref findBranchToCheckout(FetchResult result) { final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD); ObjectId headId = idHEAD != null ? idHEAD.getObjectId() : null; if (headId == null) { return null; } Ref master = result.getAdvertisedRef(Constants.R_HEADS + Constants.MASTER); ObjectId objectId = master != null ? master.getObjectId() : null; if (headId.equals(objectId)) { return master; } Ref foundBranch = null; for (final Ref r : result.getAdvertisedRefs()) { final String n = r.getName(); if (!n.startsWith(Constants.R_HEADS)) continue; if (headId.equals(r.getObjectId())) { foundBranch = r; break; } } return foundBranch; }
/** * 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"); } } }
Collection<Ref> advertisedRefs = fetchResult.getAdvertisedRefs(); switch (srcVersion.getWellKnownType()) { case branch: