dandavison / delta

A syntax-highlighting pager for git, diff, grep, and blame output
https://dandavison.github.io/delta/
MIT License
24.37k stars 391 forks source link

🐛 delta won't show diffs of files marked as autogenerated with `.gitattributes` even though they're text files #1623

Open matteematt opened 9 months ago

matteematt commented 9 months ago

Thanks for filing a Delta bug report!

We use .gitattributes on our project to mark certain files as autogenearted, so in Github they are not expanded when the revieiwer is looking at the code. This could be to mark output js files transpiled from ts files, or autogenerated markdown files.

An example of the file to mark the markdown files.

*.md -diff
*.md linguist-generated

In diff tools such as vscode I get expected diff output still, but delta just gives me info about how this is a binary file and I can't see the diff.

Output from delta:

Screenshot 2024-02-12 at 10 44 10

Output with vscode diff vieiwer (this is what I expect)

Screenshot 2024-02-12 at 10 43 20

I understand that if I use the standard git diff without delta that it has the same issue, so the answer might be that this isn't possible. I just think there could be a way (potentially enabled with an option) if other tools can manage it.

imbrish commented 9 months ago

By unsetting the diff in .gitattributes, you are telling git that it is not possible to diff the *.md files. Which, if i understand correctly, is what you want on GitHub. The standard behavior is showing such files as binary. It has nothing to do with delta.

If you want to skip these diffs on GitHub, but generate them locally, I guess you could have another attributes file, not included in version control, where you tell git it should diff these files. I am a bit unsure about inheritance though.

matteematt commented 9 months ago

I did think that is the case, does that imply then that vscode is behaving how I want due to the fact that it's probably behaving incorrectly?

imbrish commented 9 months ago

I don't use vscode myself, but I would imagine it talks with git to be helpful, and not necessarily promises to follow all the rules.

0xjac commented 6 months ago

@imbrish I have a similar issue and a scenario which I believe to be relevant here:

I have generated files which are committed to a repo. Those files are marked as binary mainly to tell git to not perform any kind of merging on those files. It also hides the diffs on Github/Gitlab which is useful as they should not be reviewed/edited when merging.

However locally, there a few times where I do need to look at the code generation process and investigate what changed in those files. I can easily do this with git diff by passing the --text option, essentially telling git to treat those files as as text (which they actually are).

I want to use delta to do a diff between two generation versions of my files in two separate dir. Ideally I'd like to do delta dirA dirB. Since this calls git it doesn't work. My current work around is to call:

git diff --no-index --color --text -- dirA dirB | delta

which works but is a bit cumbersome.

I believe the issue is here where delta calls git but does not allow passing any extra options to git. It would be great if we could do something along the lines of

delta [OPTIONS] [MINUS_FILE] [PLUS_FILE] -- [GIT_OPTIONS]

which would look like delta dirA dirB -- --text.

th1000s commented 6 months ago

The gitattributes are applied to the output before it is sent to delta or any other pager, see git diff | less - this is what delta works on, and it already mentions binary files. Setting a different file via git -c core.attributesFile=my_gitattributes diff seemingly can not override the -diff setting.

However, in your specific case, @0xjac, PR #1697 will add an option so you can call -@=--text

0xjac commented 6 months ago

@th1000s I missed that PR. Thanks a lot, it seems perfect. I'll wait for it to be released. :rocket:

matteematt commented 3 months ago

HI @th1000s I can see that PR is merged now. What is the release cadence for being able to use this new option?

dandavison commented 3 months ago

Hi @matteematt, we just released 0.18.0 with the new -@ option (--diff-args). See --help for instructions.