bacon icon indicating copy to clipboard operation
bacon copied to clipboard

Don't ignore files that have been added to a job's watch list

Open irh opened this issue 11 months ago • 6 comments

I'm doing some interactive testing on a temp file that I don't want to commit, using a file name that's in my global .gitignore.

So, I have a job where I've added the file to the watch list, and then I'd like it if GitIgnorer would make an exception for the explicitly watched file, instead of telling the watcher that it's OK to ignore it.

irh avatar Jan 17 '25 15:01 irh

This makes sense but it's not so obvious because you usually add whole dirs to watch.

What about this case ?

  • you add *.backup to your .gitignore because your IDE randomly creates such files
  • you then add amber-src because that's where the language you use bacon for stores its source files

If you decide to ignore all *.backup in amber-src, you make a mess.

I feel like we should rather leverage the ignore field and allow negative patterns.

Canop avatar Jan 17 '25 15:01 Canop

I'm sure I haven't fully thought this through, but with my user hat on I guess I would expect:

  • If I've explicitly listed something in watch then it should override .git-ignore.
  • If it's a specific file then it should be watched, no questions asked.
  • If I list a directory that's in .git-ignore then I think it should be watched while respecting .git-ignore rules for its contents.
    • So if I add amber-src, then nested *.backup files would be ignored, while watching other files that aren't ignored by .git-ignore.
    • If I wanted I could then add *.backup to watch to override .git-ignore.

I feel like we should rather leverage the ignore field and allow negative patterns.

If there's an easy way to do this for a single file then I'm all for it!

irh avatar Jan 17 '25 16:01 irh

What I propose is to support having negative patterns like this

ignore = [
     "!myfiles"
]

in your job for the files that are in a .gitignore or a .ignore file but should be watched nevertheless.

Canop avatar Jan 17 '25 16:01 Canop

I think I get it, so in my case I would have:

watch = ["myfile.txt"]     # Watch a non-standard file that's in .gitignore
ignore = ["!myfile.txt"]   # Override .gitignore

Is that right?

irh avatar Jan 17 '25 16:01 irh

Yes. This specific example looks tedious but it looks, to me, more compatible with the ignore chain logic.

Canop avatar Jan 17 '25 16:01 Canop

As an example of a concrete case I would use this for, .env files are pretty common to put in .gitignore since they may contain secrets/tokens etc., but it would be great to have bacon automatically reload a job when the .env file changes.

I wonder if adding a file to watch could just automatically add a !file entry in the ignore list for convenience to avoid the "double" configuration like that... It might be a little too magic (or cause weird other side effects) but seems like it would be more intuitive than the example above.

ian-h-chamberlain avatar Mar 07 '25 15:03 ian-h-chamberlain