MCPcopy
hub / github.com/go-git/go-git / doClean

Method doClean

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

Source from the content-addressed store, hash-verified

842}
843
844func (w *Worktree) doClean(status Status, opts *CleanOptions, dir string, files []os.FileInfo) error {
845 for _, fi := range files {
846 if fi.Name() == GitDirName {
847 continue
848 }
849
850 // relative path under the root
851 path := filepath.Join(dir, fi.Name())
852 if fi.IsDir() {
853 if !opts.Dir {
854 continue
855 }
856
857 subfiles, err := w.Filesystem.ReadDir(path)
858 if err != nil {
859 return err
860 }
861 err = w.doClean(status, opts, path, subfiles)
862 if err != nil {
863 return err
864 }
865 } else {
866 if status.IsUntracked(path) {
867 if err := w.Filesystem.Remove(path); err != nil {
868 return err
869 }
870 }
871 }
872 }
873
874 if opts.Dir && dir != "" {
875 _, err := removeDirIfEmpty(w.Filesystem, dir)
876 return err
877 }
878
879 return nil
880}
881
882// GrepResult is structure of a grep result.
883type 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