List of usage examples for org.eclipse.jgit.api PullCommand setRebase
public PullCommand setRebase(BranchRebaseMode rebaseMode)
From source file:io.fabric8.collector.git.GitBuildConfigProcessor.java
License:Apache License
protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent, UserDetails userDetails) {/* w w w . j a v a 2 s . c o m*/ try { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); Git git = new Git(repository); File projectFolder = repository.getDirectory(); StoredConfig config = repository.getConfig(); String url = config.getString("remote", userDetails.getRemote(), "url"); if (Strings.isNullOrBlank(url)) { LOG.warn("No remote repository url for " + branch + " defined for the git repository at " + projectFolder.getCanonicalPath() + " so cannot pull"); //return; } String mergeUrl = config.getString("branch", branch, "merge"); if (Strings.isNullOrBlank(mergeUrl)) { LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at " + projectFolder.getCanonicalPath() + " so not doing a pull"); //return; } LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: " + url); PullCommand pull = git.pull(); GitHelpers.configureCommand(pull, userDetails); pull.setRebase(true).call(); } catch (Throwable e) { LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage() + ". This exception is ignored.", e); } }
From source file:io.fabric8.forge.generator.pipeline.JenkinsPipelineLibrary.java
License:Apache License
protected void doPull(File gitFolder, CredentialsProvider cp, String branch, PersonIdent personIdent, UserDetails userDetails) {//from w w w . j av a2 s . com StopWatch watch = new StopWatch(); try { FileRepositoryBuilder builder = new FileRepositoryBuilder(); Repository repository = builder.setGitDir(gitFolder).readEnvironment() // scan environment GIT_* variables .findGitDir() // scan up the file system tree .build(); Git git = new Git(repository); File projectFolder = repository.getDirectory(); StoredConfig config = repository.getConfig(); String url = config.getString("remote", remote, "url"); if (io.fabric8.utils.Strings.isNullOrBlank(url)) { LOG.warn("No remote repository url for " + branch + " defined for the git repository at " + projectFolder.getCanonicalPath() + " so cannot pull"); //return; } String mergeUrl = config.getString("branch", branch, "merge"); if (io.fabric8.utils.Strings.isNullOrBlank(mergeUrl)) { LOG.warn("No merge spec for branch." + branch + ".merge in the git repository at " + projectFolder.getCanonicalPath() + " so not doing a pull"); //return; } // lets trash any failed changes LOG.debug("Stashing local changes to the repo"); boolean hasHead = true; try { git.log().all().call(); hasHead = git.getRepository().getAllRefs().containsKey("HEAD"); } catch (NoHeadException e) { hasHead = false; } if (hasHead) { // lets stash any local changes just in case.. try { git.stashCreate().setPerson(personIdent).setWorkingDirectoryMessage("Stash before a write") .setRef("HEAD").call(); } catch (Throwable e) { LOG.error("Failed to stash changes: " + e, e); Throwable cause = e.getCause(); if (cause != null && cause != e) { LOG.error("Cause: " + cause, cause); } } } //LOG.debug("Resetting the repo"); //git.reset().setMode(ResetCommand.ResetType.HARD).call(); LOG.debug("Performing a pull in git repository " + projectFolder.getCanonicalPath() + " on remote URL: " + url); PullCommand pull = git.pull(); GitUtils.configureCommand(pull, userDetails); pull.setRebase(true).call(); } catch (Throwable e) { LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage() + ". This exception is ignored.", e); } finally { LOG.debug("doPull took " + watch.taken()); } }
From source file:org.archicontribs.modelrepository.grafico.GraficoUtils.java
License:Open Source License
/** * Pull from Remote/*from w ww . j a v a 2s . c o m*/ * @param localGitFolder * @param userName * @param userPassword * @return * @throws IOException * @throws GitAPIException */ public static PullResult pullFromRemote(File localGitFolder, String userName, String userPassword, ProgressMonitor monitor) throws IOException, GitAPIException { try (Git git = Git.open(localGitFolder)) { PullCommand pullCommand = git.pull(); pullCommand.setCredentialsProvider(new UsernamePasswordCredentialsProvider(userName, userPassword)); pullCommand.setRebase(false); // Merge, not rebase pullCommand.setProgressMonitor(monitor); return pullCommand.call(); } }
From source file:org.jplus.jenkins.plugin.git.GITRepositoryUtils.java
@Override public void update() { try {/*w w w .ja va 2s. com*/ LOGGER.debug("update git:" + repositoryPath); CheckoutCommand checkout = git.checkout(); ObjectId resolve = repo.resolve("master"); if (resolve == null) { checkout.setCreateBranch(true); } checkout.setForce(true); checkout.setStage(CheckoutCommand.Stage.THEIRS); checkout.setName("master"); checkout.call(); ResetCommand reset = git.reset(); reset.setMode(ResetCommand.ResetType.HARD); reset.setRef("HEAD"); reset.call(); PullCommand pull = git.pull(); pull.setRebase(true); pull.setRemote("origin"); pull.setRemoteBranchName("master"); pull.setStrategy(MergeStrategy.THEIRS); pull.call(); } catch (Exception ex) { Logger.getLogger(GITRepositoryUtils.class.getName()).log(Level.SEVERE, "update git:" + repositoryPath + " error!!!", ex); } }