git: check for binary files
Anirudh Oppiliappan x@icyphox.sh
Mon, 19 Dec 2022 11:36:50 +0530
3 files changed,
13 insertions(+),
2 deletions(-)
M
git/diff.go
→
git/diff.go
@@ -20,6 +20,7 @@ Old string
New string } TextFragments []TextFragment + IsBinary bool } // A nicer git diff representation.@@ -88,6 +89,7 @@ for _, d := range diffs {
ndiff := Diff{} ndiff.Name.New = d.NewName ndiff.Name.Old = d.OldName + ndiff.IsBinary = d.IsBinary for _, tf := range d.TextFragments { ndiff.TextFragments = append(ndiff.TextFragments, TextFragment{
M
git/git.go
→
git/git.go
@@ -76,7 +76,13 @@ if err != nil {
return "", err } - return file.Contents() + isbin, _ := file.IsBinary() + + if !isbin { + return file.Contents() + } else { + return "Not displaying binary file", nil + } } func (g *GitRepo) Tags() ([]*object.Tag, error) {
M
templates/commit.html
→
templates/commit.html
@@ -55,7 +55,9 @@ {{ else }}
<a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a> {{- end -}} </div> - + {{ if .IsBinary }} + <p>Not showing binary file.</p> + {{ else }} <pre> {{- range .TextFragments -}} <p>{{- .Header -}}</p>@@ -71,6 +73,7 @@ <span class="diff-noop">{{ .String }}</span>
{{- end -}} {{- end -}} {{- end -}} + {{- end -}} </pre> </div> {{ end }}