diff options
author | Mikael Karlsson <mmmicke@gmail.com> | 2012-05-16 18:34:38 +0200 |
---|---|---|
committer | Chris Aniszczyk <zx@twitter.com> | 2012-11-16 12:51:35 -0800 |
commit | fa5231191d530afb24810080e89990913c8e8054 (patch) | |
tree | b6a8a55481c7f7110249f92dfbf35a470b0f2077 /org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java | |
parent | 58dd2868485352de558121b7397e8a9ea2901f82 (diff) | |
download | jgit-fa5231191d530afb24810080e89990913c8e8054.tar.gz jgit-fa5231191d530afb24810080e89990913c8e8054.zip |
Add support for pull with --rebase and --no-rebase
Bug: 394501
Change-Id: I697e2fc82a46c03762111eb1de93e673a2643b4f
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java')
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java | 52 |
1 files changed, 48 insertions, 4 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 5b8c776fd7..8179098885 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/PullCommand.java @@ -80,6 +80,14 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> { private ProgressMonitor monitor = NullProgressMonitor.INSTANCE; + private PullRebaseMode pullRebaseMode = PullRebaseMode.USE_CONFIG; + + private enum PullRebaseMode { + USE_CONFIG, + REBASE, + NO_REBASE + } + /** * @param repo */ @@ -98,6 +106,28 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> { } /** + * Set if rebase should be used after fetching. If set to true, rebase is + * used instead of merge. This is equivalent to --rebase on the command line. + * <p/> + * If set to false, merge is used after fetching, overriding the configuration + * file. This is equivalent to --no-rebase on the command line. + * <p/> + * This setting overrides the settings in the configuration file. + * By default, the setting in the repository configuration file is used. + * <p/> + * A branch can be configured to use rebase by default. + * See branch.[name].rebase and branch.autosetuprebase. + * + * @param useRebase + * @return {@code this} + */ + public PullCommand setRebase(boolean useRebase) { + checkCallable(); + pullRebaseMode = useRebase ? PullRebaseMode.REBASE : PullRebaseMode.NO_REBASE; + return this; + } + + /** * Executes the {@code Pull} command with all the options and parameters * collected by the setter methods (e.g. * {@link #setProgressMonitor(ProgressMonitor)}) of this class. Each @@ -162,10 +192,24 @@ public class PullCommand extends TransportCommand<PullCommand, PullResult> { String remoteBranchName = repoConfig.getString( ConfigConstants.CONFIG_BRANCH_SECTION, branchName, ConfigConstants.CONFIG_KEY_MERGE); - // check if the branch is configured for pull-rebase - boolean doRebase = repoConfig.getBoolean( - ConfigConstants.CONFIG_BRANCH_SECTION, branchName, - ConfigConstants.CONFIG_KEY_REBASE, false); + + // determines whether rebase should be used after fetching + boolean doRebase = false; + switch (pullRebaseMode) { + case REBASE: + doRebase = true; + break; + case NO_REBASE: + doRebase = false; + break; + case USE_CONFIG: + default: + // check if the branch is configured for pull-rebase + doRebase = repoConfig.getBoolean( + ConfigConstants.CONFIG_BRANCH_SECTION, branchName, + ConfigConstants.CONFIG_KEY_REBASE, false); + break; + } if (remoteBranchName == null) { String missingKey = ConfigConstants.CONFIG_BRANCH_SECTION + DOT |