Remove removes files from the working tree and from the index.
(path string)
| 582 | |
| 583 | // Remove removes files from the working tree and from the index. |
| 584 | func (w *Worktree) Remove(path string) (plumbing.Hash, error) { |
| 585 | // TODO(mcuadros): remove plumbing.Hash from signature at v5. |
| 586 | idx, err := w.r.Storer.Index() |
| 587 | if err != nil { |
| 588 | return plumbing.ZeroHash, err |
| 589 | } |
| 590 | |
| 591 | var h plumbing.Hash |
| 592 | |
| 593 | fi, err := w.Filesystem.Lstat(path) |
| 594 | if err != nil || !fi.IsDir() { |
| 595 | h, err = w.doRemoveFile(idx, path) |
| 596 | } else { |
| 597 | _, err = w.doRemoveDirectory(idx, path) |
| 598 | } |
| 599 | if err != nil { |
| 600 | return h, err |
| 601 | } |
| 602 | |
| 603 | return h, w.r.Storer.SetIndex(idx) |
| 604 | } |
| 605 | |
| 606 | func (w *Worktree) doRemoveDirectory(idx *index.Index, directory string) (removed bool, err error) { |
| 607 | files, err := w.Filesystem.ReadDir(directory) |