doAddFile create a new blob from path and update the index, added is true if the file added is different from the index. if s status is nil will skip the status check and update the index anyway
(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern)
| 429 | // the file added is different from the index. |
| 430 | // if s status is nil will skip the status check and update the index anyway |
| 431 | func (w *Worktree) doAddFile(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern) (added bool, h plumbing.Hash, err error) { |
| 432 | if s != nil && s.File(path).Worktree == Unmodified { |
| 433 | return false, h, nil |
| 434 | } |
| 435 | if len(ignorePattern) > 0 { |
| 436 | m := gitignore.NewMatcher(ignorePattern) |
| 437 | matchPath := strings.Split(path, string(os.PathSeparator)) |
| 438 | if m.Match(matchPath, true) { |
| 439 | // ignore |
| 440 | return false, h, nil |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | h, err = w.copyFileToStorage(path) |
| 445 | if err != nil { |
| 446 | if os.IsNotExist(err) { |
| 447 | added = true |
| 448 | h, err = w.deleteFromIndex(idx, path) |
| 449 | } |
| 450 | |
| 451 | return |
| 452 | } |
| 453 | |
| 454 | if err := w.addOrUpdateFileToIndex(idx, path, h); err != nil { |
| 455 | return false, h, err |
| 456 | } |
| 457 | |
| 458 | return true, h, err |
| 459 | } |
| 460 | |
| 461 | func (w *Worktree) copyFileToStorage(path string) (hash plumbing.Hash, err error) { |
| 462 | fi, err := w.Filesystem.Lstat(path) |
no test coverage detected