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 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$ 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 * The folder containing the hashes of (potentially) rewritten commits when
* --preserve-merges is used. * --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$ private static final String REWRITTEN = "rewritten"; //$NON-NLS-1$
@ -289,7 +296,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
} }
this.upstreamCommit = walk.parseCommit(repo this.upstreamCommit = walk.parseCommit(repo
.resolve(upstreamCommitId)); .resolve(upstreamCommitId));
preserveMerges = rebaseState.getRewrittenDir().exists(); preserveMerges = rebaseState.getRewrittenDir().isDirectory();
break; break;
case BEGIN: case BEGIN:
autoStash(); autoStash();
@ -1120,6 +1127,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
repo.writeOrigHead(headId); repo.writeOrigHead(headId);
rebaseState.createFile(REBASE_HEAD, headId.name()); rebaseState.createFile(REBASE_HEAD, headId.name());
rebaseState.createFile(REBASE_HEAD_LEGACY, headId.name());
rebaseState.createFile(HEAD_NAME, headName); rebaseState.createFile(HEAD_NAME, headName);
rebaseState.createFile(ONTO, upstreamCommit.name()); rebaseState.createFile(ONTO, upstreamCommit.name());
rebaseState.createFile(ONTO_NAME, upstreamCommitName); rebaseState.createFile(ONTO_NAME, upstreamCommitName);
@ -1336,8 +1344,8 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
private RebaseResult abort(RebaseResult result) throws IOException, private RebaseResult abort(RebaseResult result) throws IOException,
GitAPIException { GitAPIException {
ObjectId origHead = getOriginalHead();
try { try {
ObjectId origHead = repo.readOrigHead();
String commitId = origHead != null ? origHead.name() : null; String commitId = origHead != null ? origHead.name() : null;
monitor.beginTask(MessageFormat.format( monitor.beginTask(MessageFormat.format(
JGitText.get().abortingRebase, commitId), JGitText.get().abortingRebase, commitId),
@ -1376,7 +1384,7 @@ public class RebaseCommand extends GitCommand<RebaseResult> {
// update the HEAD // update the HEAD
res = refUpdate.link(headName); res = refUpdate.link(headName);
} else { } else {
refUpdate.setNewObjectId(repo.readOrigHead()); refUpdate.setNewObjectId(origHead);
res = refUpdate.forceUpdate(); 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) private boolean checkoutCommit(String headName, RevCommit commit)
throws IOException, throws IOException,
CheckoutConflictException { CheckoutConflictException {

Loading…
Cancel
Save