Browse Source

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
stable-5.4
Thomas Wolf 6 years ago committed by Gerrit Code Review @ Eclipse.org
parent
commit
f491af08ea
  1. 29
      org.eclipse.jgit/src/org/eclipse/jgit/api/RebaseCommand.java

29
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 {

Loading…
Cancel
Save