2 * Copyright (C) 2008 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License, version 2, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.jgit
.pgm
;
21 import org
.spearce
.jgit
.lib
.Constants
;
22 import org
.spearce
.jgit
.lib
.FileMode
;
23 import org
.spearce
.jgit
.treewalk
.FileTreeIterator
;
24 import org
.spearce
.jgit
.treewalk
.TreeWalk
;
26 class LsTree
extends TextBuiltin
{
28 void execute(final String
[] args
) throws Exception
{
29 final TreeWalk walk
= new TreeWalk(db
);
31 for (; argi
< args
.length
; argi
++) {
32 final String a
= args
[argi
];
36 } else if ("-r".equals(a
))
37 walk
.setRecursive(true);
42 if (argi
== args
.length
)
43 throw die("usage: [-r] treename");
44 else if (argi
+ 1 < args
.length
)
45 throw die("too many arguments");
47 final String n
= args
[argi
];
49 walk
.addTree(new FileTreeIterator(new File(n
)));
51 walk
.addTree(resolve(n
));
54 final FileMode mode
= walk
.getFileMode(0);
55 if (mode
== FileMode
.TREE
)
59 out
.print(Constants
.typeString(mode
.getObjectType()));
62 out
.print(walk
.getObjectId(0));
65 out
.print(walk
.getPathString());
70 private boolean is_WorkDir(final String name
) {
71 return new File(name
).isDirectory();