git-lfs/commands/command_ls_files.go

64 lines
1.1 KiB
Go
Raw Normal View History

package commands
import (
"os"
2015-09-25 05:30:23 +00:00
2016-11-15 17:01:18 +00:00
"github.com/git-lfs/git-lfs/git"
"github.com/git-lfs/git-lfs/lfs"
"github.com/spf13/cobra"
)
var (
longOIDs = false
)
func lsFilesCommand(cmd *cobra.Command, args []string) {
requireInRepo()
2014-10-11 14:28:46 +00:00
var ref string
if len(args) == 1 {
ref = args[0]
2014-10-11 14:28:46 +00:00
} else {
2015-08-21 14:18:26 +00:00
fullref, err := git.CurrentRef()
2014-10-11 14:28:46 +00:00
if err != nil {
Exit(err.Error())
2014-10-11 14:28:46 +00:00
}
ref = fullref.Sha
}
showOidLen := 10
2015-09-25 05:30:23 +00:00
if longOIDs {
showOidLen = 64
2015-09-25 05:30:23 +00:00
}
gitscanner := lfs.NewGitScanner(func(p *lfs.WrappedPointer, err error) {
if err != nil {
Exit("Could not scan for Git LFS tree: %s", err)
return
}
2015-09-19 06:59:39 +00:00
Print("%s %s %s", p.Oid[0:showOidLen], lsFilesMarker(p), p.Name)
})
defer gitscanner.Close()
if err := gitscanner.ScanTree(ref); err != nil {
Exit("Could not scan for Git LFS tree: %s", err)
}
}
func lsFilesMarker(p *lfs.WrappedPointer) string {
info, err := os.Stat(p.Name)
if err == nil && info.Size() == p.Size {
return "*"
}
return "-"
}
func init() {
RegisterCommand("ls-files", lsFilesCommand, func(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "")
})
}