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

Function includeExcludeRefs

commands/command_migrate.go:161–255  ·  view source on GitHub ↗

includeExcludeRefs returns fully-qualified sets of references to include, and exclude, or an error if those could not be determined. They are determined based on the following rules: - Include all local refs/heads/ references for each branch specified as an argument. - Include the currentl

(l *tasklog.Logger, args []string)

Source from the content-addressed store, hash-verified

159// - Include all references given in --include-ref=<ref>.
160// - Exclude all references given in --exclude-ref=<ref>.
161func includeExcludeRefs(l *tasklog.Logger, args []string) (include, exclude []string, err error) {
162 hardcore := len(migrateIncludeRefs) > 0 || len(migrateExcludeRefs) > 0
163
164 if len(args) == 0 && !hardcore && !migrateEverything {
165 // If no branches were given explicitly AND neither
166 // --include-ref or --exclude-ref flags were given, then add the
167 // currently checked out reference.
168 current, err := currentRefToMigrate()
169 if err != nil {
170 return nil, nil, err
171 }
172 args = append(args, current.Name)
173 }
174
175 if migrateEverything && len(args) > 0 {
176 return nil, nil, errors.New(tr.Tr.Get("Cannot use --everything with explicit reference arguments"))
177 }
178
179 for _, name := range args {
180 var excluded bool
181 if strings.HasPrefix("^", name) {
182 name = name[1:]
183 excluded = true
184 }
185
186 // Then, loop through each branch given, resolve that reference,
187 // and include it.
188 ref, err := git.ResolveRef(name)
189 if err != nil {
190 return nil, nil, err
191 }
192
193 if excluded {
194 exclude = append(exclude, ref.Refspec())
195 } else {
196 include = append(include, ref.Refspec())
197 }
198 }
199
200 if hardcore {
201 if migrateEverything {
202 return nil, nil, errors.New(tr.Tr.Get("Cannot use --everything with --include-ref or --exclude-ref"))
203 }
204
205 // If either --include-ref=<ref> or --exclude-ref=<ref> were
206 // given, append those to the include and excluded reference
207 // set, respectively.
208 include = append(include, migrateIncludeRefs...)
209 exclude = append(exclude, migrateExcludeRefs...)
210 } else if migrateEverything {
211 refs, err := git.AllRefsIn("")
212 if err != nil {
213 return nil, nil, err
214 }
215
216 for _, ref := range refs {
217 switch ref.Type {
218 case git.RefTypeLocalBranch, git.RefTypeLocalTag,

Callers 1

rewriteOptionsFunction · 0.85

Calls 11

NewFunction · 0.92
ResolveRefFunction · 0.92
AllRefsInFunction · 0.92
IsBareFunction · 0.92
WrapFunction · 0.92
currentRefToMigrateFunction · 0.85
isSpecialGitRefFunction · 0.85
getRemoteRefsFunction · 0.85
formatRefNameFunction · 0.85
RefspecMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected