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

Function rmFileAndDirsIfEmpty

worktree.go:1053–1076  ·  view source on GitHub ↗

will walk up the directory tree removing all encountered empty directories, not just the one containing this file

(fs billy.Filesystem, name string)

Source from the content-addressed store, hash-verified

1051// will walk up the directory tree removing all encountered empty
1052// directories, not just the one containing this file
1053func rmFileAndDirsIfEmpty(fs billy.Filesystem, name string) error {
1054 if err := util.RemoveAll(fs, name); err != nil {
1055 return err
1056 }
1057
1058 dir := filepath.Dir(name)
1059 for {
1060 removed, err := removeDirIfEmpty(fs, dir)
1061 if err != nil {
1062 return err
1063 }
1064
1065 if !removed {
1066 // directory was not empty and not removed,
1067 // stop checking parents
1068 break
1069 }
1070
1071 // move to parent directory
1072 dir = filepath.Dir(dir)
1073 }
1074
1075 return nil
1076}
1077
1078// removeDirIfEmpty will remove the supplied directory `dir` if
1079// `dir` is empty

Callers 1

checkoutChangeMethod · 0.85

Calls 1

removeDirIfEmptyFunction · 0.85

Tested by

no test coverage detected