Remove removes files from the working tree and from the index.
(path string)
| 553 | |
| 554 | // Remove removes files from the working tree and from the index. |
| 555 | func (w *Worktree) Remove(path string) (plumbing.Hash, error) { |
| 556 | // TODO(mcuadros): remove plumbing.Hash from signature at v5. |
| 557 | idx, err := w.r.Storer.Index() |
| 558 | if err != nil { |
| 559 | return plumbing.ZeroHash, err |
| 560 | } |
| 561 | |
| 562 | var h plumbing.Hash |
| 563 | |
| 564 | fi, err := w.Filesystem.Lstat(path) |
| 565 | if err != nil || !fi.IsDir() { |
| 566 | h, err = w.doRemoveFile(idx, path) |
| 567 | } else { |
| 568 | _, err = w.doRemoveDirectory(idx, path) |
| 569 | } |
| 570 | if err != nil { |
| 571 | return h, err |
| 572 | } |
| 573 | |
| 574 | return h, w.r.Storer.SetIndex(idx) |
| 575 | } |
| 576 | |
| 577 | func (w *Worktree) doRemoveDirectory(idx *index.Index, directory string) (removed bool, err error) { |
| 578 | files, err := w.Filesystem.ReadDir(directory) |