Proper handling of rebase during pull
After consulting with Christian Halstrick, it turned out that the handling of rebase during pull was implemented incorrectly. Change-Id: I40f03409e080cdfeceb21460150f5e02a016e7f4 Signed-off-by: Mathias Kinzler <mathias.kinzler@sap.com>
This commit is contained in:
parent
9ffcf2a8b3
commit
b15b9d5df2
|
@ -140,8 +140,9 @@ public void testPullLocalConflict() throws Exception {
|
||||||
.call();
|
.call();
|
||||||
StoredConfig config = target.getRepository().getConfig();
|
StoredConfig config = target.getRepository().getConfig();
|
||||||
config.setString("branch", "basedOnMaster", "remote", ".");
|
config.setString("branch", "basedOnMaster", "remote", ".");
|
||||||
config.setString("branch", "basedOnMaster", "rebase",
|
config.setString("branch", "basedOnMaster", "merge",
|
||||||
"refs/heads/master");
|
"refs/heads/master");
|
||||||
|
config.setBoolean("branch", "basedOnMaster", "rebase", true);
|
||||||
config.save();
|
config.save();
|
||||||
target.getRepository().updateRef(Constants.HEAD).link(
|
target.getRepository().updateRef(Constants.HEAD).link(
|
||||||
"refs/heads/basedOnMaster");
|
"refs/heads/basedOnMaster");
|
||||||
|
@ -212,9 +213,9 @@ public void setUp() throws Exception {
|
||||||
target.checkout().setStartPoint("refs/remotes/origin/master").setName(
|
target.checkout().setStartPoint("refs/remotes/origin/master").setName(
|
||||||
"master").call();
|
"master").call();
|
||||||
|
|
||||||
targetConfig.setString("branch", "master", "rebase",
|
targetConfig
|
||||||
"refs/remotes/origin/master");
|
.setString("branch", "master", "merge", "refs/heads/master");
|
||||||
targetConfig.unset("branch", "master", "merge");
|
targetConfig.setBoolean("branch", "master", "rebase", true);
|
||||||
targetConfig.save();
|
targetConfig.save();
|
||||||
|
|
||||||
assertFileContentsEqual(targetFile, "Hello world");
|
assertFileContentsEqual(targetFile, "Hello world");
|
||||||
|
|
|
@ -122,6 +122,7 @@ couldNotDeleteTemporaryIndexFileShouldNotHappen=Could not delete temporary index
|
||||||
couldNotGetAdvertisedRef=Could not get advertised Ref for branch {0}
|
couldNotGetAdvertisedRef=Could not get advertised Ref for branch {0}
|
||||||
couldNotLockHEAD=Could not lock HEAD
|
couldNotLockHEAD=Could not lock HEAD
|
||||||
couldNotReadIndexInOneGo=Could not read index in one go, only {0} out of {1} read
|
couldNotReadIndexInOneGo=Could not read index in one go, only {0} out of {1} read
|
||||||
|
couldNotReadObjectWhileParsingCommit=Could not read an object while parsing commit {0}
|
||||||
couldNotRenameDeleteOldIndex=Could not rename delete old index
|
couldNotRenameDeleteOldIndex=Could not rename delete old index
|
||||||
couldNotRenameTemporaryFile=Could not rename temporary file {0} to new location {1}
|
couldNotRenameTemporaryFile=Could not rename temporary file {0} to new location {1}
|
||||||
couldNotRenameTemporaryIndexFileToIndex=Could not rename temporary index file to index
|
couldNotRenameTemporaryIndexFileToIndex=Could not rename temporary index file to index
|
||||||
|
|
|
@ -182,6 +182,7 @@ public static JGitText get() {
|
||||||
/***/ public String couldNotGetAdvertisedRef;
|
/***/ public String couldNotGetAdvertisedRef;
|
||||||
/***/ public String couldNotLockHEAD;
|
/***/ public String couldNotLockHEAD;
|
||||||
/***/ public String couldNotReadIndexInOneGo;
|
/***/ public String couldNotReadIndexInOneGo;
|
||||||
|
/***/ public String couldNotReadObjectWhileParsingCommit;
|
||||||
/***/ public String couldNotRenameDeleteOldIndex;
|
/***/ public String couldNotRenameDeleteOldIndex;
|
||||||
/***/ public String couldNotRenameTemporaryFile;
|
/***/ public String couldNotRenameTemporaryFile;
|
||||||
/***/ public String couldNotRenameTemporaryIndexFileToIndex;
|
/***/ public String couldNotRenameTemporaryIndexFileToIndex;
|
||||||
|
|
|
@ -181,16 +181,10 @@ public PullResult call() throws WrongRepositoryStateException,
|
||||||
String remoteBranchName = repoConfig.getString(
|
String remoteBranchName = repoConfig.getString(
|
||||||
ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
|
ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
|
||||||
ConfigConstants.CONFIG_KEY_MERGE);
|
ConfigConstants.CONFIG_KEY_MERGE);
|
||||||
boolean doRebase = false;
|
// check if the branch is configured for pull-rebase
|
||||||
if (remoteBranchName == null) {
|
boolean doRebase = repoConfig.getBoolean(
|
||||||
// check if the branch is configured for pull-rebase
|
ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
|
||||||
remoteBranchName = repoConfig.getString(
|
ConfigConstants.CONFIG_KEY_REBASE, false);
|
||||||
ConfigConstants.CONFIG_BRANCH_SECTION, branchName,
|
|
||||||
ConfigConstants.CONFIG_KEY_REBASE);
|
|
||||||
if (remoteBranchName != null) {
|
|
||||||
doRebase = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (remoteBranchName == null) {
|
if (remoteBranchName == null) {
|
||||||
String missingKey = ConfigConstants.CONFIG_BRANCH_SECTION + DOT
|
String missingKey = ConfigConstants.CONFIG_BRANCH_SECTION + DOT
|
||||||
|
@ -237,11 +231,38 @@ public PullResult call() throws WrongRepositoryStateException,
|
||||||
JGitText.get().operationCanceled,
|
JGitText.get().operationCanceled,
|
||||||
JGitText.get().pullTaskName));
|
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;
|
PullResult result;
|
||||||
if (doRebase) {
|
if (doRebase) {
|
||||||
RebaseCommand rebase = new RebaseCommand(repo);
|
RebaseCommand rebase = new RebaseCommand(repo);
|
||||||
try {
|
try {
|
||||||
RebaseResult rebaseRes = rebase.setUpstream(remoteBranchName)
|
RebaseResult rebaseRes = rebase.setUpstream(commitToMerge)
|
||||||
.setProgressMonitor(monitor).setOperation(
|
.setProgressMonitor(monitor).setOperation(
|
||||||
Operation.BEGIN).call();
|
Operation.BEGIN).call();
|
||||||
result = new PullResult(fetchRes, remote, rebaseRes);
|
result = new PullResult(fetchRes, remote, rebaseRes);
|
||||||
|
@ -255,34 +276,6 @@ public PullResult call() throws WrongRepositoryStateException,
|
||||||
throw new JGitInternalException(e.getMessage(), e);
|
throw new JGitInternalException(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
} else {
|
} 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);
|
MergeCommand merge = new MergeCommand(repo);
|
||||||
merge.include(
|
merge.include(
|
||||||
"branch \'" + remoteBranchName + "\' of " + remoteUri,
|
"branch \'" + remoteBranchName + "\' of " + remoteUri,
|
||||||
|
|
|
@ -75,6 +75,7 @@
|
||||||
import org.eclipse.jgit.dircache.DirCacheCheckout;
|
import org.eclipse.jgit.dircache.DirCacheCheckout;
|
||||||
import org.eclipse.jgit.dircache.DirCacheIterator;
|
import org.eclipse.jgit.dircache.DirCacheIterator;
|
||||||
import org.eclipse.jgit.lib.AbbreviatedObjectId;
|
import org.eclipse.jgit.lib.AbbreviatedObjectId;
|
||||||
|
import org.eclipse.jgit.lib.AnyObjectId;
|
||||||
import org.eclipse.jgit.lib.Constants;
|
import org.eclipse.jgit.lib.Constants;
|
||||||
import org.eclipse.jgit.lib.NullProgressMonitor;
|
import org.eclipse.jgit.lib.NullProgressMonitor;
|
||||||
import org.eclipse.jgit.lib.ObjectId;
|
import org.eclipse.jgit.lib.ObjectId;
|
||||||
|
@ -828,6 +829,22 @@ public RebaseCommand setUpstream(RevCommit upstream) {
|
||||||
return this;
|
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
|
* @param upstream
|
||||||
* the upstream branch
|
* the upstream branch
|
||||||
|
|
Loading…
Reference in New Issue