git-lfs/commands/command_ls_files.go
Taylor Blau 4593d0a641 vendor: vendor dependencies in vendor/ using Glide
- script/vendor received an update in order to work with Glide
- import paths have been rewritten to work with GO15VENDOREXPERIMENT
2016-05-23 12:10:35 -06:00

63 lines
1022 B
Go

package commands
import (
"os"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
"github.com/spf13/cobra"
)
var (
longOIDs = false
lsFilesCmd = &cobra.Command{
Use: "ls-files",
Run: lsFilesCommand,
}
)
func lsFilesCommand(cmd *cobra.Command, args []string) {
requireInRepo()
var ref string
var err error
if len(args) == 1 {
ref = args[0]
} else {
fullref, err := git.CurrentRef()
if err != nil {
Exit(err.Error())
}
ref = fullref.Sha
}
showOidLen := 10
if longOIDs {
showOidLen = 64
}
files, err := lfs.ScanTree(ref)
if err != nil {
Panic(err, "Could not scan for Git LFS tree: %s", err)
}
for _, p := range files {
Print("%s %s %s", p.Oid[0:showOidLen], lsFilesMarker(p), p.Name)
}
}
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, "")
RootCmd.AddCommand(lsFilesCmd)
}