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 void deleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch) throws IOException { Set<Ref> processed = new HashSet<>(); for (Ref ref : localRefs().values()) { if (ref.isSymbolic()) { continue; } String refname = ref.getName(); for (RefSpec spec : toFetch) { if (spec.matchDestination(refname)) { RefSpec s = spec.expandFromDestination(refname); if (result.getAdvertisedRef(s.getSource()) == null && processed.add(ref)) { deleteTrackingRef(result, batch, s, ref); } } } } }
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; }
head = result.getAdvertisedRef(branch); if (head == null) head = result.getAdvertisedRef(Constants.R_HEADS + branch); if (head == null) head = result.getAdvertisedRef(Constants.R_TAGS + branch);
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; }
public RevCommit gitFetch() throws Exception { FetchResult result = git.fetch().setRemote("origin").call(); System.out.println("Fetch : " + result.getURI().toString()); return revWalk.parseCommit(result.getAdvertisedRef("refs/heads/" + localRepo.getBranch()).getTarget().getObjectId()); }
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; }
Ref r = null; if (fetchRes != null) { r = fetchRes.getAdvertisedRef(remoteBranchName); if (r == null) r = fetchRes.getAdvertisedRef(Constants.R_HEADS + remoteBranchName);
final Ref idHEAD = result.getAdvertisedRef(Constants.HEAD); final List<Ref> availableRefs = new ArrayList<Ref>(); Ref head = null;
private void deleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch) throws IOException { Set<Ref> processed = new HashSet<>(); for (Ref ref : localRefs().values()) { if (ref.isSymbolic()) { continue; } String refname = ref.getName(); for (RefSpec spec : toFetch) { if (spec.matchDestination(refname)) { RefSpec s = spec.expandFromDestination(refname); if (result.getAdvertisedRef(s.getSource()) == null && processed.add(ref)) { deleteTrackingRef(result, batch, s, ref); } } } } }
private void deleteStaleTrackingRefs(FetchResult result, BatchRefUpdate batch) throws IOException { for (final Ref ref : localRefs().values()) { final String refname = ref.getName(); for (final RefSpec spec : toFetch) { if (spec.matchDestination(refname)) { final RefSpec s = spec.expandFromDestination(refname); if (result.getAdvertisedRef(s.getSource()) == null) { deleteTrackingRef(result, batch, s, ref); } } } } }
private RevCommit fetchChange(String uri, RefSpec spec, IProgressMonitor monitor) throws CoreException, URISyntaxException, IOException { int timeout = Activator.getDefault().getPreferenceStore() .getInt(UIPreferences.REMOTE_CONNECTION_TIMEOUT); List<RefSpec> specs = new ArrayList<RefSpec>(1); specs.add(spec); String taskName = NLS .bind(UIText.FetchGerritChangePage_FetchingTaskName, spec.getSource()); monitor.setTaskName(taskName); FetchResult fetchRes = new FetchOperationUI(repository, new URIish(uri), specs, timeout, false).execute(monitor); monitor.worked(1); return new RevWalk(repository).parseCommit(fetchRes.getAdvertisedRef( spec.getSource()).getObjectId()); }
protected void doCheckout(FetchResult fetchResult) throws IOException { final Ref head = fetchResult.getAdvertisedRef(Constants.R_HEADS + watchBranch); final RevWalk rw = new RevWalk(repository); final RevCommit mapCommit; try { LOGGER.debug("Mapping received reference to respective commit."); mapCommit = rw.parseCommit(head.getObjectId()); } finally { rw.release(); } final RefUpdate u; boolean detached = !head.getName().startsWith(Constants.R_HEADS); LOGGER.debug("Updating HEAD reference to revision [{}]", mapCommit.getId().name()); u = repository.updateRef(Constants.HEAD, detached); u.setNewObjectId(mapCommit.getId()); u.forceUpdate(); DirCacheCheckout dirCacheCheckout = new DirCacheCheckout(repository, null, repository.lockDirCache(), mapCommit .getTree()); dirCacheCheckout.setFailOnConflict(true); boolean checkoutResult = dirCacheCheckout.checkout(); LOGGER.debug("Checked out new repository revision to working directory"); if (!checkoutResult) { throw new IOException("Internal error occured on checking out files"); } }
head = result.getAdvertisedRef(branch); if (head == null) head = result.getAdvertisedRef(Constants.R_HEADS + branch); if (head == null) head = result.getAdvertisedRef(Constants.R_TAGS + branch);
head = result.getAdvertisedRef(branch); if (head == null) head = result.getAdvertisedRef(Constants.R_HEADS + branch); if (head == null) head = result.getAdvertisedRef(Constants.R_TAGS + branch);
GitHelpers.checkoutBranch(git, branch); FetchResult fetchResult = git.fetch().setTimeout(gitTimeout).setCredentialsProvider(credentialsProvider).setRemote(remoteRef).setRefSpecs(new RefSpec("refs/heads/" + branch)).call(); Ref fetchRef = fetchResult.getAdvertisedRef("refs/heads/" + branch); git.branchRename().setOldName(branch).setNewName(branch + "-tmp").call(); git.checkout().setCreateBranch(true).setName(branch).setStartPoint(fetchRef.getObjectId().getName()).call();
checkoutRef = guessHEAD(r); else { checkoutRef = r.getAdvertisedRef(Constants.R_HEADS + branch); if (checkoutRef == null) throw die(MessageFormat.format(
GitHelpers.checkoutBranch(git, branch); FetchResult fetchResult = git.fetch().setTimeout(gitTimeout).setCredentialsProvider(credentialsProvider).setRemote(remoteRef).setRefSpecs(new RefSpec("refs/heads/" + branch)).call(); Ref fetchRef = fetchResult.getAdvertisedRef("refs/heads/" + branch); git.branchRename().setOldName(branch).setNewName(branch + "-tmp").call(); git.checkout().setCreateBranch(true).setName(branch).setStartPoint(fetchRef.getObjectId().getName()).call();
.call(); final ObjectId id = fetchResult.getAdvertisedRef(refName).getObjectId(); final RefUpdate refUpdate = git.getRepository().updateRef(refName); refUpdate.setNewObjectId(id);
.call(); final ObjectId id = fetchResult.getAdvertisedRef(refName).getObjectId(); final RefUpdate refUpdate = git.getRepository().updateRef(refName); refUpdate.setNewObjectId(id);