mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 00:20:25 +08:00 
			
		
		
		
	Propagate context and ensure git commands run in request context (#17868)
This PR continues the work in #17125 by progressively ensuring that git commands run within the request context. This now means that the if there is a git repo already open in the context it will be used instead of reopening it. Signed-off-by: Andrew Thornton <art27@cantab.net>
This commit is contained in:
		@@ -778,10 +778,10 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
 | 
			
		||||
				m.Combo("/forks").Get(repo.ListForks).
 | 
			
		||||
					Post(reqToken(), reqRepoReader(unit.TypeCode), bind(api.CreateForkOption{}), repo.CreateFork)
 | 
			
		||||
				m.Group("/branches", func() {
 | 
			
		||||
					m.Get("", repo.ListBranches)
 | 
			
		||||
					m.Get("/*", repo.GetBranch)
 | 
			
		||||
					m.Delete("/*", context.ReferencesGitRepo(false), reqRepoWriter(unit.TypeCode), repo.DeleteBranch)
 | 
			
		||||
					m.Post("", reqRepoWriter(unit.TypeCode), bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
 | 
			
		||||
					m.Get("", context.ReferencesGitRepo(false), repo.ListBranches)
 | 
			
		||||
					m.Get("/*", context.ReferencesGitRepo(false), repo.GetBranch)
 | 
			
		||||
					m.Delete("/*", reqRepoWriter(unit.TypeCode), context.ReferencesGitRepo(false), repo.DeleteBranch)
 | 
			
		||||
					m.Post("", reqRepoWriter(unit.TypeCode), context.ReferencesGitRepo(false), bind(api.CreateBranchRepoOption{}), repo.CreateBranch)
 | 
			
		||||
				}, reqRepoReader(unit.TypeCode))
 | 
			
		||||
				m.Group("/branch_protections", func() {
 | 
			
		||||
					m.Get("", repo.ListBranchProtections)
 | 
			
		||||
@@ -957,7 +957,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
 | 
			
		||||
						Post(reqToken(), bind(api.CreateStatusOption{}), repo.NewCommitStatus)
 | 
			
		||||
				}, reqRepoReader(unit.TypeCode))
 | 
			
		||||
				m.Group("/commits", func() {
 | 
			
		||||
					m.Get("", repo.GetAllCommits)
 | 
			
		||||
					m.Get("", context.ReferencesGitRepo(false), repo.GetAllCommits)
 | 
			
		||||
					m.Group("/{ref}", func() {
 | 
			
		||||
						m.Get("/status", repo.GetCombinedCommitStatusByRef)
 | 
			
		||||
						m.Get("/statuses", repo.GetCommitStatusesByRef)
 | 
			
		||||
@@ -965,7 +965,7 @@ func Routes(sessioner func(http.Handler) http.Handler) *web.Route {
 | 
			
		||||
				}, reqRepoReader(unit.TypeCode))
 | 
			
		||||
				m.Group("/git", func() {
 | 
			
		||||
					m.Group("/commits", func() {
 | 
			
		||||
						m.Get("/{sha}", repo.GetSingleCommit)
 | 
			
		||||
						m.Get("/{sha}", context.ReferencesGitRepo(false), repo.GetSingleCommit)
 | 
			
		||||
						m.Get("/{sha}.{diffType:diff|patch}", repo.DownloadCommitDiffOrPatch)
 | 
			
		||||
					})
 | 
			
		||||
					m.Get("/refs", repo.GetGitAllRefs)
 | 
			
		||||
 
 | 
			
		||||
@@ -78,6 +78,7 @@ func Markdown(ctx *context.APIContext) {
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if err := markdown.Render(&markup.RenderContext{
 | 
			
		||||
			Ctx:       ctx,
 | 
			
		||||
			URLPrefix: urlPrefix,
 | 
			
		||||
			Metas:     meta,
 | 
			
		||||
			IsWiki:    form.Wiki,
 | 
			
		||||
@@ -87,6 +88,7 @@ func Markdown(ctx *context.APIContext) {
 | 
			
		||||
		}
 | 
			
		||||
	default:
 | 
			
		||||
		if err := markdown.RenderRaw(&markup.RenderContext{
 | 
			
		||||
			Ctx:       ctx,
 | 
			
		||||
			URLPrefix: form.Context,
 | 
			
		||||
		}, strings.NewReader(form.Text), ctx.Resp); err != nil {
 | 
			
		||||
			ctx.InternalServerError(err)
 | 
			
		||||
@@ -117,7 +119,9 @@ func MarkdownRaw(ctx *context.APIContext) {
 | 
			
		||||
	//   "422":
 | 
			
		||||
	//     "$ref": "#/responses/validationError"
 | 
			
		||||
	defer ctx.Req.Body.Close()
 | 
			
		||||
	if err := markdown.RenderRaw(&markup.RenderContext{}, ctx.Req.Body, ctx.Resp); err != nil {
 | 
			
		||||
	if err := markdown.RenderRaw(&markup.RenderContext{
 | 
			
		||||
		Ctx: ctx,
 | 
			
		||||
	}, ctx.Req.Body, ctx.Resp); err != nil {
 | 
			
		||||
		ctx.InternalServerError(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -52,7 +52,7 @@ func SigningKey(ctx *context.APIContext) {
 | 
			
		||||
		path = ctx.Repo.Repository.RepoPath()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	content, err := asymkey_service.PublicSigningKey(path)
 | 
			
		||||
	content, err := asymkey_service.PublicSigningKey(ctx, path)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "gpg export", err)
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -45,7 +45,7 @@ func GetBlob(ctx *context.APIContext) {
 | 
			
		||||
		ctx.Error(http.StatusBadRequest, "", "sha not provided")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if blob, err := files_service.GetBlobBySHA(ctx.Repo.Repository, sha); err != nil {
 | 
			
		||||
	if blob, err := files_service.GetBlobBySHA(ctx, ctx.Repo.Repository, sha); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusBadRequest, "", err)
 | 
			
		||||
	} else {
 | 
			
		||||
		ctx.JSON(http.StatusOK, blob)
 | 
			
		||||
 
 | 
			
		||||
@@ -53,7 +53,7 @@ func GetBranch(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	branchName := ctx.Params("*")
 | 
			
		||||
 | 
			
		||||
	branch, err := repo_service.GetBranch(ctx.Repo.Repository, branchName)
 | 
			
		||||
	branch, err := ctx.Repo.GitRepo.GetBranch(branchName)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if git.IsErrBranchNotExist(err) {
 | 
			
		||||
			ctx.NotFound(err)
 | 
			
		||||
@@ -176,7 +176,7 @@ func CreateBranch(ctx *context.APIContext) {
 | 
			
		||||
		opt.OldBranchName = ctx.Repo.Repository.DefaultBranch
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	err := repo_service.CreateNewBranch(ctx.User, ctx.Repo.Repository, opt.OldBranchName, opt.BranchName)
 | 
			
		||||
	err := repo_service.CreateNewBranch(ctx, ctx.User, ctx.Repo.Repository, opt.OldBranchName, opt.BranchName)
 | 
			
		||||
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if models.IsErrBranchDoesNotExist(err) {
 | 
			
		||||
@@ -198,7 +198,7 @@ func CreateBranch(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	branch, err := repo_service.GetBranch(ctx.Repo.Repository, opt.BranchName)
 | 
			
		||||
	branch, err := ctx.Repo.GitRepo.GetBranch(opt.BranchName)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "GetBranch", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -257,7 +257,7 @@ func ListBranches(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	listOptions := utils.GetListOptions(ctx)
 | 
			
		||||
	skip, _ := listOptions.GetStartEnd()
 | 
			
		||||
	branches, totalNumOfBranches, err := repo_service.GetBranches(ctx.Repo.Repository, skip, listOptions.PageSize)
 | 
			
		||||
	branches, totalNumOfBranches, err := ctx.Repo.GitRepo.GetBranches(skip, listOptions.PageSize)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "GetBranches", err)
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -62,13 +62,7 @@ func GetSingleCommit(ctx *context.APIContext) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getCommit(ctx *context.APIContext, identifier string) {
 | 
			
		||||
	gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	defer gitRepo.Close()
 | 
			
		||||
	commit, err := gitRepo.GetCommit(identifier)
 | 
			
		||||
	commit, err := ctx.Repo.GitRepo.GetCommit(identifier)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		if git.IsErrNotExist(err) {
 | 
			
		||||
			ctx.NotFound(identifier)
 | 
			
		||||
@@ -78,7 +72,7 @@ func getCommit(ctx *context.APIContext, identifier string) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	json, err := convert.ToCommit(ctx.Repo.Repository, commit, nil)
 | 
			
		||||
	json, err := convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "toCommit", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -136,13 +130,6 @@ func GetAllCommits(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	defer gitRepo.Close()
 | 
			
		||||
 | 
			
		||||
	listOptions := utils.GetListOptions(ctx)
 | 
			
		||||
	if listOptions.Page <= 0 {
 | 
			
		||||
		listOptions.Page = 1
 | 
			
		||||
@@ -158,26 +145,27 @@ func GetAllCommits(ctx *context.APIContext) {
 | 
			
		||||
	var (
 | 
			
		||||
		commitsCountTotal int64
 | 
			
		||||
		commits           []*git.Commit
 | 
			
		||||
		err               error
 | 
			
		||||
	)
 | 
			
		||||
 | 
			
		||||
	if len(path) == 0 {
 | 
			
		||||
		var baseCommit *git.Commit
 | 
			
		||||
		if len(sha) == 0 {
 | 
			
		||||
			// no sha supplied - use default branch
 | 
			
		||||
			head, err := gitRepo.GetHEADBranch()
 | 
			
		||||
			head, err := ctx.Repo.GitRepo.GetHEADBranch()
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.Error(http.StatusInternalServerError, "GetHEADBranch", err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
 | 
			
		||||
			baseCommit, err = gitRepo.GetBranchCommit(head.Name)
 | 
			
		||||
			baseCommit, err = ctx.Repo.GitRepo.GetBranchCommit(head.Name)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.Error(http.StatusInternalServerError, "GetCommit", err)
 | 
			
		||||
				return
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			// get commit specified by sha
 | 
			
		||||
			baseCommit, err = gitRepo.GetCommit(sha)
 | 
			
		||||
			baseCommit, err = ctx.Repo.GitRepo.GetCommit(sha)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.Error(http.StatusInternalServerError, "GetCommit", err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -202,7 +190,7 @@ func GetAllCommits(ctx *context.APIContext) {
 | 
			
		||||
			sha = ctx.Repo.Repository.DefaultBranch
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		commitsCountTotal, err = gitRepo.FileCommitsCount(sha, path)
 | 
			
		||||
		commitsCountTotal, err = ctx.Repo.GitRepo.FileCommitsCount(sha, path)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "FileCommitsCount", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -211,7 +199,7 @@ func GetAllCommits(ctx *context.APIContext) {
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		commits, err = gitRepo.CommitsByFileAndRange(sha, path, listOptions.Page)
 | 
			
		||||
		commits, err = ctx.Repo.GitRepo.CommitsByFileAndRange(sha, path, listOptions.Page)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "CommitsByFileAndRange", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -225,7 +213,7 @@ func GetAllCommits(ctx *context.APIContext) {
 | 
			
		||||
	apiCommits := make([]*api.Commit, len(commits))
 | 
			
		||||
	for i, commit := range commits {
 | 
			
		||||
		// Create json struct
 | 
			
		||||
		apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, commit, userCache)
 | 
			
		||||
		apiCommits[i], err = convert.ToCommit(ctx.Repo.Repository, ctx.Repo.GitRepo, commit, userCache)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "toCommit", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -282,6 +270,7 @@ func DownloadCommitDiffOrPatch(ctx *context.APIContext) {
 | 
			
		||||
	//     "$ref": "#/responses/notFound"
 | 
			
		||||
	repoPath := repo_model.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
 | 
			
		||||
	if err := git.GetRawDiff(
 | 
			
		||||
		ctx,
 | 
			
		||||
		repoPath,
 | 
			
		||||
		ctx.Params(":sha"),
 | 
			
		||||
		git.RawDiffType(ctx.Params(":diffType")),
 | 
			
		||||
 
 | 
			
		||||
@@ -122,7 +122,7 @@ func GetArchive(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	repoPath := repo_model.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
 | 
			
		||||
	if ctx.Repo.GitRepo == nil {
 | 
			
		||||
		gitRepo, err := git.OpenRepository(repoPath)
 | 
			
		||||
		gitRepo, err := git.OpenRepositoryCtx(ctx, repoPath)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -402,7 +402,7 @@ func createOrUpdateFile(ctx *context.APIContext, opts *files_service.UpdateRepoF
 | 
			
		||||
	}
 | 
			
		||||
	opts.Content = string(content)
 | 
			
		||||
 | 
			
		||||
	return files_service.CreateOrUpdateRepoFile(ctx.Repo.Repository, ctx.User, opts)
 | 
			
		||||
	return files_service.CreateOrUpdateRepoFile(ctx, ctx.Repo.Repository, ctx.User, opts)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DeleteFile Delete a file in a repository
 | 
			
		||||
@@ -489,7 +489,7 @@ func DeleteFile(ctx *context.APIContext) {
 | 
			
		||||
		opts.Message = ctx.Tr("repo.editor.delete", opts.TreePath)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if fileResponse, err := files_service.DeleteRepoFile(ctx.Repo.Repository, ctx.User, opts); err != nil {
 | 
			
		||||
	if fileResponse, err := files_service.DeleteRepoFile(ctx, ctx.Repo.Repository, ctx.User, opts); err != nil {
 | 
			
		||||
		if git.IsErrBranchNotExist(err) || models.IsErrRepoFileDoesNotExist(err) || git.IsErrNotExist(err) {
 | 
			
		||||
			ctx.Error(http.StatusNotFound, "DeleteFile", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -555,7 +555,7 @@ func GetContents(ctx *context.APIContext) {
 | 
			
		||||
	treePath := ctx.Params("*")
 | 
			
		||||
	ref := ctx.FormTrim("ref")
 | 
			
		||||
 | 
			
		||||
	if fileList, err := files_service.GetContentsOrList(ctx.Repo.Repository, treePath, ref); err != nil {
 | 
			
		||||
	if fileList, err := files_service.GetContentsOrList(ctx, ctx.Repo.Repository, treePath, ref); err != nil {
 | 
			
		||||
		if git.IsErrNotExist(err) {
 | 
			
		||||
			ctx.NotFound("GetContentsOrList", err)
 | 
			
		||||
			return
 | 
			
		||||
 
 | 
			
		||||
@@ -55,7 +55,7 @@ func GetNote(ctx *context.APIContext) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func getNote(ctx *context.APIContext, identifier string) {
 | 
			
		||||
	gitRepo, err := git.OpenRepository(ctx.Repo.Repository.RepoPath())
 | 
			
		||||
	gitRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -72,7 +72,7 @@ func getNote(ctx *context.APIContext, identifier string) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	cmt, err := convert.ToCommit(ctx.Repo.Repository, note.Commit, nil)
 | 
			
		||||
	cmt, err := convert.ToCommit(ctx.Repo.Repository, gitRepo, note.Commit, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "ToCommit", err)
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -119,7 +119,7 @@ func ListPullRequests(ctx *context.APIContext) {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		apiPrs[i] = convert.ToAPIPullRequest(prs[i], ctx.User)
 | 
			
		||||
		apiPrs[i] = convert.ToAPIPullRequest(ctx, prs[i], ctx.User)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	ctx.SetLinkHeader(int(maxResults), listOptions.PageSize)
 | 
			
		||||
@@ -175,7 +175,7 @@ func GetPullRequest(ctx *context.APIContext) {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "LoadHeadRepo", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(pr, ctx.User))
 | 
			
		||||
	ctx.JSON(http.StatusOK, convert.ToAPIPullRequest(ctx, pr, ctx.User))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// DownloadPullDiffOrPatch render a pull's raw diff or patch
 | 
			
		||||
@@ -235,7 +235,7 @@ func DownloadPullDiffOrPatch(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	binary := ctx.FormBool("binary")
 | 
			
		||||
 | 
			
		||||
	if err := pull_service.DownloadDiffOrPatch(pr, ctx, patch, binary); err != nil {
 | 
			
		||||
	if err := pull_service.DownloadDiffOrPatch(ctx, pr, ctx, patch, binary); err != nil {
 | 
			
		||||
		ctx.InternalServerError(err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
@@ -411,7 +411,7 @@ func CreatePullRequest(ctx *context.APIContext) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := pull_service.NewPullRequest(repo, prIssue, labelIDs, []string{}, pr, assigneeIDs); err != nil {
 | 
			
		||||
	if err := pull_service.NewPullRequest(ctx, repo, prIssue, labelIDs, []string{}, pr, assigneeIDs); err != nil {
 | 
			
		||||
		if models.IsErrUserDoesNotHaveAccessToRepo(err) {
 | 
			
		||||
			ctx.Error(http.StatusBadRequest, "UserDoesNotHaveAccessToRepo", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -421,7 +421,7 @@ func CreatePullRequest(ctx *context.APIContext) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	log.Trace("Pull request created: %d/%d", repo.ID, prIssue.ID)
 | 
			
		||||
	ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(pr, ctx.User))
 | 
			
		||||
	ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.User))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// EditPullRequest does what it says
 | 
			
		||||
@@ -598,7 +598,7 @@ func EditPullRequest(ctx *context.APIContext) {
 | 
			
		||||
			ctx.Error(http.StatusNotFound, "NewBaseBranchNotExist", fmt.Errorf("new base '%s' not exist", form.Base))
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		if err := pull_service.ChangeTargetBranch(pr, ctx.User, form.Base); err != nil {
 | 
			
		||||
		if err := pull_service.ChangeTargetBranch(ctx, pr, ctx.User, form.Base); err != nil {
 | 
			
		||||
			if models.IsErrPullRequestAlreadyExists(err) {
 | 
			
		||||
				ctx.Error(http.StatusConflict, "IsErrPullRequestAlreadyExists", err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -628,7 +628,7 @@ func EditPullRequest(ctx *context.APIContext) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// TODO this should be 200, not 201
 | 
			
		||||
	ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(pr, ctx.User))
 | 
			
		||||
	ctx.JSON(http.StatusCreated, convert.ToAPIPullRequest(ctx, pr, ctx.User))
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// IsPullRequestMerged checks if a PR exists given an index
 | 
			
		||||
@@ -792,7 +792,7 @@ func MergePullRequest(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := pull_service.CheckPRReadyToMerge(pr, false); err != nil {
 | 
			
		||||
	if err := pull_service.CheckPRReadyToMerge(ctx, pr, false); err != nil {
 | 
			
		||||
		if !models.IsErrNotAllowedToMerge(err) {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "CheckPRReadyToMerge", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -810,7 +810,7 @@ func MergePullRequest(ctx *context.APIContext) {
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if _, err := pull_service.IsSignedIfRequired(pr, ctx.User); err != nil {
 | 
			
		||||
	if _, err := pull_service.IsSignedIfRequired(ctx, pr, ctx.User); err != nil {
 | 
			
		||||
		if !asymkey_service.IsErrWontSign(err) {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "IsSignedIfRequired", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -838,7 +838,7 @@ func MergePullRequest(ctx *context.APIContext) {
 | 
			
		||||
		message += "\n\n" + form.MergeMessageField
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := pull_service.Merge(pr, ctx.User, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message); err != nil {
 | 
			
		||||
	if err := pull_service.Merge(ctx, pr, ctx.User, ctx.Repo.GitRepo, repo_model.MergeStyle(form.Do), form.HeadCommitID, message); err != nil {
 | 
			
		||||
		if models.IsErrInvalidMergeStyle(err) {
 | 
			
		||||
			ctx.Error(http.StatusMethodNotAllowed, "Invalid merge style", fmt.Errorf("%s is not allowed an allowed merge style for this repository", repo_model.MergeStyle(form.Do)))
 | 
			
		||||
			return
 | 
			
		||||
@@ -888,7 +888,7 @@ func MergePullRequest(ctx *context.APIContext) {
 | 
			
		||||
		if ctx.Repo != nil && ctx.Repo.Repository != nil && ctx.Repo.Repository.ID == pr.HeadRepoID && ctx.Repo.GitRepo != nil {
 | 
			
		||||
			headRepo = ctx.Repo.GitRepo
 | 
			
		||||
		} else {
 | 
			
		||||
			headRepo, err = git.OpenRepository(pr.HeadRepo.RepoPath())
 | 
			
		||||
			headRepo, err = git.OpenRepositoryCtx(ctx, pr.HeadRepo.RepoPath())
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				ctx.ServerError(fmt.Sprintf("OpenRepository[%s]", pr.HeadRepo.RepoPath()), err)
 | 
			
		||||
				return
 | 
			
		||||
@@ -982,7 +982,7 @@ func parseCompareInfo(ctx *context.APIContext, form api.CreatePullRequestOption)
 | 
			
		||||
		headRepo = ctx.Repo.Repository
 | 
			
		||||
		headGitRepo = ctx.Repo.GitRepo
 | 
			
		||||
	} else {
 | 
			
		||||
		headGitRepo, err = git.OpenRepository(repo_model.RepoPath(headUser.Name, headRepo.Name))
 | 
			
		||||
		headGitRepo, err = git.OpenRepositoryCtx(ctx, repo_model.RepoPath(headUser.Name, headRepo.Name))
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "OpenRepository", err)
 | 
			
		||||
			return nil, nil, nil, nil, "", ""
 | 
			
		||||
@@ -1135,7 +1135,7 @@ func UpdatePullRequest(ctx *context.APIContext) {
 | 
			
		||||
	// default merge commit message
 | 
			
		||||
	message := fmt.Sprintf("Merge branch '%s' into %s", pr.BaseBranch, pr.HeadBranch)
 | 
			
		||||
 | 
			
		||||
	if err = pull_service.Update(pr, ctx.User, message, rebase); err != nil {
 | 
			
		||||
	if err = pull_service.Update(ctx, pr, ctx.User, message, rebase); err != nil {
 | 
			
		||||
		if models.IsErrMergeConflicts(err) {
 | 
			
		||||
			ctx.Error(http.StatusConflict, "Update", "merge failed because of conflict")
 | 
			
		||||
			return
 | 
			
		||||
@@ -1204,12 +1204,13 @@ func GetPullRequestCommits(ctx *context.APIContext) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	var prInfo *git.CompareInfo
 | 
			
		||||
	baseGitRepo, err := git.OpenRepository(pr.BaseRepo.RepoPath())
 | 
			
		||||
	baseGitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.BaseRepo.RepoPath())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.ServerError("OpenRepository", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	defer baseGitRepo.Close()
 | 
			
		||||
	defer closer.Close()
 | 
			
		||||
 | 
			
		||||
	if pr.HasMerged {
 | 
			
		||||
		prInfo, err = baseGitRepo.GetCompareInfo(pr.BaseRepo.RepoPath(), pr.MergeBase, pr.GetGitRefName(), false, false)
 | 
			
		||||
	} else {
 | 
			
		||||
@@ -1236,7 +1237,7 @@ func GetPullRequestCommits(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	apiCommits := make([]*api.Commit, 0, end-start)
 | 
			
		||||
	for i := start; i < end; i++ {
 | 
			
		||||
		apiCommit, err := convert.ToCommit(ctx.Repo.Repository, commits[i], userCache)
 | 
			
		||||
		apiCommit, err := convert.ToCommit(ctx.Repo.Repository, baseGitRepo, commits[i], userCache)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.ServerError("toCommit", err)
 | 
			
		||||
			return
 | 
			
		||||
 
 | 
			
		||||
@@ -97,7 +97,7 @@ func ListPullReviews(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	apiReviews, err := convert.ToPullReviewList(allReviews, ctx.User)
 | 
			
		||||
	apiReviews, err := convert.ToPullReviewList(ctx, allReviews, ctx.User)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -148,7 +148,7 @@ func GetPullReview(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	apiReview, err := convert.ToPullReview(review, ctx.User)
 | 
			
		||||
	apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -198,7 +198,7 @@ func GetPullReviewComments(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	apiComments, err := convert.ToPullReviewCommentList(review, ctx.User)
 | 
			
		||||
	apiComments, err := convert.ToPullReviewCommentList(ctx, review, ctx.User)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "convertToPullReviewCommentList", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -328,12 +328,13 @@ func CreatePullReview(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	// if CommitID is empty, set it as lastCommitID
 | 
			
		||||
	if opts.CommitID == "" {
 | 
			
		||||
		gitRepo, err := git.OpenRepository(pr.Issue.Repo.RepoPath())
 | 
			
		||||
 | 
			
		||||
		gitRepo, closer, err := git.RepositoryFromContextOrOpen(ctx, pr.Issue.Repo.RepoPath())
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "git.OpenRepository", err)
 | 
			
		||||
			return
 | 
			
		||||
		}
 | 
			
		||||
		defer gitRepo.Close()
 | 
			
		||||
		defer closer.Close()
 | 
			
		||||
 | 
			
		||||
		headCommitID, err := gitRepo.GetRefCommitID(pr.GetGitRefName())
 | 
			
		||||
		if err != nil {
 | 
			
		||||
@@ -351,7 +352,7 @@ func CreatePullReview(ctx *context.APIContext) {
 | 
			
		||||
			line = c.OldLineNum * -1
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if _, err := pull_service.CreateCodeComment(
 | 
			
		||||
		if _, err := pull_service.CreateCodeComment(ctx,
 | 
			
		||||
			ctx.User,
 | 
			
		||||
			ctx.Repo.GitRepo,
 | 
			
		||||
			pr.Issue,
 | 
			
		||||
@@ -368,14 +369,14 @@ func CreatePullReview(ctx *context.APIContext) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// create review and associate all pending review comments
 | 
			
		||||
	review, _, err := pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
 | 
			
		||||
	review, _, err := pull_service.SubmitReview(ctx, ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, opts.CommitID, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// convert response
 | 
			
		||||
	apiReview, err := convert.ToPullReview(review, ctx.User)
 | 
			
		||||
	apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -456,14 +457,14 @@ func SubmitPullReview(ctx *context.APIContext) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// create review and associate all pending review comments
 | 
			
		||||
	review, _, err = pull_service.SubmitReview(ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
 | 
			
		||||
	review, _, err = pull_service.SubmitReview(ctx, ctx.User, ctx.Repo.GitRepo, pr.Issue, reviewType, opts.Body, headCommitID, nil)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "SubmitReview", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// convert response
 | 
			
		||||
	apiReview, err := convert.ToPullReview(review, ctx.User)
 | 
			
		||||
	apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -555,7 +556,7 @@ func prepareSingleReview(ctx *context.APIContext) (*models.Review, *models.PullR
 | 
			
		||||
		return nil, nil, true
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := review.LoadAttributes(); err != nil && !user_model.IsErrUserNotExist(err) {
 | 
			
		||||
	if err := review.LoadAttributes(ctx); err != nil && !user_model.IsErrUserNotExist(err) {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "ReviewLoadAttributes", err)
 | 
			
		||||
		return nil, nil, true
 | 
			
		||||
	}
 | 
			
		||||
@@ -765,7 +766,7 @@ func apiReviewRequest(ctx *context.APIContext, opts api.PullReviewRequestOptions
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if isAdd {
 | 
			
		||||
		apiReviews, err := convert.ToPullReviewList(reviews, ctx.User)
 | 
			
		||||
		apiReviews, err := convert.ToPullReviewList(ctx, reviews, ctx.User)
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "convertToPullReviewList", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -883,7 +884,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	_, err := pull_service.DismissReview(review.ID, msg, ctx.User, isDismiss)
 | 
			
		||||
	_, err := pull_service.DismissReview(ctx, review.ID, msg, ctx.User, isDismiss)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "pull_service.DismissReview", err)
 | 
			
		||||
		return
 | 
			
		||||
@@ -895,7 +896,7 @@ func dismissReview(ctx *context.APIContext, msg string, isDismiss bool) {
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	// convert response
 | 
			
		||||
	apiReview, err := convert.ToPullReview(review, ctx.User)
 | 
			
		||||
	apiReview, err := convert.ToPullReview(ctx, review, ctx.User)
 | 
			
		||||
	if err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "convertToPullReview", err)
 | 
			
		||||
		return
 | 
			
		||||
 
 | 
			
		||||
@@ -356,7 +356,7 @@ func DeleteRelease(ctx *context.APIContext) {
 | 
			
		||||
		ctx.NotFound()
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if err := releaseservice.DeleteReleaseByID(id, ctx.User, false); err != nil {
 | 
			
		||||
	if err := releaseservice.DeleteReleaseByID(ctx, id, ctx.User, false); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -110,7 +110,7 @@ func DeleteReleaseByTag(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err = releaseservice.DeleteReleaseByID(release.ID, ctx.User, false); err != nil {
 | 
			
		||||
	if err = releaseservice.DeleteReleaseByID(ctx, release.ID, ctx.User, false); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -704,7 +704,7 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
 | 
			
		||||
 | 
			
		||||
	if ctx.Repo.GitRepo == nil && !repo.IsEmpty {
 | 
			
		||||
		var err error
 | 
			
		||||
		ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath())
 | 
			
		||||
		ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			ctx.Error(http.StatusInternalServerError, "Unable to OpenRepository", err)
 | 
			
		||||
			return err
 | 
			
		||||
@@ -1023,7 +1023,7 @@ func Delete(ctx *context.APIContext) {
 | 
			
		||||
		ctx.Repo.GitRepo.Close()
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := repo_service.DeleteRepository(ctx.User, repo, true); err != nil {
 | 
			
		||||
	if err := repo_service.DeleteRepository(ctx, ctx.User, repo, true); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "DeleteRepository", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -62,7 +62,7 @@ func NewCommitStatus(ctx *context.APIContext) {
 | 
			
		||||
		Description: form.Description,
 | 
			
		||||
		Context:     form.Context,
 | 
			
		||||
	}
 | 
			
		||||
	if err := files_service.CreateCommitStatus(ctx.Repo.Repository, ctx.User, sha, status); err != nil {
 | 
			
		||||
	if err := files_service.CreateCommitStatus(ctx, ctx.Repo.Repository, ctx.User, sha, status); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "CreateCommitStatus", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 
 | 
			
		||||
@@ -191,7 +191,7 @@ func CreateTag(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err := releaseservice.CreateNewTag(ctx.User, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
 | 
			
		||||
	if err := releaseservice.CreateNewTag(ctx, ctx.User, ctx.Repo.Repository, commit.ID.String(), form.TagName, form.Message); err != nil {
 | 
			
		||||
		if models.IsErrTagAlreadyExists(err) {
 | 
			
		||||
			ctx.Error(http.StatusConflict, "tag exist", err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -255,7 +255,7 @@ func DeleteTag(ctx *context.APIContext) {
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if err = releaseservice.DeleteReleaseByID(tag.ID, ctx.User, true); err != nil {
 | 
			
		||||
	if err = releaseservice.DeleteReleaseByID(ctx, tag.ID, ctx.User, true); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "DeleteReleaseByID", err)
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -60,7 +60,7 @@ func GetTree(ctx *context.APIContext) {
 | 
			
		||||
		ctx.Error(http.StatusBadRequest, "", "sha not provided")
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
	if tree, err := files_service.GetTreeBySHA(ctx.Repo.Repository, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
 | 
			
		||||
	if tree, err := files_service.GetTreeBySHA(ctx, ctx.Repo.Repository, ctx.Repo.GitRepo, sha, ctx.FormInt("page"), ctx.FormInt("per_page"), ctx.FormBool("recursive")); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusBadRequest, "", err.Error())
 | 
			
		||||
	} else {
 | 
			
		||||
		ctx.SetTotalCountHeader(int64(tree.TotalCount))
 | 
			
		||||
 
 | 
			
		||||
@@ -71,7 +71,7 @@ func NewWikiPage(ctx *context.APIContext) {
 | 
			
		||||
	}
 | 
			
		||||
	form.ContentBase64 = string(content)
 | 
			
		||||
 | 
			
		||||
	if err := wiki_service.AddWikiPage(ctx.User, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
 | 
			
		||||
	if err := wiki_service.AddWikiPage(ctx, ctx.User, ctx.Repo.Repository, wikiName, form.ContentBase64, form.Message); err != nil {
 | 
			
		||||
		if models.IsErrWikiReservedName(err) {
 | 
			
		||||
			ctx.Error(http.StatusBadRequest, "IsErrWikiReservedName", err)
 | 
			
		||||
		} else if models.IsErrWikiAlreadyExist(err) {
 | 
			
		||||
@@ -144,7 +144,7 @@ func EditWikiPage(ctx *context.APIContext) {
 | 
			
		||||
	}
 | 
			
		||||
	form.ContentBase64 = string(content)
 | 
			
		||||
 | 
			
		||||
	if err := wiki_service.EditWikiPage(ctx.User, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
 | 
			
		||||
	if err := wiki_service.EditWikiPage(ctx, ctx.User, ctx.Repo.Repository, oldWikiName, newWikiName, form.ContentBase64, form.Message); err != nil {
 | 
			
		||||
		ctx.Error(http.StatusInternalServerError, "EditWikiPage", err)
 | 
			
		||||
		return
 | 
			
		||||
	}
 | 
			
		||||
@@ -233,7 +233,7 @@ func DeleteWikiPage(ctx *context.APIContext) {
 | 
			
		||||
 | 
			
		||||
	wikiName := wiki_service.NormalizeWikiName(ctx.Params(":pageName"))
 | 
			
		||||
 | 
			
		||||
	if err := wiki_service.DeleteWikiPage(ctx.User, ctx.Repo.Repository, wikiName); err != nil {
 | 
			
		||||
	if err := wiki_service.DeleteWikiPage(ctx, ctx.User, ctx.Repo.Repository, wikiName); err != nil {
 | 
			
		||||
		if err.Error() == "file does not exist" {
 | 
			
		||||
			ctx.NotFound(err)
 | 
			
		||||
			return
 | 
			
		||||
@@ -458,7 +458,7 @@ func findEntryForFile(commit *git.Commit, target string) (*git.TreeEntry, error)
 | 
			
		||||
// findWikiRepoCommit opens the wiki repo and returns the latest commit, writing to context on error.
 | 
			
		||||
// The caller is responsible for closing the returned repo again
 | 
			
		||||
func findWikiRepoCommit(ctx *context.APIContext) (*git.Repository, *git.Commit) {
 | 
			
		||||
	wikiRepo, err := git.OpenRepository(ctx.Repo.Repository.WikiPath())
 | 
			
		||||
	wikiRepo, err := git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.WikiPath())
 | 
			
		||||
	if err != nil {
 | 
			
		||||
 | 
			
		||||
		if git.IsErrNotExist(err) || err.Error() == "no such file or directory" {
 | 
			
		||||
 
 | 
			
		||||
@@ -36,7 +36,7 @@ func ResolveRefOrSha(ctx *context.APIContext, ref string) string {
 | 
			
		||||
func GetGitRefs(ctx *context.APIContext, filter string) ([]*git.Reference, string, error) {
 | 
			
		||||
	if ctx.Repo.GitRepo == nil {
 | 
			
		||||
		var err error
 | 
			
		||||
		ctx.Repo.GitRepo, err = git.OpenRepository(ctx.Repo.Repository.RepoPath())
 | 
			
		||||
		ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
 | 
			
		||||
		if err != nil {
 | 
			
		||||
			return nil, "OpenRepository", err
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user