]> source.dussan.org Git - jgit.git/commitdiff
Fix ResetCommand to default to mixed reset 42/34742/3
authorMatthias Sohn <matthias.sohn@sap.com>
Mon, 13 Oct 2014 14:41:58 +0000 (16:41 +0200)
committerMatthias Sohn <matthias.sohn@sap.com>
Mon, 13 Oct 2014 14:41:58 +0000 (16:41 +0200)
ResetCommand threw an NPE if neither mode nor path was defined. Instead
it should default to a mixed reset like native git does.

Change-Id: I455902394f9e7b0c7afae42381f34838f7f2a138
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java

index 82249766ade89d1676c90ce88e7776f910be3b75..c48b412401c18711d76a735cf130c626b71224cb 100644 (file)
@@ -424,6 +424,21 @@ public class ResetCommandTest extends RepositoryTestCase {
                git.reset().setRef("doesnotexist").addPath("a.txt").call();
        }
 
+       @Test
+       public void testResetDefaultMode() throws Exception {
+               git = new Git(db);
+               writeTrashFile("a.txt", "content");
+               git.add().addFilepattern("a.txt").call();
+               writeTrashFile("a.txt", "modified");
+               // should use default mode MIXED
+               git.reset().call();
+
+               DirCache cache = db.readDirCache();
+               DirCacheEntry aEntry = cache.getEntry("a.txt");
+               assertNull(aEntry);
+               assertEquals("modified", read("a.txt"));
+       }
+
        @Test
        public void testHardResetOnTag() throws Exception {
                setupRepository();
index 7c2192dd9f394932185a0519f4bee3ab6a5c27e5..17b1242308cd3921a8eb7be67c62c2261dbb5536 100644 (file)
@@ -195,6 +195,9 @@ public class ResetCommand extends GitCommand<Ref> {
                                result = repo.getRef(Constants.HEAD);
                        }
 
+                       if (mode == null)
+                               mode = ResetType.MIXED;
+
                        switch (mode) {
                                case HARD:
                                        checkoutIndex(commitTree);