MCPcopy
hub / github.com/go-git/go-git / doAddDirectory

Method doAddDirectory

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

Source from the content-addressed store, hash-verified

292}
293
294func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string, ignorePattern []gitignore.Pattern) (added bool, err error) {
295 if len(ignorePattern) > 0 {
296 m := gitignore.NewMatcher(ignorePattern)
297 matchPath := strings.Split(directory, string(os.PathSeparator))
298 if m.Match(matchPath, true) {
299 // ignore
300 return false, nil
301 }
302 }
303
304 directory = filepath.ToSlash(filepath.Clean(directory))
305
306 for name := range s {
307 if !isPathInDirectory(name, directory) {
308 continue
309 }
310
311 var a bool
312 a, _, err = w.doAddFile(idx, s, name, ignorePattern)
313 if err != nil {
314 return
315 }
316
317 added = added || a
318 }
319
320 return
321}
322
323func isPathInDirectory(path, directory string) bool {
324 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