summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf <thomas.wolf@paranor.ch>2019-02-26 16:22:21 -0500
committerGerrit Code Review @ Eclipse.org <gerrit@eclipse.org>2019-02-26 16:22:22 -0500
commitf491af08ea418268c897c8cb08167c9fdae5be6e (patch)
tree35fd3b0d5467ec62f422fc604ede4e5d224e4240
parent2fe1f0d63840d455cd135ae6e61f588cb01978cf (diff)
parent38e5a75ce49abe7068e4612f4159902114ca951f (diff)
downloadjgit-f491af08ea418268c897c8cb08167c9fdae5be6e.tar.gz
jgit-f491af08ea418268c897c8cb08167c9fdae5be6e.zip
Merge changes from topic 'rebase_compatibility'
* changes: RebaseCommand: tighten check for --preserve-merges on --continue RebaseCommand: use orig-head to abort RebaseCommand: use orig-head in addition to head
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java29
1 files changed, 25 insertions, 4 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
index 416a6c2dfc..0e3d000d3a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java
@@ -162,7 +162,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private static final String PATCH = "patch"; //$NON-NLS-1$
- private static final String REBASE_HEAD = "head"; //$NON-NLS-1$
+ private static final String REBASE_HEAD = "orig-head"; //$NON-NLS-1$
+
+ /** Pre git 1.7.6 file name for {@link #REBASE_HEAD}. */
+ private static final String REBASE_HEAD_LEGACY = "head"; //$NON-NLS-1$
private static final String AMEND = "amend"; //$NON-NLS-1$
@@ -177,6 +180,10 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
/**
* The folder containing the hashes of (potentially) rewritten commits when
* --preserve-merges is used.
+ * <p>
+ * Native git rebase --merge uses a <em>file</em> of that name to record
+ * commits to copy notes at the end of the whole rebase.
+ * </p>
*/
private static final String REWRITTEN = "rewritten"; //$NON-NLS-1$
@@ -289,7 +296,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
}
this.upstreamCommit = walk.parseCommit(repo
.resolve(upstreamCommitId));
- preserveMerges = rebaseState.getRewrittenDir().exists();
+ preserveMerges = rebaseState.getRewrittenDir().isDirectory();
break;
case BEGIN:
autoStash();
@@ -1120,6 +1127,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
repo.writeOrigHead(headId);
rebaseState.createFile(REBASE_HEAD, headId.name());
+ rebaseState.createFile(REBASE_HEAD_LEGACY, headId.name());
rebaseState.createFile(HEAD_NAME, headName);
rebaseState.createFile(ONTO, upstreamCommit.name());
rebaseState.createFile(ONTO_NAME, upstreamCommitName);
@@ -1336,8 +1344,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private RebaseResult abort(RebaseResult result) throws IOException,
GitAPIException {
+ ObjectId origHead = getOriginalHead();
try {
- ObjectId origHead = repo.readOrigHead();
String commitId = origHead != null ? origHead.name() : null;
monitor.beginTask(MessageFormat.format(
JGitText.get().abortingRebase, commitId),
@@ -1376,7 +1384,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
// update the HEAD
res = refUpdate.link(headName);
} else {
- refUpdate.setNewObjectId(repo.readOrigHead());
+ refUpdate.setNewObjectId(origHead);
res = refUpdate.forceUpdate();
}
@@ -1403,6 +1411,19 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
}
}
+ private ObjectId getOriginalHead() throws IOException {
+ try {
+ return ObjectId.fromString(rebaseState.readFile(REBASE_HEAD));
+ } catch (FileNotFoundException e) {
+ try {
+ return ObjectId
+ .fromString(rebaseState.readFile(REBASE_HEAD_LEGACY));
+ } catch (FileNotFoundException ex) {
+ return repo.readOrigHead();
+ }
+ }
+ }
+
private boolean checkoutCommit(String headName, RevCommit commit)
throws IOException,
CheckoutConflictException {