import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
+import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import org.eclipse.jgit.api.MergeResult.MergeStatus;
import org.eclipse.jgit.api.RebaseCommand.InteractiveHandler;
import org.eclipse.jgit.errors.IllegalTodoFileModification;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.events.ListenerHandle;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.eclipse.jgit.lib.AbbreviatedObjectId;
import org.eclipse.jgit.lib.ConfigConstants;
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
+ @Test
+ public void testRebaseWithAutoStashAndSubdirs() throws Exception {
+ // create file0, add and commit
+ db.getConfig().setBoolean(ConfigConstants.CONFIG_REBASE_SECTION, null,
+ ConfigConstants.CONFIG_KEY_AUTOSTASH, true);
+ writeTrashFile("sub/file0", "file0");
+ git.add().addFilepattern("sub/file0").call();
+ git.commit().setMessage("commit0").call();
+ // create file1, add and commit
+ writeTrashFile(FILE1, "file1");
+ git.add().addFilepattern(FILE1).call();
+ RevCommit commit = git.commit().setMessage("commit1").call();
+
+ // create topic branch and checkout / create file2, add and commit
+ createBranch(commit, "refs/heads/topic");
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("file2", "file2");
+ git.add().addFilepattern("file2").call();
+ git.commit().setMessage("commit2").call();
+
+ // checkout master branch / modify file1, add and commit
+ checkoutBranch("refs/heads/master");
+ writeTrashFile(FILE1, "modified file1");
+ git.add().addFilepattern(FILE1).call();
+ git.commit().setMessage("commit3").call();
+
+ // checkout topic branch / modify file0
+ checkoutBranch("refs/heads/topic");
+ writeTrashFile("sub/file0", "unstaged modified file0");
+
+ Set<String> modifiedFiles = new HashSet<>();
+ ListenerHandle handle = db.getListenerList()
+ .addWorkingTreeModifiedListener(
+ event -> modifiedFiles.addAll(event.getModified()));
+ try {
+ // rebase
+ assertEquals(Status.OK, git.rebase()
+ .setUpstream("refs/heads/master").call().getStatus());
+ } finally {
+ handle.remove();
+ }
+ checkFile(new File(new File(db.getWorkTree(), "sub"), "file0"),
+ "unstaged modified file0");
+ checkFile(new File(db.getWorkTree(), FILE1), "modified file1");
+ checkFile(new File(db.getWorkTree(), "file2"), "file2");
+ assertEquals(
+ "[file1, mode:100644, content:modified file1]"
+ + "[file2, mode:100644, content:file2]"
+ + "[sub/file0, mode:100644, content:file0]",
+ indexState(CONTENT));
+ assertEquals(RepositoryState.SAFE, db.getRepositoryState());
+ List<String> modified = new ArrayList<>(modifiedFiles);
+ Collections.sort(modified);
+ assertEquals("[file1, sub/file0]", modified.toString());
+ }
+
@Test
public void testRebaseWithAutoStashConflictOnApply() throws Exception {
// create file0, add and commit
return true;
} else {
// we want THEIRS ... but THEIRS contains a folder or the
- // deletion of the path. Delete what's in the workingtree (the
- // workingtree is clean) but do not complain if the file is
- // already deleted locally. This complements the test in
- // isWorktreeDirty() for the same case.
- if (tw.getTreeCount() > T_FILE && tw.getRawMode(T_FILE) == 0)
+ // deletion of the path. Delete what's in the working tree,
+ // which we know to be clean.
+ if (tw.getTreeCount() > T_FILE && tw.getRawMode(T_FILE) == 0) {
+ // Not present in working tree, so nothing to delete
return true;
+ }
+ if (modeT != 0 && modeT == modeB) {
+ // Base, ours, and theirs all contain a folder: don't delete
+ return true;
+ }
toBeDeleted.add(tw.getPathString());
return true;
}