Rebase interactive should finish if last step is edit
When the last step was an edit step, rebase interactive did not finish after continuing the rebase. Instead, it returned with the status FAST_FORWARD. Change-Id: Ib19857474ac089dfeaae665ad5e95c66c21099b0
This commit is contained in:
parent
34fbd814d4
commit
18069ffe8c
|
@ -2294,6 +2294,39 @@ public String modifyCommitMessage(String commit) {
|
||||||
}).call();
|
}).call();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRebaseEndsIfLastStepIsEdit() throws Exception {
|
||||||
|
// create file1 on master
|
||||||
|
writeTrashFile(FILE1, FILE1);
|
||||||
|
git.add().addFilepattern(FILE1).call();
|
||||||
|
git.commit().setMessage("Add file1\nnew line").call();
|
||||||
|
assertTrue(new File(db.getWorkTree(), FILE1).exists());
|
||||||
|
|
||||||
|
// create file2 on master
|
||||||
|
writeTrashFile("file2", "file2");
|
||||||
|
git.add().addFilepattern("file2").call();
|
||||||
|
git.commit().setMessage("Add file2\nnew line").call();
|
||||||
|
assertTrue(new File(db.getWorkTree(), "file2").exists());
|
||||||
|
|
||||||
|
git.rebase().setUpstream("HEAD~1")
|
||||||
|
.runInteractively(new InteractiveHandler() {
|
||||||
|
|
||||||
|
public void prepareSteps(List<RebaseTodoLine> steps) {
|
||||||
|
steps.get(0).setAction(Action.EDIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String modifyCommitMessage(String commit) {
|
||||||
|
return commit;
|
||||||
|
}
|
||||||
|
}).call();
|
||||||
|
git.commit().setAmend(true)
|
||||||
|
.setMessage("Add file2\nnew line\nanother line").call();
|
||||||
|
RebaseResult result = git.rebase().setOperation(Operation.CONTINUE)
|
||||||
|
.call();
|
||||||
|
assertEquals(Status.OK, result.getStatus());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private File getTodoFile() {
|
private File getTodoFile() {
|
||||||
File todoFile = new File(db.getDirectory(), GIT_REBASE_TODO);
|
File todoFile = new File(db.getDirectory(), GIT_REBASE_TODO);
|
||||||
return todoFile;
|
return todoFile;
|
||||||
|
|
|
@ -284,6 +284,9 @@ public RebaseResult call() throws GitAPIException, NoHeadException,
|
||||||
|
|
||||||
List<RebaseTodoLine> steps = repo.readRebaseTodo(
|
List<RebaseTodoLine> steps = repo.readRebaseTodo(
|
||||||
rebaseState.getPath(GIT_REBASE_TODO), false);
|
rebaseState.getPath(GIT_REBASE_TODO), false);
|
||||||
|
if (steps.size() == 0) {
|
||||||
|
return finishRebase(walk.parseCommit(repo.resolve(Constants.HEAD)), false);
|
||||||
|
}
|
||||||
if (isInteractive()) {
|
if (isInteractive()) {
|
||||||
interactiveHandler.prepareSteps(steps);
|
interactiveHandler.prepareSteps(steps);
|
||||||
repo.writeRebaseTodoFile(rebaseState.getPath(GIT_REBASE_TODO),
|
repo.writeRebaseTodoFile(rebaseState.getPath(GIT_REBASE_TODO),
|
||||||
|
@ -370,15 +373,7 @@ public RebaseResult call() throws GitAPIException, NoHeadException,
|
||||||
monitor.endTask();
|
monitor.endTask();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (newHead != null) {
|
return finishRebase(newHead, lastStepWasForward);
|
||||||
String headName = rebaseState.readFile(HEAD_NAME);
|
|
||||||
updateHead(headName, newHead, upstreamCommit);
|
|
||||||
FileUtils.delete(rebaseState.getDir(), FileUtils.RECURSIVE);
|
|
||||||
if (lastStepWasForward)
|
|
||||||
return RebaseResult.FAST_FORWARD_RESULT;
|
|
||||||
return RebaseResult.OK_RESULT;
|
|
||||||
}
|
|
||||||
return RebaseResult.FAST_FORWARD_RESULT;
|
|
||||||
} catch (CheckoutConflictException cce) {
|
} catch (CheckoutConflictException cce) {
|
||||||
return new RebaseResult(cce.getConflictingPaths());
|
return new RebaseResult(cce.getConflictingPaths());
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
|
@ -386,6 +381,16 @@ public RebaseResult call() throws GitAPIException, NoHeadException,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private RebaseResult finishRebase(RevCommit newHead,
|
||||||
|
boolean lastStepWasForward) throws IOException {
|
||||||
|
String headName = rebaseState.readFile(HEAD_NAME);
|
||||||
|
updateHead(headName, newHead, upstreamCommit);
|
||||||
|
FileUtils.delete(rebaseState.getDir(), FileUtils.RECURSIVE);
|
||||||
|
if (lastStepWasForward || newHead == null)
|
||||||
|
return RebaseResult.FAST_FORWARD_RESULT;
|
||||||
|
return RebaseResult.OK_RESULT;
|
||||||
|
}
|
||||||
|
|
||||||
private void checkSteps(List<RebaseTodoLine> steps)
|
private void checkSteps(List<RebaseTodoLine> steps)
|
||||||
throws InvalidRebaseStepException, IOException {
|
throws InvalidRebaseStepException, IOException {
|
||||||
if (steps.isEmpty())
|
if (steps.isEmpty())
|
||||||
|
|
Loading…
Reference in New Issue