import org.eclipse.jgit.lib.ReflogEntry;
import org.eclipse.jgit.lib.RepositoryState;
import org.eclipse.jgit.merge.MergeStrategy;
-import org.eclipse.jgit.merge.ResolveMerger.MergeFailureReason;
import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.jgit.util.FileUtils;
// rebase
RebaseResult result = git.rebase().setUpstream("refs/heads/master")
.call();
- assertEquals(Status.CONFLICTS, result.getStatus());
- assertEquals(1, result.getConflicts().size());
- assertEquals("file2", result.getConflicts().get(0));
+ assertEquals(Status.UNCOMMITTED_CHANGES, result.getStatus());
+ assertEquals(1, result.getUncommittedChanges().size());
+ assertEquals("file2", result.getUncommittedChanges().get(0));
}
@Test
RebaseResult result = git.rebase().setUpstream("refs/heads/master")
.call();
- assertEquals(Status.CONFLICTS, result.getStatus());
- assertEquals(1, result.getConflicts().size());
- assertEquals("file2", result.getConflicts().get(0));
+ assertEquals(Status.UNCOMMITTED_CHANGES, result.getStatus());
+ assertEquals(1, result.getUncommittedChanges().size());
+ assertEquals("file2", result.getUncommittedChanges().get(0));
checkFile(uncommittedFile, "uncommitted file2");
assertEquals(RepositoryState.SAFE, git.getRepository().getRepositoryState());
// rebase
RebaseResult result = git.rebase().setUpstream("refs/heads/master")
.call();
- assertEquals(Status.CONFLICTS, result.getStatus());
- assertEquals(1, result.getConflicts().size());
- assertEquals(FILE1, result.getConflicts().get(0));
+ assertEquals(Status.UNCOMMITTED_CHANGES, result.getStatus());
+ assertEquals(1, result.getUncommittedChanges().size());
+ assertEquals(FILE1, result.getUncommittedChanges().get(0));
}
@Test
// rebase
RebaseResult result = git.rebase().setUpstream("refs/heads/master")
.call();
- assertEquals(Status.CONFLICTS, result.getStatus());
- assertEquals(1, result.getConflicts().size());
- assertEquals(FILE1, result.getConflicts().get(0));
+ assertEquals(Status.UNCOMMITTED_CHANGES, result.getStatus());
+ assertEquals(1, result.getUncommittedChanges().size());
+ assertEquals(FILE1, result.getUncommittedChanges().get(0));
}
@Test
writeTrashFile("file0", "unstaged modified file0");
// rebase
- assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master")
+ assertEquals(Status.UNCOMMITTED_CHANGES,
+ git.rebase().setUpstream("refs/heads/master")
.call().getStatus());
}
// rebase
RebaseResult result = git.rebase().setUpstream("refs/heads/master")
.call();
- assertEquals(Status.FAILED, result.getStatus());
- // staged file0 causes DIRTY_INDEX
- assertEquals(1, result.getFailingPaths().size());
- assertEquals(MergeFailureReason.DIRTY_INDEX, result.getFailingPaths()
- .get("file0"));
- assertEquals("unstaged modified file0", read(file0));
+ assertEquals(Status.UNCOMMITTED_CHANGES, result.getStatus());
+ assertEquals(1, result.getUncommittedChanges().size());
// index shall be unchanged
assertEquals(indexState, indexState(CONTENT));
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
writeTrashFile("file0", "unstaged modified file0");
// rebase
- assertEquals(Status.OK, git.rebase().setUpstream("refs/heads/master")
+ assertEquals(Status.UNCOMMITTED_CHANGES,
+ git.rebase().setUpstream("refs/heads/master")
.call().getStatus());
}
// rebase
RebaseResult result = git.rebase().setUpstream("refs/heads/master")
.call();
- assertEquals(Status.FAILED, result.getStatus());
+ assertEquals(Status.UNCOMMITTED_CHANGES, result.getStatus());
// staged file0 causes DIRTY_INDEX
- assertEquals(1, result.getFailingPaths().size());
- assertEquals(MergeFailureReason.DIRTY_INDEX, result.getFailingPaths()
- .get("file0"));
+ assertEquals(1, result.getUncommittedChanges().size());
assertEquals("unstaged modified file0", read(file0));
// index shall be unchanged
assertEquals(indexState, indexState(CONTENT));
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
+ @Test
+ public void testFastForwardRebaseWithModification() throws Exception {
+ // create file0 + file1, add and commit
+ writeTrashFile("file0", "file0");
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern("file0").addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch
+ createBranch(commit, "refs/heads/topic");
+
+ // still on master / modify file1, add and commit
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout topic branch / modify file0 and add to index
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file0", "modified file0 in index");
+ git.add().addFilepattern("file0").addFilepattern(FILE1).call();
+ // modify once more
+ writeTrashFile("file0", "modified file0");
+
+ // rebase
+ RebaseResult result = git.rebase().setUpstream("refs/heads/master")
+ .call();
+ assertEquals(Status.FAST_FORWARD, result.getStatus());
+ checkFile(new File(db.getWorkTree(), "file0"), "modified file0");
+ checkFile(new File(db.getWorkTree(), FILE1), "modified file1");
+ assertEquals("[file0, mode:100644, content:modified file0 in index]"
+ + "[file1, mode:100644, content:modified file1]",
+ indexState(CONTENT));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+ }
+
+ @Test
+ public void testRebaseWithModificationShouldNotDeleteData()
+ throws Exception {
+ // create file0 + file1, add and commit
+ writeTrashFile("file0", "file0");
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern("file0").addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch
+ createBranch(commit, "refs/heads/topic");
+
+ // still on master / modify file1, add and commit
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout topic branch / modify file1, add and commit
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile(FILE1, "modified file1 on topic");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ writeTrashFile("file0", "modified file0");
+
+ RebaseResult result = git.rebase().setUpstream("refs/heads/master")
+ .call();
+ // the following condition was true before commit 83b6ab233:
+ // jgit started the rebase and deleted the change on abort
+ // This test should verify that content was deleted
+ if (result.getStatus() == Status.STOPPED)
+ git.rebase().setOperation(Operation.ABORT).call();
+
+ checkFile(new File(db.getWorkTree(), "file0"), "modified file0");
+ checkFile(new File(db.getWorkTree(), FILE1),
+ "modified file1 on topic");
+ assertEquals("[file0, mode:100644, content:file0]"
+ + "[file1, mode:100644, content:modified file1 on topic]",
+ indexState(CONTENT));
+ }
+
@Test
public void testRebaseWithUncommittedDelete() throws Exception {
// create file0 + file1, add and commit
// and attempt to rebase
RebaseResult rebaseResult = git.rebase()
.setUpstream("refs/heads/master").call();
- assertEquals(Status.CONFLICTS, rebaseResult.getStatus());
- assertEquals(1, rebaseResult.getConflicts().size());
- assertEquals(FILE1, rebaseResult.getConflicts().get(0));
+ assertEquals(Status.UNCOMMITTED_CHANGES, rebaseResult.getStatus());
+ assertEquals(1, rebaseResult.getUncommittedChanges().size());
+ assertEquals(FILE1, rebaseResult.getUncommittedChanges().get(0));
checkFile(theFile, "dirty the file");
}
+ @Test
+ public void testInteractiveRebaseWithModificationShouldNotDeleteDataOnAbort()
+ throws Exception {
+ // create file0 + file1, add and commit
+ writeTrashFile("file0", "file0");
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern("file0").addFilepattern(FILE1).call();
+ git.commit().setMessage("commit1").call();
+
+ // modify file1, add and commit
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit2").call();
+
+ // modify file1, add and commit
+ writeTrashFile(FILE1, "modified file1 a second time");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // modify file0, but do not commit
+ writeTrashFile("file0", "modified file0 in index");
+ git.add().addFilepattern("file0").addFilepattern(FILE1).call();
+ // do not commit
+ writeTrashFile("file0", "modified file0");
+
+ // start rebase
+ RebaseResult result = git.rebase().setUpstream("HEAD~2")
+ .runInteractively(new InteractiveHandler() {
+
+ public void prepareSteps(List<RebaseTodoLine> steps) {
+ steps.get(0).setAction(Action.EDIT);
+ steps.get(1).setAction(Action.PICK);
+ }
+
+ public String modifyCommitMessage(String commit) {
+ return commit;
+ }
+ }).call();
+ // the following condition was true before commit 83b6ab233:
+ // jgit started the rebase and deleted the change on abort
+ // This test should verify that content was deleted
+ if (result.getStatus() == Status.EDIT)
+ git.rebase().setOperation(Operation.ABORT).call();
+
+ checkFile(new File(db.getWorkTree(), "file0"), "modified file0");
+ checkFile(new File(db.getWorkTree(), "file1"),
+ "modified file1 a second time");
+ assertEquals("[file0, mode:100644, content:modified file0 in index]"
+ + "[file1, mode:100644, content:modified file1 a second time]",
+ indexState(CONTENT));
+
+ }
+
private File getTodoFile() {
File todoFile = new File(db.getDirectory(), GIT_REBASE_TODO);
return todoFile;