List of usage examples for org.eclipse.jgit.api PullResult getFetchResult
public FetchResult getFetchResult()
From source file:com.chungkwong.jgitgui.RemoteTreeItem.java
License:Open Source License
private void gitPull() { ProgressDialog progressDialog = new ProgressDialog( java.util.ResourceBundle.getBundle("com/chungkwong/jgitgui/text").getString("PULLING")); PullCommand command = ((Git) getParent().getValue()).pull().setRemote(((RemoteConfig) getValue()).getName()) .setProgressMonitor(progressDialog); new Thread(() -> { try {// w w w . j av a 2 s .c om PullResult result = command.call(); HashSet<CommitTreeItem> commits = new HashSet<>(); Platform.runLater(() -> { if (result.getFetchResult() != null) { for (Ref ref : result.getFetchResult().getAdvertisedRefs()) try { commits.add(new CommitTreeItem(((Git) getParent().getValue()).log() .addRange(ref.getObjectId(), ref.getObjectId()).call().iterator().next())); } catch (Exception ex) { Logger.getLogger(RemoteTreeItem.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } } if (result.getMergeResult() != null && result.getMergeResult().getMergeStatus().equals(MergeResult.MergeStatus.MERGED)) { try { ObjectId head = result.getMergeResult().getNewHead(); commits.add(new CommitTreeItem(((Git) getParent().getValue()).log().addRange(head, head) .call().iterator().next())); } catch (Exception ex) { Logger.getLogger(RemoteTreeItem.class.getName()).log(Level.SEVERE, null, ex); Util.informUser(ex); } } else { new Alert(Alert.AlertType.INFORMATION, result.toString(), ButtonType.CLOSE).show(); } getParent().getChildren().filtered(item -> item instanceof LocalTreeItem) .forEach((item) -> item.getChildren().addAll(commits)); }); } catch (Exception ex) { Logger.getLogger(GitTreeItem.class.getName()).log(Level.SEVERE, null, ex); Platform.runLater(() -> { progressDialog.hide(); Util.informUser(ex); }); } }).start(); }
From source file:com.rimerosolutions.ant.git.tasks.PullTask.java
License:Apache License
@Override public void doExecute() { try {// ww w .j a va2s. c om PullCommand pullCommand = git.pull().setRebase(rebase); if (getProgressMonitor() != null) { pullCommand.setProgressMonitor(getProgressMonitor()); } setupCredentials(pullCommand); PullResult pullResult = pullCommand.call(); if (!pullResult.isSuccessful()) { FetchResult fetchResult = pullResult.getFetchResult(); GitTaskUtils.validateTrackingRefUpdates(MESSAGE_PULLED_FAILED, fetchResult.getTrackingRefUpdates()); MergeStatus mergeStatus = pullResult.getMergeResult().getMergeStatus(); if (!mergeStatus.isSuccessful()) { throw new BuildException(String.format(MESSAGE_PULLED_FAILED_WITH_STATUS, mergeStatus.name())); } } } catch (Exception e) { throw new GitBuildException(String.format(MESSAGE_PULLED_FAILED_WITH_URI, getUri()), e); } }
From source file:eu.cloud4soa.cli.roo.addon.commands.GitManager.java
License:Apache License
public void pull() throws GitAPIException, IOException { pullCommand = git.pull();//from w w w.j a va 2s . c o m logger.info("Performing the git pull/merge command"); PullResult pullResult = pullCommand.call(); logger.info("Fetched From: " + pullResult.getFetchedFrom()); logger.info("Fetch Result: " + pullResult.getFetchResult().getMessages()); logger.info("Merge Result:" + pullResult.getMergeResult()); logger.info("Rebase Result:" + pullResult.getRebaseResult()); logger.info(pullResult.isSuccessful() ? "Pull/Merge success" : "Failed to Pull/Merge"); }
From source file:git_manager.tool.GitOperations.java
License:Open Source License
public void pullFromRemote() { if (!getRemote()) { System.out.println("Pull cancelled."); return;/*from w w w. j a v a 2 s . c om*/ } storeRemote(); storeMergeBranch(); PullResult result; try { result = git.pull().call(); FetchResult fetchResult = result.getFetchResult(); MergeResult mergeResult = result.getMergeResult(); // TODO: Handle merge conflicts :O // TODO: Handle NoHeadException (repo not initialized) // TODO: Handle InvalidConfigurationException (no pushes made till now- // configure remote manually) System.out.println(mergeResult.getMergeStatus()); // System.out.println("fetch status: " + fetchResult.getMessages()); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { // System.out // .println("Please use a project of size <1MB when pushing (will be resolved soon)..."); e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } }
From source file:net.mobid.codetraq.runnables.GitChecker.java
License:Open Source License
private void pull(String path) { LogService.writeMessage("GitChecker is trying to do a pull from " + _server.getServerAddress()); //System.out.printf("GitChecker is trying to do a pull from %s%n", _server.getServerAddress()); try {// ww w . ja v a2 s . com File gitDir = new File(path); repo = new FileRepository(gitDir); if (mGit == null) { mGit = new Git(repo); } if (mGit.getRepository().getFullBranch() == null || Utilities.isHexString(mGit.getRepository().getFullBranch())) { attachHead(mGit, _server.getServerBranch()); } PullCommand puller = mGit.pull(); puller.setTimeout(60); puller.setProgressMonitor(new TextProgressMonitor()); PullResult pullResult = puller.call(); if (pullResult != null) { LogService.writeMessage("GitChecker has something to pull from " + _server.getServerAddress()); FetchResult result = pullResult.getFetchResult(); if (result.getTrackingRefUpdates().isEmpty()) { return; } showFetchResult(result, true); } else { LogService.writeMessage( "GitChecker did not find anything to pull from " + _server.getServerAddress()); } } catch (Exception ex) { LogService.getLogger(GitChecker.class.getName()).log(Level.SEVERE, null, ex); LogService.writeLog(Level.SEVERE, ex); } }
From source file:org.apache.stratos.cartridge.agent.artifact.deployment.synchronizer.git.impl.GitBasedArtifactRepository.java
License:Apache License
/** * Pulling if any updates are available in the remote git repository. If basic authentication is required, * will call 'RepositoryInformationService' for credentials. * * @param gitRepoCtx RepositoryContext instance for tenant * @return true if success, else false//from w ww.ja v a 2s . co m */ /*private boolean pullArtifacts(RepositoryContext gitRepoCtx) { if (log.isDebugEnabled()) { log.debug("Pulling artifacts"); } PullCommand pullCmd = gitRepoCtx.getGit().pull(); if (!gitRepoCtx.getKeyBasedAuthentication()) { UsernamePasswordCredentialsProvider credentialsProvider = createCredentialsProvider(gitRepoCtx); if (credentialsProvider != null) pullCmd.setCredentialsProvider(credentialsProvider); } try { PullResult pullResult = pullCmd.call(); // check if we have received any updates if (!pullResult.getFetchResult().getTrackingRefUpdates().isEmpty()) { if (log.isDebugEnabled()) { log.debug("Artifacts were updated as a result of the pull operation, thread: " + Thread.currentThread().getName() + " - " + Thread.currentThread().getId()); } // execute artifact update extension extensionHandler.onArtifactUpdateSchedulerEvent(String.valueOf(gitRepoCtx.getTenantId())); } } catch (InvalidConfigurationException e) { log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", " + e.getMessage()); //handleInvalidConfigurationError(gitRepoCtx); //return false; Utilities.deleteFolderStructure(new File(gitRepoCtx.getGitLocalRepoPath())); cloneRepository(gitRepoCtx); // execute artifact update extension extensionHandler.onArtifactUpdateSchedulerEvent(String.valueOf(gitRepoCtx.getTenantId())); return true; } catch (JGitInternalException e) { log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", " + e.getMessage()); return false; } catch (TransportException e) { log.error("Accessing remote git repository " + gitRepoCtx.getGitRemoteRepoUrl() + " failed for tenant " + gitRepoCtx.getTenantId(), e); return false; } catch (CheckoutConflictException e) { //TODO: handle conflict efficiently. Currently the whole directory is deleted and re-cloned log.warn("Git pull for the path " + e.getConflictingPaths().toString() + " failed due to conflicts"); Utilities.deleteFolderStructure(new File(gitRepoCtx.getGitLocalRepoPath())); cloneRepository(gitRepoCtx); // execute artifact update extension extensionHandler.onArtifactUpdateSchedulerEvent(String.valueOf(gitRepoCtx.getTenantId())); return true; } catch (GitAPIException e) { log.error("Git pull operation for tenant " + gitRepoCtx.getTenantId() + " failed", e); return false; } return true; }*/ private boolean pullArtifacts(RepositoryContext gitRepoCtx) throws CheckoutConflictException { PullCommand pullCmd = gitRepoCtx.getGit().pull(); UsernamePasswordCredentialsProvider credentialsProvider = createCredentialsProvider(gitRepoCtx); if (credentialsProvider == null) { log.warn("Remote repository credentials not available for tenant " + gitRepoCtx.getTenantId() + ", aborting pull"); return false; } pullCmd.setCredentialsProvider(credentialsProvider); try { PullResult pullResult = pullCmd.call(); // check if we have received any updates if (!pullResult.getFetchResult().getTrackingRefUpdates().isEmpty()) { if (log.isDebugEnabled()) { log.debug("Artifacts were updated as a result of the pull operation, thread: " + Thread.currentThread().getName() + " - " + Thread.currentThread().getId()); } // execute artifact update extension extensionHandler.onArtifactUpdateSchedulerEvent(String.valueOf(gitRepoCtx.getTenantId())); } } catch (InvalidConfigurationException e) { log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", invalid configuration. " + e.getMessage()); // FileUtilities.deleteFolderStructure(new File(gitRepoCtx.getLocalRepoPath())); //cloneRepository(gitRepoCtx); Utilities.deleteFolderStructure(new File(gitRepoCtx.getGitLocalRepoPath())); cloneRepository(gitRepoCtx); // execute artifact update extension extensionHandler.onArtifactUpdateSchedulerEvent(String.valueOf(gitRepoCtx.getTenantId())); return true; } catch (JGitInternalException e) { log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", " + e.getMessage()); return false; } catch (TransportException e) { log.error("Accessing remote git repository " + gitRepoCtx.getGitRemoteRepoUrl() + " failed for tenant " + gitRepoCtx.getTenantId(), e); return false; } catch (CheckoutConflictException e) { log.warn("Git pull unsuccessful for tenant " + gitRepoCtx.getTenantId() + ", conflicts detected"); throw e; } catch (GitAPIException e) { log.error("Git pull operation for tenant " + gitRepoCtx.getTenantId() + " failed", e); return false; } return true; }
From source file:org.eclipse.orion.server.filesystem.git.GitFileStore.java
License:Open Source License
/** * pulls from the remote/* w w w. j a va2 s . co m*/ * @throws CoreException */ private void pull() throws CoreException { Transport transport = null; try { Repository repo = getLocalRepo(); Git git = new Git(repo); PullCommand pull = git.pull(); pull.setCredentialsProvider(getCredentialsProvider()); PullResult pullResult = pull.call(); LogHelper.log(new Status(IStatus.INFO, Activator.PI_GIT, 1, "Pull (fetch/merge) result " + pullResult.getFetchResult().getMessages() + "/" + pullResult.getMergeResult().getMergeStatus() + " for " + this, null)); } catch (Exception e) { throw new CoreException(new Status(IStatus.ERROR, Activator.PI_GIT, IStatus.ERROR, e.getMessage(), e)); } finally { if (transport != null) transport.close(); } }
From source file:org.eclipse.orion.server.git.jobs.PullJob.java
License:Open Source License
private IStatus doPull() throws IOException, GitAPIException, CoreException { Repository db = new FileRepository(GitUtils.getGitDir(path)); Git git = new Git(db); PullCommand pc = git.pull();/* ww w . ja v a 2s. c om*/ pc.setCredentialsProvider(credentials); pc.setTransportConfigCallback(new TransportConfigCallback() { @Override public void configure(Transport t) { credentials.setUri(t.getURI()); } }); PullResult pullResult = pc.call(); // handle result if (pullResult.isSuccessful()) { return Status.OK_STATUS; } else { FetchResult fetchResult = pullResult.getFetchResult(); IStatus fetchStatus = FetchJob.handleFetchResult(fetchResult); if (!fetchStatus.isOK()) { return fetchStatus; } MergeStatus mergeStatus = pullResult.getMergeResult().getMergeStatus(); if (mergeStatus.isSuccessful()) { return Status.OK_STATUS; } else { return new Status(IStatus.ERROR, GitActivator.PI_GIT, mergeStatus.name()); } } }
From source file:org.wandora.application.tools.git.Pull.java
License:Open Source License
@Override public void execute(Wandora wandora, Context context) { try {/*from w w w . j av a2 s .c o m*/ Git git = getGit(); if (git != null) { if (isNotEmpty(getGitRemoteUrl())) { PullCommand pull = git.pull(); String user = getUsername(); if (user == null) { if (pullUI == null) { pullUI = new PullUI(); } pullUI.setUsername(getUsername()); pullUI.setPassword(getPassword()); pullUI.setRemoteUrl(getGitRemoteUrl()); pullUI.openInDialog(); if (pullUI.wasAccepted()) { setUsername(pullUI.getUsername()); setPassword(pullUI.getPassword()); // setGitRemoteUrl(pullUI.getRemoteUrl()); // pull.setRemote(pullUI.getRemoteUrl()); if (isNotEmpty(getUsername())) { CredentialsProvider credentialsProvider = new UsernamePasswordCredentialsProvider( getUsername(), getPassword()); pull.setCredentialsProvider(credentialsProvider); } } else { return; } } setDefaultLogger(); setLogTitle("Git pull"); log("Pulling changes from remote repository..."); PullResult result = pull.call(); FetchResult fetchResult = result.getFetchResult(); MergeResult mergeResult = result.getMergeResult(); MergeStatus mergeStatus = mergeResult.getMergeStatus(); String fetchResultMessages = fetchResult.getMessages(); if (isNotEmpty(fetchResultMessages)) { log(fetchResult.getMessages()); } log(mergeStatus.toString()); if (mergeStatus.equals(MergeStatus.MERGED)) { int a = WandoraOptionPane.showConfirmDialog(wandora, "Reload Wandora project after pull?", "Reload Wandora project after pull?", WandoraOptionPane.YES_NO_OPTION); if (a == WandoraOptionPane.YES_OPTION) { reloadWandoraProject(); } } log("Ready."); } else { log("Repository has no remote origin and can't be pulled. " + "Initialize repository by cloning remote repository to set the remote origin."); } } else { logAboutMissingGitRepository(); } } catch (GitAPIException gae) { log(gae.toString()); } catch (NoWorkTreeException nwte) { log(nwte.toString()); } catch (Exception e) { log(e); } setState(WAIT); }