.call();
StoredConfig config = target.getRepository().getConfig();
config.setString("branch", "basedOnMaster", "remote", ".");
- config.setString("branch", "basedOnMaster", "rebase",
+ config.setString("branch", "basedOnMaster", "merge",
"refs/heads/master");
+ config.setBoolean("branch", "basedOnMaster", "rebase", true);
config.save();
target.getRepository().updateRef(Constants.HEAD).link(
"refs/heads/basedOnMaster");
target.checkout().setStartPoint("refs/remotes/origin/master").setName(
"master").call();
- targetConfig.setString("branch", "master", "rebase",
- "refs/remotes/origin/master");
- targetConfig.unset("branch", "master", "merge");
+ targetConfig
+ .setString("branch", "master", "merge", "refs/heads/master");
+ targetConfig.setBoolean("branch", "master", "rebase", true);
targetConfig.save();
assertFileContentsEqual(targetFile, "Hello world");
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) {
- doRebase = true;
- }
- }
+ // check if the branch is configured for pull-rebase
+ boolean doRebase = repoConfig.getBoolean(
+ ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
+ ConfigConstants.CONFIG_KEY_REBASE, false);
if (remoteBranchName == null) {
String missingKey = ConfigConstants.CONFIG_BRANCH_SECTION + DOT
JGitText.get().operationCanceled,
JGitText.get().pullTaskName));
+ // 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 (r == null)
+ r = fetchRes.getAdvertisedRef(Constants.R_HEADS
+ + remoteBranchName);
+ }
+ if (r == null)
+ 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);
+ }
+ }
+
PullResult result;
if (doRebase) {
RebaseCommand rebase = new RebaseCommand(repo);
try {
- RebaseResult rebaseRes = rebase.setUpstream(remoteBranchName)
+ RebaseResult rebaseRes = rebase.setUpstream(commitToMerge)
.setProgressMonitor(monitor).setOperation(
Operation.BEGIN).call();
result = new PullResult(fetchRes, remote, rebaseRes);
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 (r == null)
- r = fetchRes.getAdvertisedRef(Constants.R_HEADS
- + remoteBranchName);
- }
- if (r == null)
- 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);
- }
- }
MergeCommand merge = new MergeCommand(repo);
merge.include(
"branch \'" + remoteBranchName + "\' of " + remoteUri,
import org.eclipse.jgit.dircache.DirCacheCheckout;
import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
+import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.NullProgressMonitor;
import org.eclipse.jgit.lib.ObjectId;
return this;
}
+ /**
+ * @param upstream
+ * id of the upstream commit
+ * @return {@code this}
+ */
+ public RebaseCommand setUpstream(AnyObjectId upstream) {
+ try {
+ this.upstreamCommit = walk.parseCommit(upstream);
+ } catch (IOException e) {
+ throw new JGitInternalException(MessageFormat.format(
+ JGitText.get().couldNotReadObjectWhileParsingCommit,
+ upstream.name()), e);
+ }
+ return this;
+ }
+
/**
* @param upstream
* the upstream branch