diff options
author | Christian Halstrick <christian.halstrick@sap.com> | 2014-02-25 17:29:45 +0100 |
---|---|---|
committer | Christian Halstrick <christian.halstrick@sap.com> | 2014-02-26 15:35:05 +0100 |
commit | 73c8e70797c5517972d06f03f2aadfb9aacfb223 (patch) | |
tree | f52d65a378f635a4b5f22b09d702a95286dc7308 /org.eclipse.jgit.pgm.test/tst/org/eclipse | |
parent | ea16c2afff85b7659391f1c418b2272c5a02bd5e (diff) | |
download | jgit-73c8e70797c5517972d06f03f2aadfb9aacfb223.tar.gz jgit-73c8e70797c5517972d06f03f2aadfb9aacfb223.zip |
Don't raise checkout conflict for file missing in working tree
During a checkout we want to prevent to overwrite unsaved local file
content. Jgit was therefore checking whether the file to overwrite is
dirty or missing and would raise a conflict if this was the case. That
was wrong. It should only check if the file is dirty. It's ok to
"overwrite" a missing/non-existing file.
Change-Id: I63c3a94f663c87f09170fdf8b1b1bf4ed5246fc5
Signed-off-by: Christian Halstrick <christian.halstrick@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse')
-rw-r--r-- | org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java index a6ea48c0ea..8012893f92 100644 --- a/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java +++ b/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java @@ -46,6 +46,10 @@ import java.io.File; import org.eclipse.jgit.api.Git; import org.eclipse.jgit.lib.CLIRepositoryTestCase; +import org.eclipse.jgit.lib.FileMode; +import org.eclipse.jgit.lib.Ref; +import org.eclipse.jgit.treewalk.FileTreeIterator; +import org.eclipse.jgit.treewalk.FileTreeIterator.FileEntry; import org.eclipse.jgit.util.FileUtils; import org.junit.Assert; import org.junit.Test; @@ -133,6 +137,52 @@ public class CheckoutTest extends CLIRepositoryTestCase { Assert.assertEquals("\ta", execute[1]); } + /** + * Steps: + * <ol> + * <li>Add file 'a' and 'b' + * <li>Commit + * <li>Create branch '1' + * <li>modify file 'a' + * <li>Commit + * <li>Delete file 'a' in the working tree + * <li>Checkout branch '1' + * </ol> + * The working tree should contain 'a' with FileMode.REGULAR_FILE after the + * checkout. + * + * @throws Exception + */ + @Test + public void testCheckoutWithMissingWorkingTreeFile() throws Exception { + Git git = new Git(db); + File fileA = writeTrashFile("a", "Hello world a"); + writeTrashFile("b", "Hello world b"); + git.add().addFilepattern(".").call(); + git.commit().setMessage("add files a & b").call(); + Ref branch_1 = git.branchCreate().setName("branch_1").call(); + writeTrashFile("a", "b"); + git.add().addFilepattern("a").call(); + git.commit().setMessage("modify file a").call(); + + FileEntry entry = new FileTreeIterator.FileEntry(new File( + db.getWorkTree(), "a"), db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + + FileUtils.delete(fileA); + + git.checkout().setName(branch_1.getName()).call(); + + entry = new FileTreeIterator.FileEntry(new File(db.getWorkTree(), "a"), + db.getFS()); + assertEquals(FileMode.REGULAR_FILE, entry.getMode()); + assertEquals("Hello world a", read(fileA)); + } + + static private void assertEquals(Object expected, Object actual) { + Assert.assertEquals(expected, actual); + } + static private void assertEquals(String expected, String[] actual) { // if there is more than one line, ignore last one if empty Assert.assertEquals( |