git-lfs/commands/command_push.go

53 lines
990 B
Go
Raw Normal View History

package commands
2013-10-04 17:09:03 +00:00
import (
"github.com/github/git-media/gitmedia"
"github.com/github/git-media/gitmediaclient"
2014-03-12 14:55:01 +00:00
"strings"
2013-10-04 17:09:03 +00:00
)
2014-05-27 16:36:07 +00:00
type PushCommand struct {
2013-10-04 17:09:03 +00:00
*Command
}
2014-05-27 16:36:07 +00:00
func (c *PushCommand) Run() {
2014-06-05 18:48:23 +00:00
q, err := gitmedia.UploadQueue()
if err != nil {
Panic(err, "Error setting up the queue")
}
q.Walk(func(id string, body []byte) error {
2014-03-12 14:55:01 +00:00
fileInfo := string(body)
parts := strings.Split(fileInfo, ":")
var sha, filename string
sha = parts[0]
if len(parts) > 1 {
filename = parts[1]
}
path := gitmedia.LocalMediaPath(sha)
err := gitmediaclient.Options(path)
if err != nil {
2014-06-05 18:48:23 +00:00
Panic(err, "error uploading file %s", filename)
}
err = gitmediaclient.Put(path, filename)
if err != nil {
2014-06-05 18:48:23 +00:00
Panic(err, "error uploading file %s", sha)
}
2013-10-21 18:42:29 +00:00
if err := q.Del(id); err != nil {
2014-06-05 18:48:23 +00:00
Panic(err, "error removing %s from queue", sha)
}
2013-10-21 20:25:24 +00:00
return nil
})
2013-10-04 17:09:03 +00:00
}
func init() {
2014-05-27 16:36:07 +00:00
registerCommand("push", func(c *Command) RunnableCommand {
return &PushCommand{Command: c}
2013-10-04 17:09:03 +00:00
})
}