RemoveGlob removes all paths, matching pattern, from the index. If pattern matches a directory path, all directory contents are removed from the index recursively.
(pattern string)
| 679 | // matches a directory path, all directory contents are removed from the index |
| 680 | // recursively. |
| 681 | func (w *Worktree) RemoveGlob(pattern string) error { |
| 682 | idx, err := w.r.Storer.Index() |
| 683 | if err != nil { |
| 684 | return err |
| 685 | } |
| 686 | |
| 687 | entries, err := idx.Glob(pattern) |
| 688 | if err != nil { |
| 689 | return err |
| 690 | } |
| 691 | |
| 692 | for _, e := range entries { |
| 693 | file := filepath.FromSlash(e.Name) |
| 694 | if _, err := w.Filesystem.Lstat(file); err != nil && !os.IsNotExist(err) { |
| 695 | return err |
| 696 | } |
| 697 | |
| 698 | if _, err := w.doRemoveFile(idx, file); err != nil { |
| 699 | return err |
| 700 | } |
| 701 | |
| 702 | dir, _ := filepath.Split(file) |
| 703 | if err := w.removeEmptyDirectory(dir); err != nil { |
| 704 | return err |
| 705 | } |
| 706 | } |
| 707 | |
| 708 | return w.r.Storer.SetIndex(idx) |
| 709 | } |
| 710 | |
| 711 | // Move moves or rename a file in the worktree and the index, directories are |
| 712 | // not supported. |