MCPcopy Create free account
hub / github.com/go-git/go-git / doClean

Method doClean

worktree.go:871–907  ·  view source on GitHub ↗
(status Status, opts *CleanOptions, dir string, files []os.FileInfo)

Source from the content-addressed store, hash-verified

869}
870
871func (w *Worktree) doClean(status Status, opts *CleanOptions, dir string, files []os.FileInfo) error {
872 for _, fi := range files {
873 if fi.Name() == GitDirName {
874 continue
875 }
876
877 // relative path under the root
878 path := filepath.Join(dir, fi.Name())
879 if fi.IsDir() {
880 if !opts.Dir {
881 continue
882 }
883
884 subfiles, err := w.Filesystem.ReadDir(path)
885 if err != nil {
886 return err
887 }
888 err = w.doClean(status, opts, path, subfiles)
889 if err != nil {
890 return err
891 }
892 } else {
893 if status.IsUntracked(path) {
894 if err := w.Filesystem.Remove(path); err != nil {
895 return err
896 }
897 }
898 }
899 }
900
901 if opts.Dir && dir != "" {
902 _, err := removeDirIfEmpty(w.Filesystem, dir)
903 return err
904 }
905
906 return nil
907}
908
909// GrepResult is structure of a grep result.
910type GrepResult struct {

Callers 1

CleanMethod · 0.95

Calls 7

removeDirIfEmptyFunction · 0.85
JoinMethod · 0.80
IsUntrackedMethod · 0.80
NameMethod · 0.65
IsDirMethod · 0.65
ReadDirMethod · 0.45
RemoveMethod · 0.45

Tested by

no test coverage detected