git: check for binary files
This commit is contained in:
parent
8ba1a9609a
commit
a05244018a
|
@ -20,6 +20,7 @@ type Diff struct {
|
||||||
New string
|
New string
|
||||||
}
|
}
|
||||||
TextFragments []TextFragment
|
TextFragments []TextFragment
|
||||||
|
IsBinary bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// A nicer git diff representation.
|
// A nicer git diff representation.
|
||||||
|
@ -88,6 +89,7 @@ func (g *GitRepo) Diff() (*NiceDiff, error) {
|
||||||
ndiff := Diff{}
|
ndiff := Diff{}
|
||||||
ndiff.Name.New = d.NewName
|
ndiff.Name.New = d.NewName
|
||||||
ndiff.Name.Old = d.OldName
|
ndiff.Name.Old = d.OldName
|
||||||
|
ndiff.IsBinary = d.IsBinary
|
||||||
|
|
||||||
for _, tf := range d.TextFragments {
|
for _, tf := range d.TextFragments {
|
||||||
ndiff.TextFragments = append(ndiff.TextFragments, TextFragment{
|
ndiff.TextFragments = append(ndiff.TextFragments, TextFragment{
|
||||||
|
|
|
@ -76,7 +76,13 @@ func (g *GitRepo) FileContent(path string) (string, error) {
|
||||||
return "", err
|
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) {
|
func (g *GitRepo) Tags() ([]*object.Tag, error) {
|
||||||
|
|
|
@ -55,7 +55,9 @@
|
||||||
<a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a>
|
<a href="/{{ $repo }}/blob/{{ $this }}/{{ .Name.New }}">{{ .Name.New }}</a>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
</div>
|
</div>
|
||||||
|
{{ if .IsBinary }}
|
||||||
|
<p>Not showing binary file.</p>
|
||||||
|
{{ else }}
|
||||||
<pre>
|
<pre>
|
||||||
{{- range .TextFragments -}}
|
{{- range .TextFragments -}}
|
||||||
<p>{{- .Header -}}</p>
|
<p>{{- .Header -}}</p>
|
||||||
|
@ -71,6 +73,7 @@
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
</pre>
|
</pre>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
Loading…
Reference in New Issue