Conditional Gitignore

3.7k views Asked by At

I have a git repo in which I store my personal documents. Some of these documents are LaTeX files and some even are PDFs. I of course want them to be in my documents repo.

But when I create an org-mode document (*.org), I often build it, resulting in these files being created if the org-mode document is called α:

  • α.tex
  • α.pdf
  • auto/α.el

I don't want to track them as they are generated files of which I have the source code but I can't simply ignore all *.tex and not even all *.pdf files.

Can a .gitignore be told to ignore every file whose name is α.tex or α.pdf if there is a file called α.org with α being a variable for an arbitrary string?

1

There are 1 answers

0
Zbynek Vyskovsky - kvr000 On BEST ANSWER

This is not possible, .gitignore is quite simple file and doesn't allow any conditional rules.

However, generally good idea is to prepare the build system to generate all the intermediate files into some build directory. Often is used build or target. Then you could simply put into .gitignore:

/target # / specifies the root path
/auto # probably your temporary files...?

If the compiling is done with Makefile, the rules can look like:

target/%.pdf: target/%.tex
         $(LATEX) -o $@ $<
target/%.tex: %.org
         generate_tex -o $@ $<

(not sure so much about syntax for latex and of course the specific command for generating *.tex from *.org)