(idx *index.Index, s Status, directory string, ignorePattern []gitignore.Pattern)
| 275 | } |
| 276 | |
| 277 | func (w *Worktree) doAddDirectory(idx *index.Index, s Status, directory string, ignorePattern []gitignore.Pattern) (added bool, err error) { |
| 278 | if len(ignorePattern) > 0 { |
| 279 | m := gitignore.NewMatcher(ignorePattern) |
| 280 | matchPath := strings.Split(directory, string(os.PathSeparator)) |
| 281 | if m.Match(matchPath, true) { |
| 282 | // ignore |
| 283 | return false, nil |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | directory = filepath.ToSlash(filepath.Clean(directory)) |
| 288 | |
| 289 | for name := range s { |
| 290 | if !isPathInDirectory(name, directory) { |
| 291 | continue |
| 292 | } |
| 293 | |
| 294 | var a bool |
| 295 | a, _, err = w.doAddFile(idx, s, name, ignorePattern) |
| 296 | if err != nil { |
| 297 | return |
| 298 | } |
| 299 | |
| 300 | added = added || a |
| 301 | } |
| 302 | |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | func isPathInDirectory(path, directory string) bool { |
| 307 | return directory == "." || strings.HasPrefix(path, directory+"/") |
no test coverage detected