mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 08:30:25 +08:00 
			
		
		
		
	Merge pull request #59 from andreynering/gitea/fix-500-on-invalid-editorconfig
Fix 500 when repo has invalid .editorconfig
This commit is contained in:
		@@ -179,12 +179,10 @@ func Diff(ctx *context.Context) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ec, err := ctx.Repo.GetEditorconfig()
 | 
						setEditorconfigIfExists(ctx)
 | 
				
			||||||
	if err != nil && !git.IsErrNotExist(err) {
 | 
						if ctx.Written() {
 | 
				
			||||||
		ctx.Handle(500, "ErrGettingEditorconfig", err)
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ctx.Data["Editorconfig"] = ec
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ctx.Data["CommitID"] = commitID
 | 
						ctx.Data["CommitID"] = commitID
 | 
				
			||||||
	ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
 | 
						ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										23
									
								
								routers/repo/middlewares.go
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								routers/repo/middlewares.go
									
									
									
									
									
										Normal file
									
								
							@@ -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
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
@@ -368,12 +368,10 @@ func ViewPullFiles(ctx *context.Context) {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ec, err := ctx.Repo.GetEditorconfig()
 | 
						setEditorconfigIfExists(ctx)
 | 
				
			||||||
	if err != nil && !git.IsErrNotExist(err) {
 | 
						if ctx.Written() {
 | 
				
			||||||
		ctx.Handle(500, "ErrGettingEditorconfig", err)
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ctx.Data["Editorconfig"] = ec
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
 | 
						headTarget := path.Join(pull.HeadUserName, pull.HeadRepo.Name)
 | 
				
			||||||
	ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
 | 
						ctx.Data["IsSplitStyle"] = ctx.Query("style") == "split"
 | 
				
			||||||
@@ -627,12 +625,10 @@ func CompareAndPullRequest(ctx *context.Context) {
 | 
				
			|||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ec, err := ctx.Repo.GetEditorconfig()
 | 
						setEditorconfigIfExists(ctx)
 | 
				
			||||||
	if err != nil && !git.IsErrNotExist(err) {
 | 
						if ctx.Written() {
 | 
				
			||||||
		ctx.Handle(500, "ErrGettingEditorconfig", err)
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ctx.Data["Editorconfig"] = ec
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ctx.HTML(200, COMPARE_PULL)
 | 
						ctx.HTML(200, COMPARE_PULL)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -245,12 +245,10 @@ func Home(ctx *context.Context) {
 | 
				
			|||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	ec, err := ctx.Repo.GetEditorconfig()
 | 
						setEditorconfigIfExists(ctx)
 | 
				
			||||||
	if err != nil && !git.IsErrNotExist(err) {
 | 
						if ctx.Written() {
 | 
				
			||||||
		ctx.Handle(500, "Repo.GetEditorconfig", err)
 | 
					 | 
				
			||||||
		return
 | 
							return
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	ctx.Data["Editorconfig"] = ec
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	var treeNames []string
 | 
						var treeNames []string
 | 
				
			||||||
	paths := make([]string, 0, 5)
 | 
						paths := make([]string, 0, 5)
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user