From cf85e9eb7b125156fc3289f6a1306e16b748929b Mon Sep 17 00:00:00 2001 From: Siarhei Navatski Date: Fri, 22 Jul 2016 21:18:56 +0300 Subject: [PATCH] add IsSubmodule field to DiffFile and hide view file button on diff page for submodules (#3097) --- models/git_diff.go | 6 +++++- templates/repo/diff_box.tmpl | 16 +++++++++------- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/models/git_diff.go b/models/git_diff.go index f893200876b..33a63295f02 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -160,6 +160,7 @@ type DiffFile struct { IsDeleted bool IsBin bool IsRenamed bool + IsSubmodule bool Sections []*DiffSection IsIncomplete bool } @@ -306,7 +307,7 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* } curFileLinesCount = 0 - // Check file diff type. + // Check file diff type and is submodule. for { line, err := input.ReadString('\n') if err != nil { @@ -333,6 +334,9 @@ func ParsePatch(maxLines, maxLineCharacteres, maxFiles int, reader io.Reader) (* curFile.Name = b } if curFile.Type > 0 { + if strings.HasSuffix(line, " 160000\n") { + curFile.IsSubmodule = true + } break } } diff --git a/templates/repo/diff_box.tmpl b/templates/repo/diff_box.tmpl index a0565e6c8dd..76a414d23e1 100644 --- a/templates/repo/diff_box.tmpl +++ b/templates/repo/diff_box.tmpl @@ -68,13 +68,15 @@ {{end}} {{if $file.IsRenamed}}{{$file.OldName}} → {{end}}{{$file.Name}} -
- {{if $file.IsDeleted}} - {{$.i18n.Tr "repo.diff.view_file"}} - {{else}} - {{$.i18n.Tr "repo.diff.view_file"}} - {{end}} -
+ {{if not $file.IsSubmodule}} +
+ {{if $file.IsDeleted}} + {{$.i18n.Tr "repo.diff.view_file"}} + {{else}} + {{$.i18n.Tr "repo.diff.view_file"}} + {{end}} +
+ {{end}}
{{if not $file.IsRenamed}}