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

Method AddGlob

worktree_status.go:396–445  ·  view source on GitHub ↗

AddGlob adds all paths, matching pattern, to the index. If pattern matches a directory path, all directory contents are added to the index recursively. No error is returned if all matching paths are already staged in index.

(pattern string)

Source from the content-addressed store, hash-verified

394// directory path, all directory contents are added to the index recursively. No
395// error is returned if all matching paths are already staged in index.
396func (w *Worktree) AddGlob(pattern string) error {
397 // TODO(mcuadros): deprecate in favor of AddWithOption in v6.
398 files, err := util.Glob(w.Filesystem, pattern)
399 if err != nil {
400 return err
401 }
402
403 if len(files) == 0 {
404 return ErrGlobNoMatches
405 }
406
407 s, err := w.Status()
408 if err != nil {
409 return err
410 }
411
412 idx, err := w.r.Storer.Index()
413 if err != nil {
414 return err
415 }
416
417 var saveIndex bool
418 for _, file := range files {
419 fi, err := w.Filesystem.Lstat(file)
420 if err != nil {
421 return err
422 }
423
424 var added bool
425 if fi.IsDir() {
426 added, err = w.doAddDirectory(idx, s, file, make([]gitignore.Pattern, 0))
427 } else {
428 added, _, err = w.doAddFile(idx, s, file, make([]gitignore.Pattern, 0))
429 }
430
431 if err != nil {
432 return err
433 }
434
435 if !saveIndex && added {
436 saveIndex = true
437 }
438 }
439
440 if saveIndex {
441 return w.r.Storer.SetIndex(idx)
442 }
443
444 return nil
445}
446
447// doAddFile create a new blob from path and update the index, added is true if
448// the file added is different from the index.

Callers 3

AddWithOptionsMethod · 0.95
setupBenchmarkRepoFunction · 0.80

Calls 8

StatusMethod · 0.95
doAddDirectoryMethod · 0.95
doAddFileMethod · 0.95
GlobMethod · 0.80
IndexMethod · 0.65
IsDirMethod · 0.65
SetIndexMethod · 0.65
LstatMethod · 0.45

Tested by 2

setupBenchmarkRepoFunction · 0.64