Browse Source

Have git-ls tree to accept path args like git-ls-tree

Usage is:

jgit ls-tree [-r|--recursive] <tree-ish> [-- paths...]

Change-Id: I2e1c9c3cc8cddfa12ca4bfb9afc4df0492a9fce1
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Signed-off-by: Chris Aniszczyk <zx@twitter.com>
stable-2.2
Ketan Padegaonkar 13 years ago committed by Chris Aniszczyk
parent
commit
360be05fd4
  1. 16
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java

16
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/LsTree.java

@ -45,12 +45,17 @@
package org.eclipse.jgit.pgm;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.treewalk.AbstractTreeIterator;
import org.eclipse.jgit.treewalk.TreeWalk;
import org.eclipse.jgit.treewalk.filter.PathFilterGroup;
import org.kohsuke.args4j.Argument;
import org.kohsuke.args4j.Option;
import org.kohsuke.args4j.spi.StopOptionHandler;
class LsTree extends TextBuiltin {
@Option(name = "--recursive", usage = "usage_recurseIntoSubtrees", aliases = { "-r" })
@ -59,9 +64,16 @@ class LsTree extends TextBuiltin {
@Argument(index = 0, required = true, metaVar = "metaVar_treeish")
private AbstractTreeIterator tree;
@Argument(index = 1)
@Option(name = "--", metaVar = "metaVar_paths", multiValued = true, handler = StopOptionHandler.class)
private List<String> paths = new ArrayList<String>();
@Override
protected void run() throws Exception {
final TreeWalk walk = new TreeWalk(db);
walk.reset(); // drop the first empty tree, which we do not need here
if (paths.size() > 0)
walk.setFilter(PathFilterGroup.createFromStrings(paths));
walk.setRecursive(recursive);
walk.addTree(tree);

Loading…
Cancel
Save