[proposal] Custom git diff rendering for binary files #5765

Open
opened 2025-11-02 06:35:18 -06:00 by GiteaMirror · 1 comment
Owner

Originally created by @HarvsG on GitHub (Jul 21, 2020).

Currently gitea only shows git diffs for text files, and can't for binary files.

image

git diff has native support for custom drivers for converting binary files to text in order to display a diff.

Since gitea just runs the git diff command and parses stdout we can leverage this
9542b7317d/services/gitdiff/gitdiff.go (L717)

By customising git config --global --edit and adding:

[core]
        quotePath = false
        attributesfile = /root/gitea/custom/git/.gitattributes
[diff "pandoc"]
     textconv=pandoc --to=markdown
     prompt = false

Which is equivalent to running:

git config --global core.attributesfile /root/gitea/custom/git/.gitattributes
git config --global diff.pandoc.textconv "pandoc --to=markdown"
git config --global diff.pandoc.prompt false

And then creating the file /root/gitea/custom/git/.gitattributes with contents:

*.docx diff=pandoc

We get a much better outpjut:
image

The proposal

I propse that we allow users to implement this in an easier way, this could be done in a number of ways.

  1. Allow the user to customise their git config --global file - default location being /root/.gitconfig
    1. by using the includes field with value $GITEA_CUSTOM/git/config and allowing the user to configure that as they please
    2. or by creating a new section in app.ini called something like [git.config] and allow the user to build a git config from the entries there - this may require translation between .ini syntax and whatever syntax git config uses
  2. Expand the external renderer section with new fields CUSTOM_DIFF and TEXTCONV_DIFF_COMMAND and use that to autopopulate /root/.gitconfig and a .gitattributes file

Note 1.a and 1.b generailse to allow the user to configure all of the git config options, 2 is specific to the rendering of diffs

Originally created by @HarvsG on GitHub (Jul 21, 2020). Currently gitea only shows git diffs for text files, and can't for binary files. ![image](https://user-images.githubusercontent.com/11440490/88071353-9d58c080-cb6b-11ea-8aa5-11179265df9a.png) `git diff` has [native support](https://git.wiki.kernel.org/index.php/Textconv) for custom drivers for converting binary files to text in order to display a diff. Since gitea just runs the `git diff` command and parses `stdout` we can leverage this https://github.com/go-gitea/gitea/blob/9542b7317da36f366545803f77e250036b168318/services/gitdiff/gitdiff.go#L717 By customising `git config --global --edit` and adding: ```ini [core] quotePath = false attributesfile = /root/gitea/custom/git/.gitattributes [diff "pandoc"] textconv=pandoc --to=markdown prompt = false ``` Which is equivalent to running: ```bash git config --global core.attributesfile /root/gitea/custom/git/.gitattributes git config --global diff.pandoc.textconv "pandoc --to=markdown" git config --global diff.pandoc.prompt false ``` And then creating the file `/root/gitea/custom/git/.gitattributes` with contents: ```ini *.docx diff=pandoc ``` We get a much better outpjut: ![image](https://user-images.githubusercontent.com/11440490/88071915-53bca580-cb6c-11ea-92df-96bb90b4e234.png) ## The proposal I propse that we allow users to implement this in an easier way, this could be done in a number of ways. 1. Allow the user to customise their `git config --global` file - default location being `/root/.gitconfig` 1. by using the [includes](https://git-scm.com/docs/git-config#_includes) field with value `$GITEA_CUSTOM/git/config` and allowing the user to configure that as they please 2. or by creating a new section in `app.ini` called something like [git.config] and allow the user to build a git config from the entries there - this may require translation between `.ini` syntax and whatever syntax `git config` uses 2. Expand the [external renderer](https://docs.gitea.io/en-us/external-renderers/) section with new fields `CUSTOM_DIFF` and `TEXTCONV_DIFF_COMMAND` and use that to autopopulate `/root/.gitconfig` and a `.gitattributes` file Note `1.a` and `1.b` generailse to allow the user to configure [all of the git config options](https://git-scm.com/docs/git-config), `2` is specific to the rendering of diffs
GiteaMirror added the type/proposaltopic/content-rendering labels 2025-11-02 06:35:18 -06:00
Author
Owner

@HarvsG commented on GitHub (Jul 21, 2020):

Currently git config is run here in the checkAndSetConfig() command
ae3cfa8449/modules/git/git.go (L159-L161)

here (not sure this one is relevant)
c52d48aae4/services/pull/merge.go (L159-L168)

and here (also probably not relevant)
801843b011/integrations/gitea-repositories-meta/user2/repo1.wiki.git/hooks/update.sample (L45-L50)

@HarvsG commented on GitHub (Jul 21, 2020): Currently `git config` is run here in the `checkAndSetConfig()` command https://github.com/go-gitea/gitea/blob/ae3cfa844945f446b511dbcae358b3f5b930b3ce/modules/git/git.go#L159-L161 here (not sure this one is relevant) https://github.com/go-gitea/gitea/blob/c52d48aae46af879fdfcfd94d03b7072878b5441/services/pull/merge.go#L159-L168 and here (also probably not relevant) https://github.com/go-gitea/gitea/blob/801843b0115e29ba2304fa6a5bea1ae169a58e02/integrations/gitea-repositories-meta/user2/repo1.wiki.git/hooks/update.sample#L45-L50
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#5765