List of usage examples for org.eclipse.jgit.api PullResult getMergeResult
public MergeResult getMergeResult()
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 {/*from w w w . j a v a 2 s . co m*/ 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.door43.translationstudio.tasks.PullTargetTranslationTask.java
private String pull(Repo repo, String remote) { Git git;// w w w . j a va 2 s .c o m try { repo.deleteRemote("origin"); repo.setRemote("origin", remote); git = repo.getGit(); } catch (IOException e) { return null; } Manifest localManifest = Manifest.generate(this.targetTranslation.getPath()); // TODO: we might want to get some progress feedback for the user PullCommand pullCommand = git.pull().setTransportConfigCallback(new TransportCallback()).setRemote("origin") .setStrategy(mergeStrategy).setRemoteBranchName("master").setProgressMonitor(new ProgressMonitor() { @Override public void start(int totalTasks) { } @Override public void beginTask(String title, int totalWork) { } @Override public void update(int completed) { } @Override public void endTask() { } @Override public boolean isCancelled() { return false; } }); try { PullResult result = pullCommand.call(); MergeResult mergeResult = result.getMergeResult(); if (mergeResult != null && mergeResult.getConflicts() != null && mergeResult.getConflicts().size() > 0) { this.status = Status.MERGE_CONFLICTS; this.conflicts = mergeResult.getConflicts(); // revert manifest merge conflict to avoid corruption if (this.conflicts.containsKey("manifest.json")) { Logger.i("PullTargetTranslationTask", "Reverting to server manifest"); try { git.checkout().setStage(CheckoutCommand.Stage.THEIRS).addPath("manifest.json").call(); Manifest remoteManifest = Manifest.generate(this.targetTranslation.getPath()); localManifest = TargetTranslation.mergeManifests(localManifest, remoteManifest); } catch (CheckoutConflictException e) { // failed to reset manifest.json Logger.e(this.getClass().getName(), "Failed to reset manifest: " + e.getMessage(), e); } finally { localManifest.save(); } } // keep our license if (this.conflicts.containsKey("LICENSE.md")) { Logger.i("PullTargetTranslationTask", "Reverting to local license"); try { git.checkout().setStage(CheckoutCommand.Stage.OURS).addPath("LICENSE.md").call(); } catch (CheckoutConflictException e) { Logger.e(this.getClass().getName(), "Failed to reset license: " + e.getMessage(), e); } } } else { this.status = Status.UP_TO_DATE; } return "message"; } catch (TransportException e) { Logger.e(this.getClass().getName(), e.getMessage(), e); Throwable cause = e.getCause(); if (cause != null) { Throwable subException = cause.getCause(); if (subException != null) { String detail = subException.getMessage(); if ("Auth fail".equals(detail)) { this.status = Status.AUTH_FAILURE; // we do special handling for auth failure } } else if (cause instanceof NoRemoteRepositoryException) { this.status = Status.NO_REMOTE_REPO; } } return null; } catch (Exception e) { Throwable cause = e.getCause(); if (cause instanceof NoRemoteRepositoryException) { this.status = Status.NO_REMOTE_REPO; } Logger.e(this.getClass().getName(), e.getMessage(), e); return null; } catch (OutOfMemoryError e) { Logger.e(this.getClass().getName(), e.getMessage(), e); this.status = Status.OUT_OF_MEMORY; return null; } catch (Throwable e) { Logger.e(this.getClass().getName(), e.getMessage(), e); return null; } }
From source file:com.rimerosolutions.ant.git.tasks.PullTask.java
License:Apache License
@Override public void doExecute() { try {// w ww . ja v a 2s . com 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:edu.wustl.lookingglass.community.CommunityRepository.java
License:Open Source License
private void pull() throws GitAPIException, IOException { assert this.credentials != null; assert this.remoteName != null; assert this.username != null; assert this.email != null; String head = this.git.getRepository().getBranch(); PullCommand pull = git.pull().setCredentialsProvider(this.credentials).setRemote(this.remoteName) .setRemoteBranchName(head);/*from w ww.j av a2 s. c om*/ PullResult result = pull.call(); MergeResult mergeResult = result.getMergeResult(); MergeStatus mergeStatus = mergeResult.getMergeStatus(); // How did the merge go? switch (mergeStatus) { case ALREADY_UP_TO_DATE: case FAST_FORWARD: case FAST_FORWARD_SQUASHED: case MERGED: case MERGED_SQUASHED: // Yeah! Everything is good! break; case MERGED_NOT_COMMITTED: case MERGED_SQUASHED_NOT_COMMITTED: // Merged, but we need to commit this.git.commit().setAuthor(this.username, this.email).call(); break; case CONFLICTING: // We got conflicts! this.resolveMerge(); break; case CHECKOUT_CONFLICT: case ABORTED: case FAILED: case NOT_SUPPORTED: // something went wrong throw new IllegalStateException("invalid merge state: " + mergeStatus); default: throw new IllegalArgumentException("unknown merge status state: " + mergeStatus); } }
From source file:eu.cloud4soa.cli.roo.addon.commands.GitManager.java
License:Apache License
public void pull() throws GitAPIException, IOException { pullCommand = git.pull();/*from ww w. ja va 2 s.c om*/ 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:facade.GitFacade.java
public static String pullRepo(Repository repository) throws GitAPIException { Git git = new Git(repository); PullResult result = null; org.eclipse.jgit.api.PullCommand pullComand = git.pull(); result = pullComand.call();/*from ww w . ja v a2 s . c o m*/ MergeResult mergeResult = result.getMergeResult(); return "Merge Status: " + mergeResult.getMergeStatus().toString(); }
From source file:fr.duminy.tools.jgit.JGitToolbox.java
License:Open Source License
public String track(Parameters parameters) throws GitToolboxException { try {//from w w w . ja v a2s. c o m Git targetGit = Git.open(parameters.getGitDirectory()); ProgressMonitor progressMonitor = new TextProgressMonitor(); PullCommand pullCommand = targetGit.pull().setProgressMonitor(progressMonitor); PullResult result = pullCommand.call(); System.out.println(result); if (!result.isSuccessful()) { throw new GitToolboxException("Failed to update tracking branch : " + result.toString()); } MergeResult.MergeStatus mergeStatus = result.getMergeResult().getMergeStatus(); if (!ALREADY_UP_TO_DATE.equals(mergeStatus) && !FAST_FORWARD.equals(mergeStatus)) { throw new GitToolboxException("Failed to update tracking branch : " + result.toString()); } return targetGit.getRepository().getRef(Constants.HEAD).getName(); } catch (Exception e) { throw new GitToolboxException("Error while updating tracking branch", e); } }
From source file:git_manager.tool.GitOperations.java
License:Open Source License
public void pullFromRemote() { if (!getRemote()) { System.out.println("Pull cancelled."); return;/*from ww w.j a v a 2 s .c o m*/ } 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:io.github.thefishlive.updater.Updater.java
License:Open Source License
public void run() { System.out.println("-------------------------"); System.out.println(gitDir.getAbsolutePath()); File updateFile = new File(basedir, "UPDATE"); Git git = null;/*from w w w . j a va 2s. c o m*/ try { if (!gitDir.exists()) { git = Git.cloneRepository().setDirectory(basedir).setURI(GitUpdater.remote) .setProgressMonitor(buildProgressMonitor()).call(); System.out.println("Repository cloned"); } else { updateFile.createNewFile(); FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repo = builder.setGitDir(gitDir).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); git = new Git(repo); PullResult result = git.pull().setProgressMonitor(buildProgressMonitor()).call(); if (!result.isSuccessful() || result.getMergeResult().getMergeStatus().equals(MergeStatus.MERGED)) { System.out.println("Update Failed"); FileUtils.deleteDirectory(basedir); basedir.mkdir(); System.out.println("Re-cloning repository"); git = Git.cloneRepository().setDirectory(basedir).setURI(GitUpdater.remote) .setProgressMonitor(buildProgressMonitor()).call(); System.out.println("Repository cloned"); } System.out.println("State: " + result.getMergeResult().getMergeStatus()); } File configdir = new File("config"); if (configdir.exists()) { FileUtils.copyDirectory(configdir, new File(basedir, "config")); } } catch (Exception e) { e.printStackTrace(); } finally { git.getRepository().close(); } updateFile.delete(); System.out.println("-------------------------"); }
From source file:io.vertx.config.git.GitConfigStore.java
License:Apache License
private Future<Void> update() { Promise<Void> result = Promise.promise(); vertx.executeBlocking(future -> { PullResult call; try {//from www .j a va 2 s .c om call = git.pull().setRemote(remote).setRemoteBranchName(branch) .setCredentialsProvider(credentialProvider).call(); } catch (GitAPIException e) { future.fail(e); return; } if (call.isSuccessful()) { future.complete(); } else { if (call.getMergeResult() != null) { future.fail("Unable to merge repository - Conflicts: " + call.getMergeResult().getCheckoutConflicts()); } else { future.fail( "Unable to rebase repository - Conflicts: " + call.getRebaseResult().getConflicts()); } } }, result); return result.future(); }