List of usage examples for org.eclipse.jgit.api PullResult isSuccessful
public boolean isSuccessful()
From source file:ch.sbb.releasetrain.git.GitRepoImpl.java
License:Apache License
private Git pull(Git git) throws GitAPIException { if (remoteBranchExists(git)) { PullResult result = git.pull().setStrategy(MergeStrategy.RECURSIVE) .setCredentialsProvider(this.credentialsProvider()).call(); if (result.isSuccessful()) { return git; } else {/*from ww w .ja va 2s . c om*/ log.info( "*** pulling git, not able to merge with MergeStrategy.RECURSIVE go for MergeStrategy.THEIRS"); result = git.pull().setStrategy(MergeStrategy.THEIRS) .setCredentialsProvider(this.credentialsProvider()).call(); if (result.isSuccessful()) { return git; } throw new GitException("Pull failed: " + result.toString()); } } else { return git; } }
From source file:com.bb.extensions.plugin.unittests.internal.git.GitWrapper.java
License:Open Source License
/** * @return performs a pull from origin//from w w w. j a v a 2 s . co m */ public boolean pullMocks() { PullCommand pullCmd = git.pull(); try { PullResult pullResult = pullCmd.call(); return pullResult.isSuccessful(); } catch (WrongRepositoryStateException e) { e.printStackTrace(); } catch (InvalidConfigurationException e) { e.printStackTrace(); } catch (DetachedHeadException e) { e.printStackTrace(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (CanceledException e) { e.printStackTrace(); } catch (RefNotFoundException e) { e.printStackTrace(); } catch (NoHeadException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } return false; }
From source file:com.osbitools.ws.shared.prj.utils.GitUtils.java
License:Open Source License
/** * Push git changes from remote git repository * * @param git Local git repository/*w w w . j a v a2s. co m*/ * @param name Remote Git name * @param url Remote Git url * @return pull result * @throws WsSrvException */ public static boolean pullFromRemote(Git git, String name, String url) throws WsSrvException { checkRemoteGitConfig(name, url); try { PullResult pres = git.pull().setRemote(name).call(); return pres.isSuccessful(); } catch (GitAPIException e) { //-- 250 throw new WsSrvException(250, e, "Error pull from remote [" + name + "]"); } }
From source file:com.rimerosolutions.ant.git.tasks.PullTask.java
License:Apache License
@Override public void doExecute() { try {/*from www .j a v a 2 s .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();/*www . j a v a 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:ezbake.deployer.publishers.openShift.RhcApplication.java
License:Apache License
/** * This will make sure that a directory is on disk for the git repository. It will clone the git repo to the directory * if needed, or git pull the new contents if required. * * @return git repository created/retrieved from OpenShift with the remote pointing to OpenShift * @throws DeploymentException - on any exception getting it from git *//*from w w w. j a v a 2s .co m*/ public Git getOrCreateGitRepo() throws DeploymentException { String gitUrl = applicationInstance.getGitUrl(); Files.createDirectories(appTmpDir); File gitDir = new File(appTmpDir, ".git"); if (gitRepo != null || gitDir.exists() && gitDir.isDirectory()) { try { Git git = gitRepo != null ? gitRepo : Git.open(appTmpDir); // stash to get to a clean state of git dir so that we can pull without conflicts git.stashCreate(); git.stashDrop(); PullCommand pullCommand = git.pull(); if (gitCredentialsProvider != null) pullCommand.setCredentialsProvider(gitCredentialsProvider); PullResult result = pullCommand.call(); if (!result.isSuccessful()) throw new DeploymentException("Git pull was not successful: " + result.toString()); setGitRepo(git); return git; } catch (IOException | GitAPIException e) { log.error("Error opening existing cached git repo", e); throw new DeploymentException("Error opening existing cached git repo: " + e.getMessage()); } } else { try { log.info("Cloning to " + appTmpDir.toString()); CloneCommand cloneCommand = Git.cloneRepository().setURI(gitUrl).setTimeout(10000) .setDirectory(appTmpDir); if (gitCredentialsProvider != null) cloneCommand.setCredentialsProvider(gitCredentialsProvider); gitRepo = cloneCommand.call(); log.info("Cloned to directory: " + gitRepo.getRepository().getDirectory().getParentFile().getAbsolutePath()); return gitRepo; } catch (GitAPIException | JGitInternalException e) { log.error("Error cloning repository from OpenShift", e); throw new DeploymentException("Error cloning repository from OpenShift: " + e.getMessage()); } } }
From source file:fr.duminy.tools.jgit.JGitToolbox.java
License:Open Source License
public String track(Parameters parameters) throws GitToolboxException { try {/* w w w . j a v a2 s . c om*/ 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:io.fabric8.itests.basic.git.FabricGitTestSupport.java
License:Apache License
/** * Create a profile in the registry and check that its bridged to git. *///w w w . j a v a 2 s.co m protected void createAndTestProfileInDataStore(FabricService fabricService, CuratorFramework curator, Git git, String version, String profile) throws Exception { System.out.println("Create test profile:" + profile + " in datastore."); List<String> versions = Lists.transform(Arrays.<Version>asList(fabricService.getVersions()), new Function<Version, String>() { @Override public String apply(Version version) { return version.getId(); } }); if (!versions.contains(version)) { fabricService.createVersion(version); } fabricService.getDataStore().createProfile(version, profile); GitUtils.waitForBranchUpdate(curator, version); GitUtils.checkoutBranch(git, "origin", version); PullResult pullResult = git.pull().setCredentialsProvider(getCredentialsProvider()).setRebase(true).call(); assertTrue(pullResult.isSuccessful()); String relativeProfileDir = "fabric/profiles/" + profile + ".profile"; File testProfileDir = new File(git.getRepository().getWorkTree(), relativeProfileDir); assertTrue(testProfileDir.exists()); File testProfileConfig = new File(testProfileDir, "io.fabric8.agent.properties"); assertTrue(testProfileConfig.exists()); }
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 ww .jav a 2 s . 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 Git initializeGit() throws IOException, GitAPIException { if (path.isDirectory()) { Git git = Git.open(path);//from w w w. jav a 2 s. c o m String current = git.getRepository().getBranch(); if (branch.equalsIgnoreCase(current)) { PullResult pull = git.pull().setRemote(remote).setCredentialsProvider(credentialProvider) .setTransportConfigCallback(transportConfigCallback).call(); if (!pull.isSuccessful()) { LOGGER.warn("Unable to pull the branch + '" + branch + "' from the remote repository '" + remote + "'"); } return git; } else { git.checkout().setName(branch).setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK) .setStartPoint(remote + "/" + branch).call(); return git; } } else { return Git.cloneRepository().setURI(url).setBranch(branch).setRemote(remote).setDirectory(path) .setCredentialsProvider(credentialProvider).setTransportConfigCallback(transportConfigCallback) .call(); } }