aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit
diff options
context:
space:
mode:
authorChristian Halstrick <christian.halstrick@sap.com>2018-02-12 15:44:04 +0100
committerChristian Halstrick <christian.halstrick@sap.com>2019-01-08 10:01:09 +0100
commite406d500de01b9ae7155e296baebf3ec8024869d (patch)
tree3873d4a07a3c46d662d7ed5d66cd234c2f07188c /org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit
parent6c8240a75126013b7f4588d78e66baa54e89cbfc (diff)
downloadjgit-e406d500de01b9ae7155e296baebf3ec8024869d.tar.gz
jgit-e406d500de01b9ae7155e296baebf3ec8024869d.zip
Fix "jgit checkout -f" to overwrite dirty worktree files
CheckoutCommand had a setForce() method. But this didn't correspond to native git's 'git checkout -f' option. Deprecate the old setForce() method and move its implementation to a new method setForceRefUpdate() and use it to implement the -B option in the CLI class Checkout. Add a setForced() method and use it to fix the associated '-f' option of the CLI Checkout class to behave like native git's 'git checkout -f' which overwrites dirty worktree files during checkout. This is still not fully matching native git's behavior: updating additionally dirty index entries is not done yet. Bug: 530771 Change-Id: I776b78eb623b6ea0aca42f681788f2e4b1667f15 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit')
-rw-r--r--org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/CheckoutTest.java16
1 files changed, 16 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 b2115a4b74..f0e2b38cb4 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
@@ -58,6 +58,7 @@ import java.util.List;
import org.eclipse.jgit.api.Git;
import org.eclipse.jgit.api.errors.CheckoutConflictException;
import org.eclipse.jgit.diff.DiffEntry;
+import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.CLIRepositoryTestCase;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.Ref;
@@ -684,4 +685,19 @@ public class CheckoutTest extends CLIRepositoryTestCase {
assertTrue(Files.isSymbolicLink(path));
}
}
+
+ @Test
+ public void testCheckoutForce_Bug530771() throws Exception {
+ try (Git git = new Git(db)) {
+ File f = writeTrashFile("a", "Hello world");
+ git.add().addFilepattern("a").call();
+ git.commit().setMessage("create a").call();
+ writeTrashFile("a", "Goodbye world");
+ assertEquals("[]",
+ Arrays.toString(execute("git checkout -f HEAD")));
+ assertEquals("Hello world", read(f));
+ assertEquals("[a, mode:100644, content:Hello world]",
+ indexState(db, LocalDiskRepositoryTestCase.CONTENT));
+ }
+ }
}