Flagging Files that Ignore Files Match
Zürich, Schweiz
I found myself wanting an tool recently, and I was honestly surprised that none already existed to do this. What was it that I wanted? Rather simply a way identify files in a project tree that a .gitignore file or similar would ignore. Namely I wanted to identify files that would be ignored and delete them in certain programmatic workflows.
Suppose we have a project directory structure like follows:
| |
If we examine the .gitignore file:
| |
Pretty rudimentary, but I’d want a tool that could flag directory dist as being a target to remove. If you’re reasonably familiar with Git, you’d say: Git already has the functionality built in, and you’d be correct — to an extent. It does, but it’s not extensible outside of Git, which leads me to my next point:
Above when I say “or similar,” this invites an interesting question: what other types of files are there? In my case, I am having to deal with .gcloudignore, too. I recall there being .dockerignore. After a bit of digging, it appears that the list of these files goes on further. Does this class of files have a formal name? Not that I could find, but how about we just call them “ignore files” for the sake of it.
So I built a tool to do this:
| |
It can be run largely as follows (using our QuakeC scenario above):
| |
And if one wanted to be so bold:
| |
I had envisioned that I could use it with .gcloudignore files, as these were the main motivation of creating this tool. It turns out there are a few bugs in the gcloud CLI in terms of it ignoring simple directives when over-broadly copying file assets. I checked with a trusted expert friend, and it appears that this is a real bug as opposed to a case of PEBCAK on my side. In short, this tool shouldn’t even exist short of needing to the dreaded incantation in some stateless CI/CD pipeline:
| |
You see: I wouldn’t want to build a tool like this myself nor even be doing this in the first place. But here we are.
As you can see by examining the source, there isn’t really that much meat to this tool. The real credit goes to Andrew Gallant for having created two useful APIs that made this possible.
- Automation (3)
- Cloud (2)
- Swe (19)
- Tools (2)