(idx *index.Index, s Status, directory string, ignorePattern []gitignore.Pattern)
| 292 | } |
| 293 | |
| 294 | func (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 | |
| 323 | func isPathInDirectory(path, directory string) bool { |
| 324 | return directory == "." || strings.HasPrefix(path, directory+"/") |
no test coverage detected