|
|
@ -73,28 +73,34 @@ 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 |
|
|
|
public void testCheckoutNonExistingBranch() throws Exception { |
|
|
|
public void testCheckoutNonExistingBranch() throws Exception { |
|
|
@ -105,12 +111,14 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
|
|
|
|
|
|
|
|
@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.", |
|
|
|
executeUnchecked("git checkout -b master")); |
|
|
|
executeUnchecked("git checkout -b master")); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCheckoutNewBranchOnBranchToBeBorn() throws Exception { |
|
|
|
public void testCheckoutNewBranchOnBranchToBeBorn() throws Exception { |
|
|
@ -127,14 +135,16 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
|
|
|
|
|
|
|
|
@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(); |
|
|
@ -154,6 +164,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
execute[0]); |
|
|
|
execute[0]); |
|
|
|
assertEquals("\ta", execute[1]); |
|
|
|
assertEquals("\ta", execute[1]); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -174,7 +185,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@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(); |
|
|
@ -197,10 +208,11 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
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'", |
|
|
@ -210,6 +222,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
RevCommit commit = git.commit().setMessage("orphan commit").call(); |
|
|
|
RevCommit commit = git.commit().setMessage("orphan commit").call(); |
|
|
|
assertEquals(0, commit.getParentCount()); |
|
|
|
assertEquals(0, commit.getParentCount()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -231,7 +244,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
@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(); |
|
|
@ -259,6 +272,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
db.getFS()); |
|
|
|
db.getFS()); |
|
|
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); |
|
|
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -279,7 +293,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@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(); |
|
|
@ -304,6 +318,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
db.getFS()); |
|
|
|
db.getFS()); |
|
|
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); |
|
|
|
assertEquals(FileMode.REGULAR_FILE, entry.getMode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -324,7 +339,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@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(); |
|
|
@ -351,6 +366,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
assertEquals("a", exception.getConflictingPaths().get(0)); |
|
|
|
assertEquals("a", exception.getConflictingPaths().get(0)); |
|
|
|
assertEquals("a/c", exception.getConflictingPaths().get(1)); |
|
|
|
assertEquals("a/c", exception.getConflictingPaths().get(1)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -371,7 +387,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
@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"); |
|
|
@ -406,6 +422,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
assertEquals(1, exception.getConflictingPaths().size()); |
|
|
|
assertEquals(1, exception.getConflictingPaths().size()); |
|
|
|
assertEquals("a", exception.getConflictingPaths().get(0)); |
|
|
|
assertEquals("a", exception.getConflictingPaths().get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -427,7 +444,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
@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"); |
|
|
@ -452,6 +469,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
db.getFS()); |
|
|
|
db.getFS()); |
|
|
|
assertEquals(FileMode.TREE, entry.getMode()); |
|
|
|
assertEquals(FileMode.TREE, entry.getMode()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -471,7 +489,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@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(); |
|
|
@ -504,6 +522,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
assertEquals(1, exception.getConflictingPaths().size()); |
|
|
|
assertEquals(1, exception.getConflictingPaths().size()); |
|
|
|
assertEquals("a", exception.getConflictingPaths().get(0)); |
|
|
|
assertEquals("a", exception.getConflictingPaths().get(0)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Steps: |
|
|
|
* Steps: |
|
|
@ -524,7 +543,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@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(); |
|
|
@ -563,10 +582,11 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
// assertEquals("a", exception.getConflictingPaths().get(0));
|
|
|
|
// assertEquals("a", exception.getConflictingPaths().get(0));
|
|
|
|
// assertEquals("a/c", exception.getConflictingPaths().get(1));
|
|
|
|
// 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(); |
|
|
@ -585,6 +605,7 @@ public class CheckoutTest extends CLIRepositoryTestCase { |
|
|
|
execute("git branch")); |
|
|
|
execute("git branch")); |
|
|
|
assertEquals("Hello world b", read(b)); |
|
|
|
assertEquals("Hello world b", read(b)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCheckouSingleFile() throws Exception { |
|
|
|
public void testCheckouSingleFile() throws Exception { |
|
|
|