gitlib
gitlib copied to clipboard
List files in a git repo
Hey, I'm trying to list all files in a git repo but unsure how to accomplish to this. Ideally it would have similar behaviour to git ls-files
.
I tried using:
+ tree <- lookupTree =<< createTree readIndex
+
+ files <- readFileTree' tree "." False
But that seemed to not list everything:
[9:02:00] hjwylde@poliwrath| issue/5> la ~/git/hjwylde/git-fmt
total 64
drwxr-xr-x 15 hjwylde staff 510 9 Nov 18:27 ./
drwxr-xr-x 4 hjwylde staff 136 8 Nov 22:31 ../
drwxr-xr-x 13 hjwylde staff 442 10 Nov 09:01 .git/
-rw-r--r-- 1 hjwylde staff 14 8 Nov 22:51 .gitignore
drwxr-xr-x 5 hjwylde staff 170 8 Nov 23:43 .stack-work/
-rw-r--r-- 1 hjwylde staff 599 9 Nov 09:18 .travis.yml
-rw-r--r-- 1 hjwylde staff 39 8 Nov 22:51 CHANGELOG.md
-rw-r--r-- 1 hjwylde staff 1479 8 Nov 22:57 LICENSE
-rw-r--r-- 1 hjwylde staff 1847 8 Nov 22:55 README.md
-rw-r--r-- 1 hjwylde staff 46 8 Nov 22:57 Setup.hs
drwxr-xr-x 3 hjwylde staff 102 8 Nov 23:44 app/
-rw-r--r-- 1 hjwylde staff 1768 9 Nov 18:55 git-fmt.cabal
drwxr-xr-x 3 hjwylde staff 102 8 Nov 23:44 src/
-rw-r--r-- 1 hjwylde staff 37 9 Nov 17:42 stack.yaml
drwxr-xr-x 4 hjwylde staff 136 9 Nov 09:18 test/
[9:02:05] hjwylde@poliwrath| issue/5> git fmt ~/git/hjwylde/git-fmt
["git-fmt.cabal","CHANGELOG.md","Setup.hs","src/Git/Fmt/Options/Applicative/Parser.hs","test/app/Main.hs","README.md"]
[9:02:09] hjwylde@poliwrath| issue/5>
I'm probably misunderstanding how to use trees and the index, so any help is appreciated :).
At least in the current version, this works:
Just ref <- Git.resolveReference "HEAD"
commit <- Git.lookupCommit $ Tagged ref
tree <- Git.lookupTree $ Git.commitTree commit
xs <- Git.listTreeEntries True tree
return $ map fst xs