In a project where for instance a parser is involved, some source code is the product of a program. For instance yacc
generates - based on a .yy
fi
My suggestion is create a script to update .gitignore. I don't know any, but you can look for a solution that runs this script automatically before a commit.
Edit: I Googled and found this: https://github.com/observing/pre-commit - Probably needs some tests.
I can see three ways to do this -- to answer the question directly, no, ignore processing consults only the pathname in question, not anything else about the environment.
Put your generated source in a generated
folder you ignore.
Me, I like this one best, I know I'm in a minority but I don't like build detritus in my source directories.
Have your makefile targets also update the .gitignore
, with
grep -qs ^target$ .gitignore || echo target >>.gitignore
where target
is the generated source file, as part of the recipe.
put some marker in the generated filenames themselves, scanner.generated.c
or something.
For some reason I really dislike the pre-commit hook cleaning out unwanted source, git deleting things from a commit all by itself is just disturbing.