private void pull() throws GitAPIException { Git git = recordGit(Git.wrap(repository)); PullCommand pull = git.pull() .setRebase(true); PullResult result = pull.call(); if (!result.isSuccessful()) { LOGGER.log(Level.WARNING, () -> String.format("Cannot pull from git '%s', branch '%s'", uri.toASCIIString(), branch)); if (LOGGER.isLoggable(Level.FINEST)) { Status status = git.status().call(); LOGGER.finest(() -> "git status cleanliness: " + status.isClean()); if (!status.isClean()) { LOGGER.finest(() -> "git status uncommitted changes: " + status.getUncommittedChanges()); LOGGER.finest(() -> "git status untracked: " + status.getUntracked()); } } } else { LOGGER.fine("Pull was successful."); } LOGGER.finest(() -> "git rebase result: " + result.getRebaseResult().getStatus().name()); LOGGER.finest(() -> "git fetch result: " + result.getFetchResult().getMessages()); }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { System.out.println("Starting fetch"); try (Git git = new Git(repository)) { FetchResult result = git.fetch().setCheckFetchedObjects(true).call(); System.out.println("Messages: " + result.getMessages()); } } } }
public static void main(String[] args) throws IOException, GitAPIException { try (Repository repository = CookbookHelper.openJGitCookbookRepository()) { System.out.println("Starting fetch"); try (Git git = new Git(repository)) { FetchResult result = git.fetch().setCheckFetchedObjects(true).call(); System.out.println("Messages: " + result.getMessages()); } } } }
System.out.println("Messages: " + result.getMessages());
System.out.println("Messages: " + result.getMessages());
/** * Fetch a git repository. * * @param git The git repository. * @param username The username to use for the repository connection. * @param password The password to use for the repository connection. */ public static void fetch(Git git, String username, String password) { try { FetchCommand fetchCommand = git.fetch(); setCredentials(fetchCommand, username, password); FetchResult fetchResult = fetchCommand.call(); log.debug(String.format("Fetched git repository=%s messages=%s", git.getRepository().getDirectory(), fetchResult.getMessages())); } catch (GitAPIException e) { throw new GitException("Unable to fetch git repository", e); } }
@Override public String fetch(String localBranchName, String remoteBranchName) { RefSpec spec = new RefSpec().setSourceDestination(localBranchName, remoteBranchName); FetchCommand command = _git.fetch(); command.setRefSpecs(spec); FetchResult result = null; try { if(_cp != null) command.setCredentialsProvider(_cp); result = command.call(); } catch (Throwable e) { throw new RuntimeException(String.format( "Failed to fetch from [%s] to [%s]", remoteBranchName, localBranchName), e); } return result.getMessages(); }
public boolean updateData() { // git pull SshSessionFactory sshSessionFactory = new JschConfigSessionFactory() { @Override protected void configure(Host host, Session session) { session.setConfig("StrictHostKeyChecking", "no"); } @Override protected JSch createDefaultJSch(FS fs) throws JSchException { JSch defaultJSch = super.createDefaultJSch(fs); defaultJSch.addIdentity(keyfile); return defaultJSch; } }; FetchCommand fetchCommand = git.fetch().setCheckFetchedObjects(true); fetchCommand.setTransportConfigCallback(new TransportConfigCallback() { public void configure(Transport transport) { SshTransport sshTransport = (SshTransport) transport; sshTransport.setSshSessionFactory(sshSessionFactory); } }); try { FetchResult result = fetchCommand.call(); System.out.println("Messages: " + result.getMessages()); } catch (GitAPIException e) { return false; //e.printStackTrace(); } return true; }
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()); }