Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
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.java52
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

Back to the top