From 13ffda0666cec94183529307eecbbda3bcf12fb1 Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Mon, 13 Oct 2014 16:41:58 +0200 Subject: [PATCH] Fix ResetCommand to default to mixed reset 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 --- .../org/eclipse/jgit/api/ResetCommandTest.java | 15 +++++++++++++++ .../src/org/eclipse/jgit/api/ResetCommand.java | 3 +++ 2 files changed, 18 insertions(+) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java index 82249766a..c48b41240 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java @@ -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(); diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java index 7c2192dd9..17b124230 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/ResetCommand.java @@ -195,6 +195,9 @@ public class ResetCommand extends GitCommand { result = repo.getRef(Constants.HEAD); } + if (mode == null) + mode = ResetType.MIXED; + switch (mode) { case HARD: checkoutIndex(commitTree);