2019-07-29 17:18:22 +02:00
|
|
|
package ignore
|
|
|
|
|
|
|
|
import (
|
2020-05-15 16:34:39 +02:00
|
|
|
"github.com/tilt-dev/tilt/internal/dockerignore"
|
|
|
|
"github.com/tilt-dev/tilt/pkg/model"
|
2019-07-29 17:18:22 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
// Filter out spurious changes that we don't want to rebuild on, like IDE
|
|
|
|
// temp/lock files.
|
|
|
|
//
|
|
|
|
// This isn't an ideal solution. In an ideal world, the user would put
|
|
|
|
// everything to ignore in their tiltignore/dockerignore files. This is a
|
|
|
|
// stop-gap so they don't have a terrible experience if those files aren't
|
|
|
|
// there or aren't in the right places.
|
|
|
|
//
|
|
|
|
// https://app.clubhouse.io/windmill/story/691/filter-out-ephemeral-file-changes
|
2021-03-09 19:05:32 +01:00
|
|
|
var EphemeralPathMatcher = initEphemeralPathMatcher()
|
2019-07-29 17:18:22 +02:00
|
|
|
|
|
|
|
func initEphemeralPathMatcher() model.PathMatcher {
|
2019-08-15 20:38:44 +02:00
|
|
|
golandPatterns := []string{"**/*___jb_old___", "**/*___jb_tmp___", "**/.idea/**"}
|
2019-07-29 17:18:22 +02:00
|
|
|
emacsPatterns := []string{"**/.#*"}
|
2019-09-12 17:57:39 +02:00
|
|
|
// if .swp is taken (presumably because multiple vims are running in that dir),
|
|
|
|
// vim will go with .swo, .swn, etc, and then even .svz, .svy!
|
|
|
|
// https://github.com/vim/vim/blob/ea781459b9617aa47335061fcc78403495260315/src/memline.c#L5076
|
|
|
|
// ignoring .sw? seems dangerous, since things like .swf or .swi exist, but ignoring the first few
|
|
|
|
// seems safe and should catch most cases
|
|
|
|
vimPatterns := []string{"**/4913", "**/*~", "**/.*.swp", "**/.*.swx", "**/.*.swo", "**/.*.swn"}
|
2020-05-27 16:36:06 +02:00
|
|
|
// kate (the default text editor for KDE) uses a file similar to Vim's .swp
|
|
|
|
// files, but it doesn't have the "incrememnting" character problem mentioned
|
|
|
|
// above
|
|
|
|
katePatterns := []string{"**/.*.kate-swp"}
|
2019-07-29 17:18:22 +02:00
|
|
|
|
|
|
|
allPatterns := []string{}
|
|
|
|
allPatterns = append(allPatterns, golandPatterns...)
|
|
|
|
allPatterns = append(allPatterns, emacsPatterns...)
|
|
|
|
allPatterns = append(allPatterns, vimPatterns...)
|
2020-05-27 16:36:06 +02:00
|
|
|
allPatterns = append(allPatterns, katePatterns...)
|
2019-07-29 17:18:22 +02:00
|
|
|
|
|
|
|
matcher, err := dockerignore.NewDockerPatternMatcher("/", allPatterns)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return matcher
|
|
|
|
}
|