git-lfs/commands/command_pull.go
risk danger olson cf3dc4e5eb use shared include/exclude flag values across all commands
reduces the chance of bugs between the flag handling in pull/fetch/clone
2016-08-02 10:37:16 -06:00

57 lines
1.2 KiB
Go

package commands
import (
"fmt"
"github.com/github/git-lfs/git"
"github.com/spf13/cobra"
)
var (
pullCmd = &cobra.Command{
Use: "pull",
Run: pullCommand,
}
)
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]))
}
cfg.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")
}
cfg.CurrentRemote = defaultRemote
}
includeArg, excludeArg := getIncludeExcludeArgs(cmd)
pull(determineIncludeExcludePaths(cfg, includeArg, excludeArg))
}
func pull(includePaths, excludePaths []string) {
ref, err := git.CurrentRef()
if err != nil {
Panic(err, "Could not pull")
}
c := fetchRefToChan(ref.Sha, includePaths, excludePaths)
checkoutFromFetchChan(includePaths, excludePaths, c)
}
func init() {
pullCmd.Flags().StringVarP(&includeArg, "include", "I", "", "Include a list of paths")
pullCmd.Flags().StringVarP(&excludeArg, "exclude", "X", "", "Exclude a list of paths")
RootCmd.AddCommand(pullCmd)
}