2014-09-22 21:26:43 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2015-09-25 16:30:01 +00:00
|
|
|
"os"
|
2015-09-25 05:30:23 +00:00
|
|
|
|
2015-03-19 19:30:55 +00:00
|
|
|
"github.com/github/git-lfs/git"
|
2015-04-23 16:20:36 +00:00
|
|
|
"github.com/github/git-lfs/lfs"
|
2015-05-25 18:20:50 +00:00
|
|
|
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
|
2014-09-22 21:26:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2015-09-25 05:30:23 +00:00
|
|
|
longOIDs = false
|
2014-09-22 21:26:43 +00:00
|
|
|
lsFilesCmd = &cobra.Command{
|
2015-09-17 22:08:28 +00:00
|
|
|
Use: "ls-files",
|
|
|
|
Run: lsFilesCommand,
|
2014-09-22 21:26:43 +00:00
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
func lsFilesCommand(cmd *cobra.Command, args []string) {
|
2015-09-08 16:23:27 +00:00
|
|
|
requireInRepo()
|
2015-09-08 15:29:53 +00:00
|
|
|
|
2014-10-11 14:28:46 +00:00
|
|
|
var ref string
|
|
|
|
var err error
|
2014-09-22 21:26:43 +00:00
|
|
|
|
2014-10-03 16:17:26 +00:00
|
|
|
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 {
|
2015-09-17 21:03:11 +00:00
|
|
|
Exit(err.Error())
|
2014-10-11 14:28:46 +00:00
|
|
|
}
|
2015-08-20 14:36:10 +00:00
|
|
|
ref = fullref.Sha
|
2014-10-03 16:17:26 +00:00
|
|
|
}
|
2014-09-22 21:26:43 +00:00
|
|
|
|
2015-09-25 16:30:01 +00:00
|
|
|
showOidLen := 10
|
2015-09-25 05:30:23 +00:00
|
|
|
if longOIDs {
|
2015-09-25 16:30:01 +00:00
|
|
|
showOidLen = 64
|
2015-09-25 05:30:23 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 16:30:01 +00:00
|
|
|
files, err := lfs.ScanTree(ref)
|
2015-09-19 06:59:39 +00:00
|
|
|
if err != nil {
|
2015-09-25 16:30:01 +00:00
|
|
|
Panic(err, "Could not scan for Git LFS tree: %s", err)
|
2015-09-19 06:59:39 +00:00
|
|
|
}
|
|
|
|
|
2015-09-25 16:30:01 +00:00
|
|
|
for _, p := range files {
|
|
|
|
Print("%s %s %s", p.Oid[0:showOidLen], lsFilesMarker(p), p.Name)
|
2014-10-03 16:17:26 +00:00
|
|
|
}
|
2015-09-25 16:30:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func lsFilesMarker(p *lfs.WrappedPointer) string {
|
|
|
|
info, err := os.Stat(p.Name)
|
|
|
|
if err == nil && info.Size() == p.Size {
|
|
|
|
return "*"
|
2014-10-03 16:17:26 +00:00
|
|
|
}
|
2015-09-25 16:30:01 +00:00
|
|
|
|
|
|
|
return "-"
|
2014-09-22 21:26:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2015-09-25 16:30:01 +00:00
|
|
|
lsFilesCmd.Flags().BoolVarP(&longOIDs, "long", "l", false, "")
|
2014-09-22 21:26:43 +00:00
|
|
|
RootCmd.AddCommand(lsFilesCmd)
|
|
|
|
}
|