forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_pull.go
58 lines (46 loc) · 1.3 KB
/
command_pull.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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
}
pull(determineIncludeExcludePaths(pullIncludeArg, pullExcludeArg))
}
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(&pullIncludeArg, "include", "I", "", "Include a list of paths")
pullCmd.Flags().StringVarP(&pullExcludeArg, "exclude", "X", "", "Exclude a list of paths")
RootCmd.AddCommand(pullCmd)
}