MCPcopy Create free account
hub / github.com/go-git/go-git / doAddDirectory

Method doAddDirectory

worktree_status.go:277–304  ·  view source on GitHub ↗
(idx *index.Index, s Status, directory string, ignorePattern []gitignore.Pattern)

Source from the content-addressed store, hash-verified

275}
276
277func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string, ignorePattern []gitignore.Pattern) (added bool, err error) {
278 if len(ignorePattern) > 0 {
279 m := gitignore.NewMatcher(ignorePattern)
280 matchPath := strings.Split(directory, string(os.PathSeparator))
281 if m.Match(matchPath, true) {
282 // ignore
283 return false, nil
284 }
285 }
286
287 directory = filepath.ToSlash(filepath.Clean(directory))
288
289 for name := range s {
290 if !isPathInDirectory(name, directory) {
291 continue
292 }
293
294 var a bool
295 a, _, err = w.doAddFile(idx, s, name, ignorePattern)
296 if err != nil {
297 return
298 }
299
300 added = added || a
301 }
302
303 return
304}
305
306func isPathInDirectory(path, directory string) bool {
307 return directory == "." || strings.HasPrefix(path, directory+"/")

Callers 2

doAddMethod · 0.95
AddGlobMethod · 0.95

Calls 5

MatchMethod · 0.95
doAddFileMethod · 0.95
NewMatcherFunction · 0.92
isPathInDirectoryFunction · 0.85
CleanMethod · 0.80

Tested by

no test coverage detected