github.com/tilt-dev/tilt@v0.33.15-0.20240515162809-0a22ed45d8a0/internal/ignore/ephemeral.go (about)

     1  package ignore
     2  
     3  import (
     4  	"github.com/tilt-dev/tilt/internal/dockerignore"
     5  	"github.com/tilt-dev/tilt/pkg/model"
     6  )
     7  
     8  // EphemeralPathMatcher filters out spurious changes that we don't want to
     9  // rebuild on, like IDE temp/lock files.
    10  //
    11  // This isn't an ideal solution. In an ideal world, the user would put
    12  // everything to ignore in their tiltignore/dockerignore files. This is a
    13  // stop-gap so they don't have a terrible experience if those files aren't
    14  // there or aren't in the right places.
    15  //
    16  // https://app.clubhouse.io/windmill/story/691/filter-out-ephemeral-file-changes
    17  var EphemeralPathMatcher = initEphemeralPathMatcher()
    18  
    19  func initEphemeralPathMatcher() model.PathMatcher {
    20  	golandPatterns := []string{"**/*___jb_old___", "**/*___jb_tmp___", "**/.idea/**"}
    21  	emacsPatterns := []string{"**/.#*", "**/#*#"}
    22  	// if .swp is taken (presumably because multiple vims are running in that dir),
    23  	// vim will go with .swo, .swn, etc, and then even .svz, .svy!
    24  	// https://github.com/vim/vim/blob/ea781459b9617aa47335061fcc78403495260315/src/memline.c#L5076
    25  	// ignoring .sw? seems dangerous, since things like .swf or .swi exist, but ignoring the first few
    26  	// seems safe and should catch most cases
    27  	vimPatterns := []string{"**/4913", "**/*~", "**/.*.swp", "**/.*.swx", "**/.*.swo", "**/.*.swn"}
    28  	// kate (the default text editor for KDE) uses a file similar to Vim's .swp
    29  	// files, but it doesn't have the "incrememnting" character problem mentioned
    30  	// above
    31  	katePatterns := []string{"**/.*.kate-swp"}
    32  	// go stdlib creates tmpfiles to determine umask for setting permissions
    33  	// during file creation; they are then immediately deleted
    34  	// https://github.com/golang/go/blob/0b5218cf4e3e5c17344ea113af346e8e0836f6c4/src/cmd/go/internal/work/exec.go#L1764
    35  	goPatterns := []string{"**/*-go-tmp-umask"}
    36  
    37  	allPatterns := []string{}
    38  	allPatterns = append(allPatterns, golandPatterns...)
    39  	allPatterns = append(allPatterns, emacsPatterns...)
    40  	allPatterns = append(allPatterns, vimPatterns...)
    41  	allPatterns = append(allPatterns, katePatterns...)
    42  	allPatterns = append(allPatterns, goPatterns...)
    43  
    44  	matcher, err := dockerignore.NewDockerPatternMatcher("/", allPatterns)
    45  	if err != nil {
    46  		panic(err)
    47  	}
    48  	return matcher
    49  }