Skip to content

Commit 1565e63

Browse files
commands: teach 'git lfs ls-files' a '--debug' option
There was no way to conveniently display LFS pointer file properties for debugging. Teach 'git lfs ls-files' a '--debug' option that prints all available information following the 'git ls-files' interface [1]. [1] git/git@8497421
1 parent 25a87db commit 1565e63

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

commands/command_ls_files.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
var (
1212
longOIDs = false
13+
debug = false
1314
)
1415

1516
func lsFilesCommand(cmd *cobra.Command, args []string) {
@@ -38,7 +39,24 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
3839
return
3940
}
4041

41-
Print("%s %s %s", p.Oid[0:showOidLen], lsFilesMarker(p), p.Name)
42+
if debug {
43+
Print(
44+
"filepath: %s\n"+
45+
" size: %d\n"+
46+
"checkout: %v\n"+
47+
"download: %v\n"+
48+
" oid: %s %s\n"+
49+
" version: %s\n",
50+
p.Name,
51+
p.Size,
52+
fileExistsOfSize(p),
53+
lfs.ObjectExistsOfSize(p.Oid, p.Size),
54+
p.OidType,
55+
p.Oid,
56+
p.Version)
57+
} else {
58+
Print("%s %s %s", p.Oid[0:showOidLen], lsFilesMarker(p), p.Name)
59+
}
4260
})
4361
defer gitscanner.Close()
4462

@@ -63,5 +81,6 @@ func lsFilesMarker(p *lfs.WrappedPointer) string {
6381
func init() {
6482
RegisterCommand("ls-files", lsFilesCommand, func(cmd *cobra.Command) {
6583
cmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "")
84+
cmd.Flags().BoolVarP(&debug, "debug", "d", false, "")
6685
})
6786
}

docs/man/git-lfs-ls-files.1.ronn

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ reference. If no reference is given, scan the currently checked-out branch.
1515
* `-l` `--long`:
1616
Show the entire 64 character OID, instead of just first 10.
1717

18+
* -d --debug:
19+
Show as much information as possible about a LFS file. This is intended
20+
for manual inspection; the exact format may change at any time.
21+
1822
## SEE ALSO
1923

2024
git-lfs-status(1).

test/test-ls-files.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,16 @@ begin_test "ls-files"
2424
git lfs ls-files | tee ls.log
2525
grep some.dat ls.log
2626
[ `wc -l < ls.log` = 1 ]
27+
28+
diff -u <(git lfs ls-files --debug) <(cat <<-EOF
29+
filepath: some.dat
30+
size: 10
31+
checkout: true
32+
download: true
33+
oid: sha256 5aa03f96c77536579166fba147929626cc3a97960e994057a9d80271a736d10f
34+
version: https://git-lfs.github.com/spec/v1
35+
36+
EOF)
2737
)
2838
end_test
2939

0 commit comments

Comments
 (0)