git-lfs/commands/command_pull.go
Steve Streeting 1e7cb85954 Validate user-supplied remote names in fetch/pull
Without this user would get a confusing message of the form:
Post objects/batch: unsupported protocol scheme ""
2015-10-06 17:35:58 +01:00

54 lines
1.3 KiB
Go

package commands
import (
"fmt"
"github.com/github/git-lfs/git"
"github.com/github/git-lfs/lfs"
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
)
var (
pullCmd = &cobra.Command{
Use: "pull",
Run: pullCommand,
}
pullIncludeArg string
pullExcludeArg string
)
func pullCommand(cmd *cobra.Command, args []string) {
requireInRepo()
if len(args) > 0 {
// Remote is first arg
if err := git.ValidateRemote(args[0]); err != nil {
Panic(err, fmt.Sprintf("Invalid remote name '%v'", args[0]))
}
lfs.Config.CurrentRemote = args[0]
} else {
// Actively find the default remote, don't just assume origin
defaultRemote, err := git.DefaultRemote()
if err != nil {
Panic(err, "No default remote")
}
lfs.Config.CurrentRemote = defaultRemote
}
ref, err := git.CurrentRef()
if err != nil {
Panic(err, "Could not pull")
}
includePaths, excludePaths := determineIncludeExcludePaths(pullIncludeArg, pullExcludeArg)
c := fetchRefToChan(ref.Sha, includePaths, excludePaths)
checkoutFromFetchChan(includePaths, excludePaths, c)
}
func init() {
pullCmd.Flags().StringVarP(&pullIncludeArg, "include", "I", "", "Include a list of paths")
pullCmd.Flags().StringVarP(&pullExcludeArg, "exclude", "X", "", "Exclude a list of paths")
RootCmd.AddCommand(pullCmd)
}