Thank you joey for git annex diffdriver --text
, that is a big step towards easier diffing of annexed files. The following is now a copy-paste solution to 'make git diff work with git annex':
echo '* diff=annextextdiff' >> .git/info/attributes && git config diff.annextextdiff.command "git annex diffdriver --text"
This however then has git diff
use git-annex' diffing mechanism for all files, including normal git-tracked files. There probably is no gitattributes-way of applying a diff command only to annexed files, right?
Customizing diff
options
Apparently, git annex diffdriver --text
uses the system's diff
command and doesn't (allow to) give it any specific options. The below points could be worked around by having something like git annex diffdriver --text --diffopts='--color=auto'
so that the user can customize the diff
invocation. Alternatively you could introduce an environment variable like GIT_ANNEX_DIFFDRIVER_DIFF_OPTIONS
or shorter GIT_ANNEX_DIFF_FLAGS
that could also be used to temporarily diff that one file with specific options.
Coloring the output
How about passing the (sanitized, false
→never
and true
→auto
) git config color.diff
(and fallback color.ui
) setting as the diff --color=...
option? The experience would then match the users configured expectation.
Handling all files as text
diff
detects some files as binary, although it can make sense to text-diff them (e.g. PDFs), just to get an impression of the changes. diff
(and git diff
as well, AFAIK without any good workaround without an external driver again) then just displays the unhelpful message that the 'binary files differ' (you don't say...🙄).
How about having git annex diffdriver --text
always using diff --text
? That would deviate from the usual git diff
behaviour, but I argue that:
- a) People explicitly configure (a subset of) files in
.gitattributes
to be diffed withgit annex diffdriver --text
. - b) If they wouldn't care about the diff between files, then they wouldn't configure it.
- c) Tracking binary(-like) files is something git-annex is explicitly designed for, it makes sense that git just skips over those, but git-annex could add value here
Thanks again a ton for git-annex, the Tübix2023-Workshop was well appreciated and lots of fun. 👍
Yann
If your annexed files have a common extension you can match them in .gitattributes that way.
I've added support for passing options for diff. Eg:
As for passing --color automatically, I don't know if every diff(1) supports --color, and this would be more complexity.
I doubt that most users would appreciate diff --text by default for large binary files. That is really getting into territory that an external diff driver program can handle much better. Eg, if you're diffing jpegs and also zip files, you can write a diff driver program that lists the contents of zip files and passes that to diff, and that uses imagemagick
compare -compose
or https://github.com/x1ddos/imgdiff to show a visual diff between two jpegs.The point off the --text option is that sometimes you know you have plain text and so writing such a program is not necessary.