bacon icon indicating copy to clipboard operation
bacon copied to clipboard

Bacon should ignore changes to editor temporary or lock files

Open bruceg opened this issue 3 years ago • 3 comments

Some editors create temporary or lock files in the same directory as the file being edited. For example vi/vim will create a file named .FILENAME.swp when the file is first opened for editing, and emacs will create a link named .#FILENAME when a file open for editing has unsaved changes. When these files are created, they trigger an unnecessary extra run of the current job.

See https://github.com/watchexec/watchexec/blob/35e39afb95d5c66b41f843ce8850ee8da37a5516/src/cli.rs#L265 for a good starting point on which file patterns can be safely ignored. Obviously the *.py? patterns don't apply here.

bruceg avatar Jan 18 '21 18:01 bruceg

OK. Note that if you're willing to make a tested PR, it could be welcome.

Canop avatar Jan 18 '21 18:01 Canop

Hmm, this is tricky in two ways:

  1. Technically you can include any file with include_bytes!, even temporary or generated files
  2. Use a whitelist of patterns is too coarse, because it will rebuild even if it doesn't need to for files that aren't in the module hierarchy

I think the ideal solution would be to use --emit=dep-info to tell exactly what files need to be watched. This file is in make syntax so it's annoying to parse, but there's a function in cargo you could copy-paste: https://github.com/rust-lang/cargo/blob/c524fa4e36b1b6134bf6d1fc17f0648f194118c7/src/cargo/core/compiler/fingerprint.rs#L1974

jyn514 avatar Jan 19 '21 05:01 jyn514

An alternative, at least for git users, would be to leverage the ignore list.

Canop avatar Jan 19 '21 05:01 Canop

Similar issue here while using insta: https://github.com/mitsuhiko/insta

Failing tests create temporary snapshots with a .new extension for review.

So when running bacon test, if it fails it creates a new file, which triggers the watch, which loops forever and makes everything buggy.

mrtolkien avatar Dec 26 '22 13:12 mrtolkien

I'm preparing a PR avoiding launching jobs when the modified files are excluded by gitignore rules: https://github.com/Canop/bacon/pull/98

Can you test it and tell me how well it works for you ?

Canop avatar Dec 29 '22 08:12 Canop

Compiled and tried it and it works properly. As the temp files are called .new it was indeed the right workflow. Thanks for the help and the quick addition!

mrtolkien avatar Dec 30 '22 06:12 mrtolkien

released in 2.3.0

Canop avatar Dec 30 '22 16:12 Canop

Woops! This broke my use case where I literate-compile markdown files into rust, the markdown files are checked-in, but I .gitignore built files such as src/ and Cargo.toml

Bacon now doesn't see changes to my src/ files.

Is there an override? I acknowledge I might be the only one using bacon like this XD

0atman avatar Jan 22 '23 17:01 0atman

bacon -p src/ does not override the gitignore behaviour

0atman avatar Jan 22 '23 18:01 0atman

Aha @Canop thought of everything, there's a way to ignore it with job.apply_gitignore testing now, thank you

0atman avatar Jan 22 '23 18:01 0atman

apply_gitignore = false

in bacon.toml did the trick, thank you!

Full example if anyone sees this:

[jobs.clippy]
command = ["cargo", "clippy", "--color", "always", "--", "-W", "clippy::pedantic"]
need_stdout = false
apply_gitignore = false

0atman avatar Jan 22 '23 18:01 0atman