CheckoutTest: Create Git instances in try-with-resource
Change-Id: I49a03f7bee0b61c062ce160674f9aa0cd1bcc8ba Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
This commit is contained in:
parent
9d721de69b
commit
7f84e40f31
|
@ -66,27 +66,33 @@ public class CheckoutTest extends CLIRepositoryTestCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutSelf() throws Exception {
|
public void testCheckoutSelf() throws Exception {
|
||||||
new Git(db).commit().setMessage("initial commit").call();
|
try (Git git = new Git(db)) {
|
||||||
|
git.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
assertStringArrayEquals("Already on 'master'",
|
assertStringArrayEquals("Already on 'master'",
|
||||||
execute("git checkout master"));
|
execute("git checkout master"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutBranch() throws Exception {
|
public void testCheckoutBranch() throws Exception {
|
||||||
new Git(db).commit().setMessage("initial commit").call();
|
try (Git git = new Git(db)) {
|
||||||
new Git(db).branchCreate().setName("side").call();
|
git.commit().setMessage("initial commit").call();
|
||||||
|
git.branchCreate().setName("side").call();
|
||||||
|
|
||||||
assertStringArrayEquals("Switched to branch 'side'",
|
assertStringArrayEquals("Switched to branch 'side'",
|
||||||
execute("git checkout side"));
|
execute("git checkout side"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutNewBranch() throws Exception {
|
public void testCheckoutNewBranch() throws Exception {
|
||||||
new Git(db).commit().setMessage("initial commit").call();
|
try (Git git = new Git(db)) {
|
||||||
|
git.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
assertStringArrayEquals("Switched to a new branch 'side'",
|
assertStringArrayEquals("Switched to a new branch 'side'",
|
||||||
execute("git checkout -b side"));
|
execute("git checkout -b side"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -98,11 +104,13 @@ public void testCheckoutNonExistingBranch() throws Exception {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutNewBranchThatAlreadyExists() throws Exception {
|
public void testCheckoutNewBranchThatAlreadyExists() throws Exception {
|
||||||
new Git(db).commit().setMessage("initial commit").call();
|
try (Git git = new Git(db)) {
|
||||||
|
git.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
assertStringArrayEquals(
|
assertStringArrayEquals(
|
||||||
"fatal: A branch named 'master' already exists.",
|
"fatal: A branch named 'master' already exists.",
|
||||||
execute("git checkout -b master"));
|
execute("git checkout -b master"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -120,32 +128,35 @@ public void testCheckoutUnresolvedHead() throws Exception {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutHead() throws Exception {
|
public void testCheckoutHead() throws Exception {
|
||||||
new Git(db).commit().setMessage("initial commit").call();
|
try (Git git = new Git(db)) {
|
||||||
|
git.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
assertStringArrayEquals("", execute("git checkout HEAD"));
|
assertStringArrayEquals("", execute("git checkout HEAD"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutExistingBranchWithConflict() throws Exception {
|
public void testCheckoutExistingBranchWithConflict() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("a", "Hello world a");
|
writeTrashFile("a", "Hello world a");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("commit file a").call();
|
git.commit().setMessage("commit file a").call();
|
||||||
git.branchCreate().setName("branch_1").call();
|
git.branchCreate().setName("branch_1").call();
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
||||||
writeTrashFile("a/b", "Hello world b");
|
writeTrashFile("a/b", "Hello world b");
|
||||||
git.add().addFilepattern("a/b").call();
|
git.add().addFilepattern("a/b").call();
|
||||||
git.commit().setMessage("commit folder a").call();
|
git.commit().setMessage("commit folder a").call();
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
writeTrashFile("a", "New Hello world a");
|
writeTrashFile("a", "New Hello world a");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
|
|
||||||
String[] execute = execute("git checkout branch_1");
|
String[] execute = execute("git checkout branch_1");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"error: Your local changes to the following files would be overwritten by checkout:",
|
"error: Your local changes to the following files would be overwritten by checkout:",
|
||||||
execute[0]);
|
execute[0]);
|
||||||
assertEquals("\ta", execute[1]);
|
assertEquals("\ta", execute[1]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -167,41 +178,43 @@ public void testCheckoutExistingBranchWithConflict() throws Exception {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutWithMissingWorkingTreeFile() throws Exception {
|
public void testCheckoutWithMissingWorkingTreeFile() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
File fileA = writeTrashFile("a", "Hello world a");
|
File fileA = writeTrashFile("a", "Hello world a");
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add files a & b").call();
|
git.commit().setMessage("add files a & b").call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
git.add().addFilepattern("a").call();
|
git.add().addFilepattern("a").call();
|
||||||
git.commit().setMessage("modify file a").call();
|
git.commit().setMessage("modify file a").call();
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
|
||||||
FileUtils.delete(fileA);
|
FileUtils.delete(fileA);
|
||||||
|
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
|
|
||||||
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
||||||
db.getFS());
|
db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
assertEquals("Hello world a", read(fileA));
|
assertEquals("Hello world a", read(fileA));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutOrphan() throws Exception {
|
public void testCheckoutOrphan() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
git.commit().setMessage("initial commit").call();
|
git.commit().setMessage("initial commit").call();
|
||||||
|
|
||||||
assertStringArrayEquals("Switched to a new branch 'new_branch'",
|
assertStringArrayEquals("Switched to a new branch 'new_branch'",
|
||||||
execute("git checkout --orphan new_branch"));
|
execute("git checkout --orphan new_branch"));
|
||||||
assertEquals("refs/heads/new_branch",
|
assertEquals("refs/heads/new_branch",
|
||||||
db.exactRef("HEAD").getTarget().getName());
|
db.exactRef("HEAD").getTarget().getName());
|
||||||
RevCommit commit = git.commit().setMessage("orphan commit").call();
|
RevCommit commit = git.commit().setMessage("orphan commit").call();
|
||||||
assertEquals(0, commit.getParentCount());
|
assertEquals(0, commit.getParentCount());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -224,33 +237,34 @@ public void testCheckoutOrphan() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void fileModeTestMissingThenFolderWithFileInWorkingTree()
|
public void fileModeTestMissingThenFolderWithFileInWorkingTree()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add file b").call();
|
git.commit().setMessage("add file b").call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
File folderA = new File(db.getWorkTree(), "a");
|
File folderA = new File(db.getWorkTree(), "a");
|
||||||
FileUtils.mkdirs(folderA);
|
FileUtils.mkdirs(folderA);
|
||||||
writeTrashFile("a/c", "Hello world c");
|
writeTrashFile("a/c", "Hello world c");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add folder a").call();
|
git.commit().setMessage("add folder a").call();
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.TREE, entry.getMode());
|
assertEquals(FileMode.TREE, entry.getMode());
|
||||||
|
|
||||||
FileUtils.delete(folderA, FileUtils.RECURSIVE);
|
FileUtils.delete(folderA, FileUtils.RECURSIVE);
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
|
|
||||||
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
||||||
db.getFS());
|
db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
|
|
||||||
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
||||||
db.getFS());
|
db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -272,30 +286,31 @@ public void fileModeTestMissingThenFolderWithFileInWorkingTree()
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void fileModeTestFolderWithMissingInWorkingTree() throws Exception {
|
public void fileModeTestFolderWithMissingInWorkingTree() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add file b & file a").call();
|
git.commit().setMessage("add file b & file a").call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
File folderA = new File(db.getWorkTree(), "a");
|
File folderA = new File(db.getWorkTree(), "a");
|
||||||
FileUtils.mkdirs(folderA);
|
FileUtils.mkdirs(folderA);
|
||||||
writeTrashFile("a/c", "Hello world c");
|
writeTrashFile("a/c", "Hello world c");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add folder a").call();
|
git.commit().setMessage("add folder a").call();
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.TREE, entry.getMode());
|
assertEquals(FileMode.TREE, entry.getMode());
|
||||||
|
|
||||||
FileUtils.delete(folderA, FileUtils.RECURSIVE);
|
FileUtils.delete(folderA, FileUtils.RECURSIVE);
|
||||||
|
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
|
|
||||||
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
||||||
db.getFS());
|
db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -317,32 +332,33 @@ public void fileModeTestFolderWithMissingInWorkingTree() throws Exception {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void fileModeTestMissingWithFolderInWorkingTree() throws Exception {
|
public void fileModeTestMissingWithFolderInWorkingTree() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add file b & file a").call();
|
git.commit().setMessage("add file b & file a").call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
git.commit().setMessage("delete file a").call();
|
git.commit().setMessage("delete file a").call();
|
||||||
|
|
||||||
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
||||||
writeTrashFile("a/c", "Hello world c");
|
writeTrashFile("a/c", "Hello world c");
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.TREE, entry.getMode());
|
assertEquals(FileMode.TREE, entry.getMode());
|
||||||
|
|
||||||
CheckoutConflictException exception = null;
|
CheckoutConflictException exception = null;
|
||||||
try {
|
try {
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
} catch (CheckoutConflictException e) {
|
} catch (CheckoutConflictException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
|
}
|
||||||
|
assertNotNull(exception);
|
||||||
|
assertEquals(2, exception.getConflictingPaths().size());
|
||||||
|
assertEquals("a", exception.getConflictingPaths().get(0));
|
||||||
|
assertEquals("a/c", exception.getConflictingPaths().get(1));
|
||||||
}
|
}
|
||||||
assertNotNull(exception);
|
|
||||||
assertEquals(2, exception.getConflictingPaths().size());
|
|
||||||
assertEquals("a", exception.getConflictingPaths().get(0));
|
|
||||||
assertEquals("a/c", exception.getConflictingPaths().get(1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -364,40 +380,41 @@ public void fileModeTestMissingWithFolderInWorkingTree() throws Exception {
|
||||||
@Test
|
@Test
|
||||||
public void fileModeTestFolderThenMissingWithFileInWorkingTree()
|
public void fileModeTestFolderThenMissingWithFileInWorkingTree()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
||||||
writeTrashFile("a/c", "Hello world c");
|
writeTrashFile("a/c", "Hello world c");
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
RevCommit commit1 = git.commit().setMessage("add folder a & file b")
|
RevCommit commit1 = git.commit().setMessage("add folder a & file b")
|
||||||
.call();
|
.call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
RevCommit commit2 = git.commit().setMessage("delete folder a").call();
|
RevCommit commit2 = git.commit().setMessage("delete folder a").call();
|
||||||
|
|
||||||
TreeWalk tw = new TreeWalk(db);
|
TreeWalk tw = new TreeWalk(db);
|
||||||
tw.addTree(commit1.getTree());
|
tw.addTree(commit1.getTree());
|
||||||
tw.addTree(commit2.getTree());
|
tw.addTree(commit2.getTree());
|
||||||
List<DiffEntry> scan = DiffEntry.scan(tw);
|
List<DiffEntry> scan = DiffEntry.scan(tw);
|
||||||
assertEquals(1, scan.size());
|
assertEquals(1, scan.size());
|
||||||
assertEquals(FileMode.MISSING, scan.get(0).getNewMode());
|
assertEquals(FileMode.MISSING, scan.get(0).getNewMode());
|
||||||
assertEquals(FileMode.TREE, scan.get(0).getOldMode());
|
assertEquals(FileMode.TREE, scan.get(0).getOldMode());
|
||||||
|
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
|
||||||
CheckoutConflictException exception = null;
|
CheckoutConflictException exception = null;
|
||||||
try {
|
try {
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
} catch (CheckoutConflictException e) {
|
} catch (CheckoutConflictException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
|
}
|
||||||
|
assertNotNull(exception);
|
||||||
|
assertEquals(1, exception.getConflictingPaths().size());
|
||||||
|
assertEquals("a", exception.getConflictingPaths().get(0));
|
||||||
}
|
}
|
||||||
assertNotNull(exception);
|
|
||||||
assertEquals(1, exception.getConflictingPaths().size());
|
|
||||||
assertEquals("a", exception.getConflictingPaths().get(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -420,30 +437,31 @@ public void fileModeTestFolderThenMissingWithFileInWorkingTree()
|
||||||
@Test
|
@Test
|
||||||
public void fileModeTestFolderThenFileWithMissingInWorkingTree()
|
public void fileModeTestFolderThenFileWithMissingInWorkingTree()
|
||||||
throws Exception {
|
throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
||||||
writeTrashFile("a/c", "Hello world c");
|
writeTrashFile("a/c", "Hello world c");
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add folder a & file b").call();
|
git.commit().setMessage("add folder a & file b").call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
File fileA = new File(db.getWorkTree(), "a");
|
File fileA = new File(db.getWorkTree(), "a");
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
git.add().addFilepattern("a").call();
|
git.add().addFilepattern("a").call();
|
||||||
git.commit().setMessage("add file a").call();
|
git.commit().setMessage("add file a").call();
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
|
||||||
FileUtils.delete(fileA);
|
FileUtils.delete(fileA);
|
||||||
|
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
|
|
||||||
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
||||||
db.getFS());
|
db.getFS());
|
||||||
assertEquals(FileMode.TREE, entry.getMode());
|
assertEquals(FileMode.TREE, entry.getMode());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -464,38 +482,39 @@ public void fileModeTestFolderThenFileWithMissingInWorkingTree()
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void fileModeTestFileThenFileWithFolderInIndex() throws Exception {
|
public void fileModeTestFileThenFileWithFolderInIndex() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("a", "Hello world a");
|
writeTrashFile("a", "Hello world a");
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add files a & b").call();
|
git.commit().setMessage("add files a & b").call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
git.add().addFilepattern("a").call();
|
git.add().addFilepattern("a").call();
|
||||||
git.commit().setMessage("add file a").call();
|
git.commit().setMessage("add file a").call();
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
||||||
writeTrashFile("a/c", "Hello world c");
|
writeTrashFile("a/c", "Hello world c");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
|
|
||||||
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
||||||
db.getFS());
|
db.getFS());
|
||||||
assertEquals(FileMode.TREE, entry.getMode());
|
assertEquals(FileMode.TREE, entry.getMode());
|
||||||
|
|
||||||
CheckoutConflictException exception = null;
|
CheckoutConflictException exception = null;
|
||||||
try {
|
try {
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
} catch (CheckoutConflictException e) {
|
} catch (CheckoutConflictException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
|
}
|
||||||
|
assertNotNull(exception);
|
||||||
|
assertEquals(1, exception.getConflictingPaths().size());
|
||||||
|
assertEquals("a", exception.getConflictingPaths().get(0));
|
||||||
}
|
}
|
||||||
assertNotNull(exception);
|
|
||||||
assertEquals(1, exception.getConflictingPaths().size());
|
|
||||||
assertEquals("a", exception.getConflictingPaths().get(0));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -517,65 +536,67 @@ public void fileModeTestFileThenFileWithFolderInIndex() throws Exception {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void fileModeTestFileWithFolderInIndex() throws Exception {
|
public void fileModeTestFileWithFolderInIndex() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("b", "Hello world b");
|
writeTrashFile("b", "Hello world b");
|
||||||
writeTrashFile("a", "b");
|
writeTrashFile("a", "b");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("add file b & file a").call();
|
git.commit().setMessage("add file b & file a").call();
|
||||||
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
Ref branch_1 = git.branchCreate().setName("branch_1").call();
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
writeTrashFile("a", "Hello world a");
|
writeTrashFile("a", "Hello world a");
|
||||||
git.add().addFilepattern("a").call();
|
git.add().addFilepattern("a").call();
|
||||||
git.commit().setMessage("add file a").call();
|
git.commit().setMessage("add file a").call();
|
||||||
|
|
||||||
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
FileEntry entry = new FileTreeIterator.FileEntry(new File(
|
||||||
db.getWorkTree(), "a"), db.getFS());
|
db.getWorkTree(), "a"), db.getFS());
|
||||||
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
|
||||||
|
|
||||||
git.rm().addFilepattern("a").call();
|
git.rm().addFilepattern("a").call();
|
||||||
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
|
||||||
writeTrashFile("a/c", "Hello world c");
|
writeTrashFile("a/c", "Hello world c");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
|
|
||||||
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"),
|
||||||
db.getFS());
|
db.getFS());
|
||||||
assertEquals(FileMode.TREE, entry.getMode());
|
assertEquals(FileMode.TREE, entry.getMode());
|
||||||
|
|
||||||
CheckoutConflictException exception = null;
|
CheckoutConflictException exception = null;
|
||||||
try {
|
try {
|
||||||
git.checkout().setName(branch_1.getName()).call();
|
git.checkout().setName(branch_1.getName()).call();
|
||||||
} catch (CheckoutConflictException e) {
|
} catch (CheckoutConflictException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
|
}
|
||||||
|
assertNotNull(exception);
|
||||||
|
assertEquals(1, exception.getConflictingPaths().size());
|
||||||
|
assertEquals("a", exception.getConflictingPaths().get(0));
|
||||||
|
|
||||||
|
// TODO: ideally we'd like to get two paths from this exception
|
||||||
|
// assertEquals(2, exception.getConflictingPaths().size());
|
||||||
|
// assertEquals("a", exception.getConflictingPaths().get(0));
|
||||||
|
// assertEquals("a/c", exception.getConflictingPaths().get(1));
|
||||||
}
|
}
|
||||||
assertNotNull(exception);
|
|
||||||
assertEquals(1, exception.getConflictingPaths().size());
|
|
||||||
assertEquals("a", exception.getConflictingPaths().get(0));
|
|
||||||
|
|
||||||
// TODO: ideally we'd like to get two paths from this exception
|
|
||||||
// assertEquals(2, exception.getConflictingPaths().size());
|
|
||||||
// assertEquals("a", exception.getConflictingPaths().get(0));
|
|
||||||
// assertEquals("a/c", exception.getConflictingPaths().get(1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCheckoutPath() throws Exception {
|
public void testCheckoutPath() throws Exception {
|
||||||
Git git = new Git(db);
|
try (Git git = new Git(db)) {
|
||||||
writeTrashFile("a", "Hello world a");
|
writeTrashFile("a", "Hello world a");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("commit file a").call();
|
git.commit().setMessage("commit file a").call();
|
||||||
git.branchCreate().setName("branch_1").call();
|
git.branchCreate().setName("branch_1").call();
|
||||||
git.checkout().setName("branch_1").call();
|
git.checkout().setName("branch_1").call();
|
||||||
File b = writeTrashFile("b", "Hello world b");
|
File b = writeTrashFile("b", "Hello world b");
|
||||||
git.add().addFilepattern("b").call();
|
git.add().addFilepattern("b").call();
|
||||||
git.commit().setMessage("commit file b").call();
|
git.commit().setMessage("commit file b").call();
|
||||||
File a = writeTrashFile("a", "New Hello world a");
|
File a = writeTrashFile("a", "New Hello world a");
|
||||||
git.add().addFilepattern(".").call();
|
git.add().addFilepattern(".").call();
|
||||||
git.commit().setMessage("modified a").call();
|
git.commit().setMessage("modified a").call();
|
||||||
assertArrayEquals(new String[] { "" },
|
assertArrayEquals(new String[] { "" },
|
||||||
execute("git checkout HEAD~2 -- a"));
|
execute("git checkout HEAD~2 -- a"));
|
||||||
assertEquals("Hello world a", read(a));
|
assertEquals("Hello world a", read(a));
|
||||||
assertArrayEquals(new String[] { "* branch_1", " master", "" },
|
assertArrayEquals(new String[] { "* branch_1", " master", "" },
|
||||||
execute("git branch"));
|
execute("git branch"));
|
||||||
assertEquals("Hello world b", read(b));
|
assertEquals("Hello world b", read(b));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue