Skip to content

Commit

Permalink
.gitattributes: treat all *.pdf files as binary
Browse files Browse the repository at this point in the history
Some students may wish to commit PDF files into their downstream repos.

The PDF file format[1] is _mostly_ text-like. As such, it is likely that
the first 8000 bytes of any PDF file will _not_ contain a NUL byte,
leading Git to treat the PDF file as a text file[2].

In AddressBook-Level4, our Travis `run-checks` scripts requires all text
files, as determined by Git, to fulfill certain requirements such as
only having LF line endings and not having any trailing whitespace.

However, PDF files, although usually determined by Git to be text files,
may not actually be _fully_ text. Particularly, PDF files may contain
embedded binary streams which contain arbitrary binary data.

This arbitrary binary data can cause PDF files to fail our Travis
`run-checks` scripts.

Given that PDFs _can_ contain binary data, it would thus make more sense
to treat the entire file as binary. This both allows them to pass our
`run-checks` scripts, as well as to prevent Git from giving
not-very-useful text diffs when the PDF files are modified.

As such, let's tell Git to treat all *.pdf files as binary.

[1] https://en.wikipedia.org/wiki/PDF#File_structure
[2] https://github.com/git/git/blob/ffc6fa0e396238de3a30623912980263b4f283ab/xdiff-interface.c#L201-L207
  • Loading branch information
pyokagan committed Jul 28, 2018
1 parent ac37d6e commit b410fca
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pdf binary

0 comments on commit b410fca

Please sign in to comment.