tweak ls-files output
* simpler, easier to chop up with unix tools * show LFS OID, not Git SHA1 * only scan the tree, not the refs * show whether files are LFS pointers or full objects
This commit is contained in:
parent
21bc33e8c0
commit
2082b26ce7
@ -1,7 +1,7 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"os"
|
||||
|
||||
"github.com/github/git-lfs/git"
|
||||
"github.com/github/git-lfs/lfs"
|
||||
@ -32,32 +32,31 @@ func lsFilesCommand(cmd *cobra.Command, args []string) {
|
||||
ref = fullref.Sha
|
||||
}
|
||||
|
||||
showShaLen := 7
|
||||
showOidLen := 10
|
||||
if longOIDs {
|
||||
showShaLen = 40
|
||||
showOidLen = 64
|
||||
}
|
||||
|
||||
scanOpt := &lfs.ScanRefsOptions{SkipDeletedBlobs: true}
|
||||
listFiles := make(map[string][]string)
|
||||
fileTree, err := lfs.ScanTree(ref)
|
||||
files, err := lfs.ScanTree(ref)
|
||||
if err != nil {
|
||||
Panic(err, "Could not scan for Git LFS tree")
|
||||
}
|
||||
for _, p := range fileTree {
|
||||
listFiles[p.Sha1] = append(listFiles[p.Sha1], p.Name)
|
||||
Panic(err, "Could not scan for Git LFS tree: %s", err)
|
||||
}
|
||||
|
||||
pointers, err := lfs.ScanRefs(ref, "", scanOpt)
|
||||
if err != nil {
|
||||
Panic(err, "Could not scan for Git LFS files")
|
||||
for _, p := range files {
|
||||
Print("%s %s %s", p.Oid[0:showOidLen], lsFilesMarker(p), p.Name)
|
||||
}
|
||||
for _, p := range pointers {
|
||||
Print(p.Sha1[0:showShaLen] + " ==> [ " + strings.Join(listFiles[p.Sha1], ",") + " ]")
|
||||
delete(listFiles, p.Sha1)
|
||||
}
|
||||
|
||||
func lsFilesMarker(p *lfs.WrappedPointer) string {
|
||||
info, err := os.Stat(p.Name)
|
||||
if err == nil && info.Size() == p.Size {
|
||||
return "*"
|
||||
}
|
||||
|
||||
return "-"
|
||||
}
|
||||
|
||||
func init() {
|
||||
lsFilesCmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "Show object ID(s) 40 characters")
|
||||
lsFilesCmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "")
|
||||
RootCmd.AddCommand(lsFilesCmd)
|
||||
}
|
||||
|
@ -15,7 +15,7 @@ begin_test "ls-files"
|
||||
echo "missing" > missing.dat
|
||||
git add missing.dat
|
||||
git commit -m "add missing file"
|
||||
[ "74f2f1c ==> [ missing.dat ]" = "$(git lfs ls-files)" ]
|
||||
[ "6bbd052ab0 * missing.dat" = "$(git lfs ls-files)" ]
|
||||
|
||||
git rm missing.dat
|
||||
git add some.dat some.txt
|
||||
@ -80,7 +80,11 @@ begin_test "ls-files: show duplicate files"
|
||||
git add one.tgz
|
||||
git add two.tgz
|
||||
git commit -m "add duplicate files"
|
||||
[ "67f58a4 ==> [ one.tgz,two.tgz ]" = "$(git lfs ls-files)" ]
|
||||
|
||||
expected="$(echo "a1fff0ffef * one.tgz
|
||||
a1fff0ffef * two.tgz")"
|
||||
|
||||
[ "$expected" = "$(git lfs ls-files)" ]
|
||||
)
|
||||
end_test
|
||||
|
||||
@ -98,6 +102,10 @@ begin_test "ls-files: show duplicate files with long OID"
|
||||
git add one.tgz
|
||||
git add two.tgz
|
||||
git commit -m "add duplicate files with long OID"
|
||||
[ "67f58a40df1e32b439f55e722178c337042d2148 ==> [ one.tgz,two.tgz ]" = "$(git lfs ls-files --long)" ]
|
||||
|
||||
expected="$(echo "a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * one.tgz
|
||||
a1fff0ffefb9eace7230c24e50731f0a91c62f9cefdfe77121c2f607125dffae * two.tgz")"
|
||||
|
||||
[ "$expected" = "$(git lfs ls-files --long)" ]
|
||||
)
|
||||
end_test
|
||||
|
Loading…
Reference in New Issue
Block a user