diff options
author | Chris Aniszczyk <caniszczyk@gmail.com> | 2011-01-28 10:52:38 -0500 |
---|---|---|
committer | Code Review <codereview-daemon@eclipse.org> | 2011-01-28 10:52:38 -0500 |
commit | bf69401feeea459d10b0cfc9cbe9bdb5d8f38bf0 (patch) | |
tree | 3c1e437bf4c156866ab351eeea52c4b5c3f26a96 /org.eclipse.jgit | |
parent | 0b2ac1e929292d385855dba26e753d09a9e14255 (diff) | |
parent | 14ca80bc90ed85e3484fa28aa665fa0538096d30 (diff) | |
download | jgit-bf69401feeea459d10b0cfc9cbe9bdb5d8f38bf0.tar.gz jgit-bf69401feeea459d10b0cfc9cbe9bdb5d8f38bf0.zip |
Merge "Make PullCommand work with Rebase"
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java | 123 | ||||
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/PullResult.java | 22 |
2 files changed, 94 insertions, 51 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java index adcea90f56..73dc452ae2 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java @@ -47,16 +47,19 @@ import java.io.IOException; import java.text.MessageFormat; import org.eclipse.jgit.JGitText; +import org.eclipse.jgit.api.RebaseCommand.Operation; import org.eclipse.jgit.api.errors.CanceledException; import org.eclipse.jgit.api.errors.CheckoutConflictException; import org.eclipse.jgit.api.errors.ConcurrentRefUpdateException; import org.eclipse.jgit.api.errors.DetachedHeadException; +import org.eclipse.jgit.api.errors.GitAPIException; import org.eclipse.jgit.api.errors.InvalidConfigurationException; import org.eclipse.jgit.api.errors.InvalidMergeHeadsException; import org.eclipse.jgit.api.errors.InvalidRemoteException; import org.eclipse.jgit.api.errors.JGitInternalException; import org.eclipse.jgit.api.errors.NoHeadException; import org.eclipse.jgit.api.errors.NoMessageException; +import org.eclipse.jgit.api.errors.RefNotFoundException; import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.Config; @@ -163,15 +166,14 @@ public class PullCommand extends GitCommand<PullResult> { String remoteBranchName = repoConfig.getString( ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); + boolean doRebase = false; if (remoteBranchName == null) { // check if the branch is configured for pull-rebase remoteBranchName = repoConfig.getString( ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_REBASE); if (remoteBranchName != null) { - // TODO implement pull-rebase - throw new JGitInternalException( - "Pull with rebase is not yet supported"); + doRebase = true; } } @@ -214,60 +216,81 @@ public class PullCommand extends GitCommand<PullResult> { monitor.update(1); - // we check the updates to see which of the updated branches corresponds - // to the remote branch name + if (monitor.isCancelled()) + throw new CanceledException(MessageFormat.format( + JGitText.get().operationCanceled, + JGitText.get().pullTaskName)); - AnyObjectId commitToMerge; + PullResult result; + if (doRebase) { + RebaseCommand rebase = new RebaseCommand(repo); + try { + RebaseResult rebaseRes = rebase.setUpstream(remoteBranchName) + .setProgressMonitor(monitor).setOperation( + Operation.BEGIN).call(); + result = new PullResult(fetchRes, remote, rebaseRes); + } catch (NoHeadException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (RefNotFoundException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (JGitInternalException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (GitAPIException e) { + throw new JGitInternalException(e.getMessage(), e); + } + } else { + // we check the updates to see which of the updated branches + // corresponds + // to the remote branch name + AnyObjectId commitToMerge; - if (isRemote) { - Ref r = null; - if (fetchRes != null) { - r = fetchRes.getAdvertisedRef(remoteBranchName); + if (isRemote) { + Ref r = null; + if (fetchRes != null) { + r = fetchRes.getAdvertisedRef(remoteBranchName); + if (r == null) + r = fetchRes.getAdvertisedRef(Constants.R_HEADS + + remoteBranchName); + } if (r == null) - r = fetchRes.getAdvertisedRef(Constants.R_HEADS - + remoteBranchName); + throw new JGitInternalException(MessageFormat.format( + JGitText.get().couldNotGetAdvertisedRef, + remoteBranchName)); + else + commitToMerge = r.getObjectId(); + } else { + try { + commitToMerge = repo.resolve(remoteBranchName); + } catch (IOException e) { + throw new JGitInternalException( + JGitText.get().exceptionCaughtDuringExecutionOfPullCommand, + e); + } } - if (r == null) - throw new JGitInternalException(MessageFormat.format(JGitText - .get().couldNotGetAdvertisedRef, remoteBranchName)); - else - commitToMerge = r.getObjectId(); - } else { + MergeCommand merge = new MergeCommand(repo); + merge.include( + "branch \'" + remoteBranchName + "\' of " + remoteUri, + commitToMerge); + MergeResult mergeRes; try { - commitToMerge = repo.resolve(remoteBranchName); - } catch (IOException e) { - throw new JGitInternalException( - JGitText.get().exceptionCaughtDuringExecutionOfPullCommand, - e); + mergeRes = merge.call(); + monitor.update(1); + result = new PullResult(fetchRes, remote, mergeRes); + } catch (NoHeadException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (ConcurrentRefUpdateException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (CheckoutConflictException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (InvalidMergeHeadsException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (WrongRepositoryStateException e) { + throw new JGitInternalException(e.getMessage(), e); + } catch (NoMessageException e) { + throw new JGitInternalException(e.getMessage(), e); } } - - if (monitor.isCancelled()) - throw new CanceledException(MessageFormat.format( - JGitText.get().operationCanceled, - JGitText.get().pullTaskName)); - - MergeCommand merge = new MergeCommand(repo); - merge.include("branch \'" + remoteBranchName + "\' of " + remoteUri, - commitToMerge); - MergeResult mergeRes; - try { - mergeRes = merge.call(); - monitor.update(1); - } catch (NoHeadException e) { - throw new JGitInternalException(e.getMessage(), e); - } catch (ConcurrentRefUpdateException e) { - throw new JGitInternalException(e.getMessage(), e); - } catch (CheckoutConflictException e) { - throw new JGitInternalException(e.getMessage(), e); - } catch (InvalidMergeHeadsException e) { - throw new JGitInternalException(e.getMessage(), e); - } catch (WrongRepositoryStateException e) { - throw new JGitInternalException(e.getMessage(), e); - } catch (NoMessageException e) { - throw new JGitInternalException(e.getMessage(), e); - } monitor.endTask(); - return new PullResult(fetchRes, remote, mergeRes); + return result; } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullResult.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullResult.java index 105b76f811..40ed137ee0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullResult.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullResult.java @@ -52,6 +52,8 @@ public class PullResult { private final MergeResult mergeResult; + private final RebaseResult rebaseResult; + private final String fetchedFrom; PullResult(FetchResult fetchResult, String fetchedFrom, @@ -59,6 +61,15 @@ public class PullResult { this.fetchResult = fetchResult; this.fetchedFrom = fetchedFrom; this.mergeResult = mergeResult; + this.rebaseResult = null; + } + + PullResult(FetchResult fetchResult, String fetchedFrom, + RebaseResult rebaseResult) { + this.fetchResult = fetchResult; + this.fetchedFrom = fetchedFrom; + this.mergeResult = null; + this.rebaseResult = rebaseResult; } /** @@ -76,6 +87,13 @@ public class PullResult { } /** + * @return the rebase result, or <code>null</code> + */ + public RebaseResult getRebaseResult() { + return this.rebaseResult; + } + + /** * @return the name of the remote configuration from which fetch was tried, * or <code>null</code> */ @@ -93,8 +111,10 @@ public class PullResult { sb.append("\n"); if (mergeResult != null) sb.append(mergeResult.toString()); + else if (rebaseResult != null) + sb.append(rebaseResult.toString()); else - sb.append("No merge result"); + sb.append("No update result"); return sb.toString(); } } |