Skip to content

Commit

Permalink
Merge pull request #59 from andreynering/gitea/fix-500-on-invalid-edi…
Browse files Browse the repository at this point in the history
…torconfig

Fix 500 when repo has invalid .editorconfig
  • Loading branch information
strk committed Nov 5, 2016
2 parents ab12596 + 984fa8d commit 789dacd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 16 deletions.
6 changes: 2 additions & 4 deletions routers/repo/commit.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,10 @@ func Diff(ctx *context.Context) {
}
}

ec, err := ctx.Repo.GetEditorconfig()
if err != nil && !git.IsErrNotExist(err) {
ctx.Handle(500, "ErrGettingEditorconfig", err)
setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}
ctx.Data["Editorconfig"] = ec

ctx.Data["CommitID"] = commitID
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
Expand Down
23 changes: 23 additions & 0 deletions routers/repo/middlewares.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package repo

import (
"fmt"

"github.com/go-gitea/gitea/models"
"github.com/go-gitea/gitea/modules/context"
"github.com/gogits/git-module"
)

func setEditorconfigIfExists(ctx *context.Context) {
ec, err := ctx.Repo.GetEditorconfig()

if err != nil && !git.IsErrNotExist(err) {
description := fmt.Sprintf("Error while getting .editorconfig file: %v", err)
if err := models.CreateRepositoryNotice(description); err != nil {
ctx.Handle(500, "ErrCreatingReporitoryNotice", err)
}
return
}

ctx.Data["Editorconfig"] = ec
}
12 changes: 4 additions & 8 deletions routers/repo/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,10 @@ func ViewPullFiles(ctx *context.Context) {
return
}

ec, err := ctx.Repo.GetEditorconfig()
if err != nil && !git.IsErrNotExist(err) {
ctx.Handle(500, "ErrGettingEditorconfig", err)
setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}
ctx.Data["Editorconfig"] = ec

headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
Expand Down Expand Up @@ -627,12 +625,10 @@ func CompareAndPullRequest(ctx *context.Context) {
}
}

ec, err := ctx.Repo.GetEditorconfig()
if err != nil && !git.IsErrNotExist(err) {
ctx.Handle(500, "ErrGettingEditorconfig", err)
setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}
ctx.Data["Editorconfig"] = ec

ctx.HTML(200, COMPARE_PULL)
}
Expand Down
6 changes: 2 additions & 4 deletions routers/repo/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,10 @@ func Home(ctx *context.Context) {
return
}

ec, err := ctx.Repo.GetEditorconfig()
if err != nil && !git.IsErrNotExist(err) {
ctx.Handle(500, "Repo.GetEditorconfig", err)
setEditorconfigIfExists(ctx)
if ctx.Written() {
return
}
ctx.Data["Editorconfig"] = ec

var treeNames []string
paths := make([]string, 0, 5)
Expand Down

0 comments on commit 789dacd

Please sign in to comment.