code: func FindTrackedFiles(dir string, patterns []string) ([]string, error) {
  	// Avoid scanning the directory if the tracked set is known to be empty.
  	if len(patterns) == 0 {
  		return nil, nil
  	}
  
  	// Missing directory is considered empty.
  	if _, err := os.Stat(dir); os.IsNotExist(err) {
  		return nil, nil
  	}
  
  	isTracked := TrackedSet(patterns)
  
  	var tracked []string
  	err := filepath.Walk(dir, func(p string, info os.FileInfo, err error) error {
  		if err != nil || !info.Mode().IsRegular() {
  			return err
  		}
  		rel, err := filepath.Rel(dir, p)
  		if err != nil {
  			return err
  		}
  		rel = filepath.ToSlash(rel)
  		yes, err := isTracked(rel)
  		if yes {
  			tracked = append(tracked, rel)
  		}
  		return err
  	})
  	if err != nil {
  		return nil, errors.Annotate(err, "failed to scan the directory for tracked files").Err()
  	}
  
  	sort.Strings(tracked)
  	return tracked, nil
  }
docs: // FindTrackedFiles recursively discovers all regular files in the given
  // directory whose names match given patterns.
  //
  // See TrackedSet for the format of `patterns`. If the directory doesn't exist,
  // returns empty slice.
  //
  // Returned file names are sorted, slash-separated and relative to `dir`.