33 lines
581 B
Go
33 lines
581 B
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
|
|
"github.com/logrusorgru/aurora"
|
|
)
|
|
|
|
const (
|
|
largeFileLimit = 1 << 20 // 1MiB
|
|
)
|
|
|
|
func checkLargeFiles() error {
|
|
return filepath.Walk(".", checkLargeFilesW)
|
|
}
|
|
|
|
func checkLargeFilesW(path string, info os.FileInfo, err error) error {
|
|
switch {
|
|
case err != nil:
|
|
return err
|
|
case info.Size() > largeFileLimit:
|
|
return fmt.Errorf("committing large file: %s (%d bytes)",
|
|
aurora.Red(path), info.Size())
|
|
case info.IsDir() && strings.HasPrefix(info.Name(), "."):
|
|
return filepath.SkipDir
|
|
default:
|
|
return nil
|
|
}
|
|
}
|