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)
| 448 | // the file added is different from the index. |
| 449 | // if s status is nil will skip the status check and update the index anyway |
| 450 | func (w *Worktree) doAddFile(idx *index.Index, s Status, path string, ignorePattern []gitignore.Pattern) (added bool, h plumbing.Hash, err error) { |
| 451 | if s != nil && s.File(path).Worktree == Unmodified { |
| 452 | return false, h, nil |
| 453 | } |
| 454 | if len(ignorePattern) > 0 { |
| 455 | m := gitignore.NewMatcher(ignorePattern) |
| 456 | matchPath := strings.Split(path, string(os.PathSeparator)) |
| 457 | if m.Match(matchPath, true) { |
| 458 | // ignore |
| 459 | return false, h, nil |
| 460 | } |
| 461 | } |
| 462 | |
| 463 | h, err = w.copyFileToStorage(path) |
| 464 | if err != nil { |
| 465 | if os.IsNotExist(err) { |
| 466 | added = true |
| 467 | h, err = w.deleteFromIndex(idx, path) |
| 468 | } |
| 469 | |
| 470 | return |
| 471 | } |
| 472 | |
| 473 | if err := w.addOrUpdateFileToIndex(idx, path, h); err != nil { |
| 474 | return false, h, err |
| 475 | } |
| 476 | |
| 477 | return true, h, err |
| 478 | } |
| 479 | |
| 480 | func (w *Worktree) copyFileToStorage(path string) (hash plumbing.Hash, err error) { |
| 481 | fi, err := w.Filesystem.Lstat(path) |
no test coverage detected