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()); }
/** * @param parentShell * @param localDb * @param result * @param sourceString */ public FetchResultDialog(final Shell parentShell, final Repository localDb, final FetchResult result, final String sourceString) { super(parentShell); setShellStyle(getShellStyle() & ~SWT.APPLICATION_MODAL | SWT.RESIZE); setBlockOnOpen(false); this.localDb = localDb; this.result = new FetchOperationResult(result.getURI(), result); this.sourceString = sourceString; }
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); } }
protected void showFetchResult(final FetchResult r) throws IOException { ObjectReader reader = db.newObjectReader(); try { boolean shownURI = false; for (final TrackingRefUpdate u : r.getTrackingRefUpdates()) { if (!verbose && u.getResult() == RefUpdate.Result.NO_CHANGE) continue; final char type = shortTypeOf(u.getResult()); final String longType = longTypeOf(reader, u); final String src = abbreviateRef(u.getRemoteName(), false); final String dst = abbreviateRef(u.getLocalName(), true); if (!shownURI) { outw.println(MessageFormat.format(CLIText.get().fromURI, r.getURI())); shownURI = true; } outw.format(" %c %-17s %-10s -> %s", valueOf(type), longType, //$NON-NLS-1$ src, dst); outw.println(); } } finally { reader.release(); } showRemoteMessages(errw, r.getMessages()); }