code: func (w *Worktree) AddGlob(pattern string) error {
  	files, err := util.Glob(w.Filesystem, pattern)
  	if err != nil {
  		return err
  	}
  
  	if len(files) == 0 {
  		return ErrGlobNoMatches
  	}
  
  	s, err := w.Status()
  	if err != nil {
  		return err
  	}
  
  	idx, err := w.r.Storer.Index()
  	if err != nil {
  		return err
  	}
  
  	var saveIndex bool
  	for _, file := range files {
  		fi, err := w.Filesystem.Lstat(file)
  		if err != nil {
  			return err
  		}
  
  		var added bool
  		if fi.IsDir() {
  			added, err = w.doAddDirectory(idx, s, file)
  		} else {
  			added, _, err = w.doAddFile(idx, s, file)
  		}
  
  		if err != nil {
  			return err
  		}
  
  		if !saveIndex && added {
  			saveIndex = true
  		}
  	}
  
  	if saveIndex {
  		return w.r.Storer.SetIndex(idx)
  	}
  
  	return nil
  }
docs: // 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.