diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java index 20a1acbd9..243d791cd 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PathCheckoutCommandTest.java @@ -233,4 +233,14 @@ public class PathCheckoutCommandTest extends RepositoryTestCase { assertEquals(0, status.getRemoved().size()); assertEquals(0, status.getUntracked().size()); } + + @Test + public void testCheckoutRepository() throws Exception { + CheckoutCommand co = git.checkout(); + File test = writeTrashFile(FILE1, ""); + File test2 = writeTrashFile(FILE2, ""); + co.setStartPoint("HEAD~2").setAllPaths(true).call(); + assertEquals("1", read(test)); + assertEquals("a", read(test2)); + } } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java index 6f2570a40..a41ff8454 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CheckoutCommand.java @@ -102,6 +102,8 @@ public class CheckoutCommand extends GitCommand { private List paths; + private boolean checkoutAllPaths; + /** * @param repo */ @@ -126,7 +128,7 @@ public class CheckoutCommand extends GitCommand { checkCallable(); processOptions(); try { - if (!paths.isEmpty()) { + if (checkoutAllPaths || !paths.isEmpty()) { checkoutPaths(); status = CheckoutResult.OK_RESULT; setCallable(false); @@ -234,6 +236,22 @@ public class CheckoutCommand extends GitCommand { return this; } + /** + * Set whether to checkout all paths + *

+ * This options should be used when you want to do a path checkout on the + * entire repository and so calling {@link #addPath(String)} is not possible + * since empty paths are not allowed. + * + * @param all + * true to checkout all paths, false otherwise + * @return {@code this} + */ + public CheckoutCommand setAllPaths(boolean all) { + checkoutAllPaths = all; + return this; + } + /** * Checkout paths into index and working directory * @@ -249,7 +267,8 @@ public class CheckoutCommand extends GitCommand { DirCacheEditor editor = dc.editor(); TreeWalk startWalk = new TreeWalk(revWalk.getObjectReader()); startWalk.setRecursive(true); - startWalk.setFilter(PathFilterGroup.createFromStrings(paths)); + if (!checkoutAllPaths) + startWalk.setFilter(PathFilterGroup.createFromStrings(paths)); boolean checkoutIndex = startCommit == null && startPoint == null; if (!checkoutIndex) startWalk.addTree(revWalk.parseCommit(getStartPoint()) @@ -310,7 +329,7 @@ public class CheckoutCommand extends GitCommand { } private void processOptions() throws InvalidRefNameException { - if (paths.isEmpty() + if ((!checkoutAllPaths && paths.isEmpty()) && (name == null || !Repository .isValidRefName(Constants.R_HEADS + name))) throw new InvalidRefNameException(MessageFormat.format(JGitText