Last week I posted about Kruftle, my open source cleaner for old build folders. Someone commented with a simple question: what does it do when a build folder is actually committed to the repo?
I answered from memory. Then I went and tested it, and my answer was wrong.
What broke
Kruftle has a git guard. It never deletes a folder outright if git tracks anything in it. I thought that covered everything.
It didn't. The guard only checked Kruftle's own deletes. For Gradle projects, Kruftle runs the project's own clean command (gradlew clean, or gradle clean). That command doesn't know about the guard. In a repo that commits files under build/, including in a nested subproject, gradle clean removed them. A rebuild wouldn't bring them back.
The exact kind of loss I wrote the post to warn about, and my own tool could cause it.
The fix in 0.2.14
Before running any clean command, Kruftle now works out which folders that command would clear. It asks git whether any of them contains tracked files. If one does, the clean command is skipped for that project, and the review screen says so, so it isn't a silent skip.
This applies to every toolchain, not just Gradle. Gradle was just where I hit it.
Also in 0.2.13
Kruftle now recognises Godot, Elm, CocoaPods, and Turborepo/Nx cache folders. Two new contributors sent PRs for that, which was a nice surprise.
What I learned
A safety rule is only as wide as the code path it sits on. I had guarded the delete I wrote, and not the delete I delegated.
And answering a question honestly, even when it means finding out your own post overstated things, was worth more than a clean reply.
Kruftle is free and open source for Windows, macOS and Linux: https://github.com/dizitart/kruftle?utm_source=devto&utm_medium=community&utm_campaign=release-0-2-14
It's still young. If you have a repo with committed build output, I'd really like to know if you find another way to make it delete something it shouldn't. What other tools do you trust to run clean commands for you?
