storj/scripts/check-clean-directory.go

57 lines
1.2 KiB
Go
Raw Normal View History

2019-01-24 20:15:10 +00:00
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// +build ignore
package main
import (
"fmt"
"os"
"os/exec"
"strings"
)
func main() {
cmd := exec.Command("git", "ls-files", ".", "--others")
out, err := cmd.Output()
if err != nil {
fmt.Println("Checking left-over files failed.")
fmt.Println(err)
os.Exit(1)
}
2019-04-24 16:33:01 +01:00
leftover := strings.Split(strings.TrimSpace(string(out)), "\n")
leftover = ignorePrefix(leftover, ".build")
// there's no easy way to modify npm to use tmp folders
leftover = ignorePrefix(leftover, "web/satellite/node_modules/")
leftover = ignorePrefix(leftover, "web/satellite/coverage/")
leftover = ignorePrefix(leftover, "web/satellite/dist/")
// TODO: shouldn't this be already up to date?
leftover = ignorePrefix(leftover, "web/satellite/package-lock.json")
2019-04-24 16:33:01 +01:00
if len(leftover) != 0 {
fmt.Println("Files left-over after running tests:")
2019-04-24 16:33:01 +01:00
for _, file := range leftover {
fmt.Println(file)
}
os.Exit(1)
}
}
2019-04-24 16:33:01 +01:00
func ignorePrefix(files []string, dir string) []string {
2019-04-24 16:33:01 +01:00
result := files[:0]
for _, file := range files {
if file == "" {
continue
}
if strings.HasPrefix(file, dir) {
continue
}
result = append(result, file)
}
return result
}