diff --git a/git/diff.go b/git/diff.go index 38c00f2..063ac87 100644 --- a/git/diff.go +++ b/git/diff.go @@ -20,6 +20,7 @@ type Diff struct { New string } TextFragments []TextFragment + IsBinary bool } // A nicer git diff representation. @@ -88,6 +89,7 @@ func (g *GitRepo) Diff() (*NiceDiff, error) { 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{ diff --git a/git/git.go b/git/git.go index 3756840..34e8a80 100644 --- a/git/git.go +++ b/git/git.go @@ -76,7 +76,13 @@ func (g *GitRepo) FileContent(path string) (string, error) { 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) { diff --git a/templates/commit.html b/templates/commit.html index 1b4a8d9..b1b3cbc 100644 --- a/templates/commit.html +++ b/templates/commit.html @@ -55,7 +55,9 @@ {{ .Name.New }} {{- end -}} - + {{ if .IsBinary }} +

Not showing binary file.

+ {{ else }}
             {{- range .TextFragments -}}
             

{{- .Header -}}

@@ -71,6 +73,7 @@ {{- end -}} {{- end -}} {{- end -}} + {{- end -}}
{{ end }}