MCPcopy
hub / github.com/git-lfs/git-lfs / fetchCommand

Function fetchCommand

commands/command_fetch.go:90–180  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

88}
89
90func fetchCommand(cmd *cobra.Command, args []string) {
91 setupRepository()
92
93 var refs []*git.Ref
94
95 if len(args) > 0 {
96 // Remote is first arg
97 if err := cfg.SetValidRemote(args[0]); err != nil {
98 Exit(tr.Tr.Get("Invalid remote name %q: %s", args[0], err))
99 }
100 }
101
102 if len(args) > 1 {
103 resolvedrefs, err := git.ResolveRefs(args[1:])
104 if err != nil {
105 Panic(err, tr.Tr.Get("Invalid ref argument: %v", args[1:]))
106 }
107 refs = resolvedrefs
108 } else if !fetchAllArg {
109 ref, err := git.CurrentRef()
110 if err != nil {
111 Panic(err, tr.Tr.Get("Could not fetch"))
112 }
113 refs = []*git.Ref{ref}
114 }
115
116 if fetchJsonArg && fetchPruneArg {
117 // git lfs prune has no `--json` flag, so let's not allow that here for the moment
118 Exit(tr.Tr.Get("Cannot combine --json with --prune"))
119 }
120
121 success := true
122 include, exclude := getIncludeExcludeArgs(cmd)
123 fetchPruneCfg := lfs.NewFetchPruneConfig(cfg.Git)
124
125 watcher := &fetchWatcher{}
126
127 if fetchAllArg {
128 if fetchRecentArg {
129 Exit(tr.Tr.Get("Cannot combine --all with --recent"))
130 }
131 if include != nil || exclude != nil {
132 Exit(tr.Tr.Get("Cannot combine --all with --include or --exclude"))
133 }
134 if len(cfg.FetchIncludePaths()) > 0 || len(cfg.FetchExcludePaths()) > 0 {
135 printProgress(tr.Tr.Get("Ignoring global include / exclude paths to fulfil --all"))
136 }
137
138 if len(args) > 1 {
139 refShas := make([]string, 0, len(refs))
140 for _, ref := range refs {
141 refShas = append(refShas, ref.Sha)
142 }
143 success = fetchRefs(refShas, watcher)
144 } else {
145 success = fetchAll(watcher)
146 }
147

Callers

nothing calls this directly

Calls 15

dumpJsonMethod · 0.95
ResolveRefsFunction · 0.92
CurrentRefFunction · 0.92
NewFetchPruneConfigFunction · 0.92
setupRepositoryFunction · 0.85
ExitFunction · 0.85
PanicFunction · 0.85
getIncludeExcludeArgsFunction · 0.85
printProgressFunction · 0.85
fetchRefsFunction · 0.85
fetchAllFunction · 0.85
buildFilepathFilterFunction · 0.85

Tested by

no test coverage detected