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()); }
command.setRebase(settings.valueOfIndex("rebase").toBoolean());
/** * Pulls changes for the project * @param project - a Git project */ void pull(File project) { try { try (Git git = this.gitFactory.open(project)) { PullCommand command = this.gitFactory.pull(git); command.setRebase(true).call(); } } catch (Exception e) { throw new IllegalStateException(e); } }
protected void doPull(Git git, GitContext context) throws GitAPIException { StopWatch watch = new StopWatch(); LOG.info("Performing a pull in git repository " + this.gitFolder + " on remote URL: " + this.remoteRepository); CredentialsProvider cp = userDetails.createCredentialsProvider(); PullCommand command = git.pull(); configureCommand(command, userDetails); command.setCredentialsProvider(cp).setRebase(true).call(); LOG.info("Took " + watch.taken() + " to complete pull in git repository " + this.gitFolder + " on remote URL: " + this.remoteRepository); }
private Collection<String> attemptRebase() throws GitAPIException { val conflicts = new HashSet<String>(); createStashIfNeeded(); val pr = git.pull().setStrategy(MergeStrategy.RESOLVE).setRebase(true).call(); if (pr.getRebaseResult().getConflicts() != null) { conflicts.addAll(pr.getRebaseResult().getConflicts()); } conflicts.addAll(applyStashIfNeeded()); return conflicts; }
@Override public Void call() { try { /** git pull is preferable since it's more efficient **/ LOGGER.debug("Started refresh with git pull"); final PullResult result = getGit().pull().setProgressMonitor(PROGRESS_MONITOR).setRebase(true).setCredentialsProvider(user).call(); if (!result.isSuccessful()) { /** if git pull failed, use git reset **/ LOGGER.info("refresh failed. Running undo local changes"); undoLocalChanges(); } LOGGER.debug("Finished refresh"); } catch (final Exception e) { LOGGER.error("Error when refreshing git directory " + workspaceProvider.getRootDirectory(), e); } return null; } });
@Override public Void call() { try { /** git pull is preferable since it's more efficient **/ LOGGER.debug("Started refresh with git pull"); final PullResult result = getGit().pull().setProgressMonitor(PROGRESS_MONITOR).setRebase(true).setCredentialsProvider(user).call(); if (!result.isSuccessful()) { /** if git pull failed, use git reset **/ LOGGER.info("refresh failed. Running undo local changes"); undoLocalChanges(); } LOGGER.debug("Finished refresh"); } catch (final Exception e) { LOGGER.error("Error when refreshing git directory " + workspaceProvider.getRootDirectory(), e); } return null; } });
private Git pullRepository(final File workingDir) throws GitAPIException, IOException { final Git git = Git.open(workingDir); git.pull().setProgressMonitor(PROGRESS_MONITOR) .setRebase(true) .setCredentialsProvider(user) .setTimeout(pullPushTimeoutSeconds) .call(); return git; }
private Git pullRepository(final File workingDir) throws GitAPIException, IOException { final Git git = Git.open(workingDir); git.pull().setProgressMonitor(PROGRESS_MONITOR) .setRebase(true) .setCredentialsProvider(user) .setTimeout(pullPushTimeoutSeconds) .call(); return git; }
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);
public void pullRepo() { try { git.pull().setRemote(REMOTE_NAME).setRemoteBranchName(MASTER_BRANCH).setRebase(false).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } }
protected void doPull() { CredentialsProvider cp = getCredentials(); try { Repository repository = git.getRepository(); StoredConfig config = repository.getConfig(); String url = config.getString("remote", "origin", "url"); if (Strings.isBlank(url)) { logPull("No remote repository defined for the git repository at " + getRootGitDirectory().getCanonicalPath() + " so not doing a pull"); return; } String branch = repository.getBranch(); String mergeUrl = config.getString("branch", branch, "merge"); if (Strings.isBlank(mergeUrl)) { logPull("No merge spec for branch." + branch + ".merge in the git repository at " + getRootGitDirectory().getCanonicalPath() + " so not doing a pull"); return; } logPull("Performing a pull in git repository " + getRootGitDirectory().getCanonicalPath() + " on remote URL: " + url); git.pull().setCredentialsProvider(cp).setRebase(true).call(); } catch (Throwable e) { String credText = ""; if (cp instanceof UsernamePasswordCredentialsProvider) { } LOG.error("Failed to pull from the remote git repo with credentials " + cp + " due: " + e.getMessage() + ". This exception is ignored.", e); } finally { firstPull = false; } }
@Override public Void call() { try { final PullResult result = gitProctorCore.getGit() .pull() .setProgressMonitor(PROGRESS_MONITOR) .setRebase(true) .setCredentialsProvider(user) .setTimeout(GitProctorUtils.DEFAULT_GIT_PULL_PUSH_TIMEOUT_SECONDS) .call(); if (!result.isSuccessful()) { /** if git pull failed, use git reset **/ gitProctorCore.undoLocalChanges(); } } catch (final Exception e) { LOGGER.error("Error when refreshing git directory " + getDirectoryPath(), e); } return null; } });
public void pullRepo(String uri, String branch) { try { setRemote(uri); git.pull().setRemote(REMOTE_NAME).setRemoteBranchName(branch).setRebase(false).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } }
@Override public Void call() { try { final PullResult result = gitProctorCore.getGit() .pull() .setProgressMonitor(PROGRESS_MONITOR) .setRebase(true) .setCredentialsProvider(user) .setTimeout(GitProctorUtils.DEFAULT_GIT_PULL_PUSH_TIMEOUT_SECONDS) .call(); if (!result.isSuccessful()) { /** if git pull failed, use git reset **/ gitProctorCore.undoLocalChanges(); } } catch (final Exception e) { LOGGER.error("Error when refreshing git directory " + getDirectoryPath(), e); } return null; } });
/** * Pull-rebase and push to the remote repo if git.remote is enabled * * @throws GitAPIException If there is a failure talking to the remote repository */ public void push() throws GitAPIException { if (remote) { synchronized (gitDir) { if (haveRemoteBranch()) { git.pull().setCredentialsProvider(provider).setRebase(true).call(); } git.push().setCredentialsProvider(provider).setRemote("origin").call(); } } }
/** * Pull from upstream * * @param git * @param stash * @param newBranch * @param previousBranch * @throws Exception */ private void pullFromRemoteUpstream(Git git, RevCommit stash, String newBranch, String previousBranch) throws Exception { try { PullCommand pull = git.pull() .setRebase(true) .setRemote(UPSTREAM) .setRemoteBranchName(branch); PullResult pullResult = pull.call(); if(!pullResult.isSuccessful()){ rebaseAbort(git); checkoutBranch(git, previousBranch); if (stash != null) { git.stashApply().setStashRef(stash.getName()).call(); } deleteTempBranch(git, newBranch); throw new Exception(CONFLICT_MESSAGE_REASON); } } catch (GitAPIException e) { throw new Exception(PULL_COMMAND_PROBLEM_REASON, e); } }
public GitManager pullUpdates( final ConflictStrategy strategy ) throws GitSubsystemException { lockAnd( me->{ try { git.pull() .setStrategy( strategy.mergeStrategy() ) .setRemoteBranchName( config.getRemoteBranchName() ) .setRebase( true ) .call(); } catch ( final GitAPIException e ) { throw new GitSubsystemException( "Cannot pull content updates via git: " + e.getMessage(), e ); } return me; } ); return this; }
public static Boolean pullAndRebase(final Git git) { Boolean result = Boolean.FALSE; try { git.reset().setMode(ResetCommand.ResetType.HARD).call(); final RebaseResult rr = git.pull().setRemote(REMOTE).setRebase(Boolean.TRUE).call().getRebaseResult(); if (rr.getStatus().equals(RebaseResult.Status.UP_TO_DATE) || rr.getStatus().equals(RebaseResult.Status.FAST_FORWARD)) { result = Boolean.TRUE; } if (rr.getStatus().equals(RebaseResult.Status.UNCOMMITTED_CHANGES)) { PullResult pr = git.pull().call(); if (pr.isSuccessful()) { result = Boolean.TRUE; } else { result = Boolean.FALSE; } } } catch (Exception e) { logger.error(e.getMessage()); } return result; }
public void pullRepo(String uri, String branch, GitUser user) { try { setRemote(uri); git.pull().setRemote(REMOTE_NAME).setRemoteBranchName(branch).setRebase(false) .setCredentialsProvider(new UsernamePasswordCredentialsProvider(user.getUsername(), user.getPassword())).call(); } catch (InvalidRemoteException e) { e.printStackTrace(); } catch (TransportException e) { e.printStackTrace(); } catch (GitAPIException e) { e.printStackTrace(); } }