Skip to content

Commit 14549b8

Browse files
committed
Address comments from wxiaoguang
1 parent bf23a19 commit 14549b8

File tree

3 files changed

+5
-17
lines changed

3 files changed

+5
-17
lines changed

routers/web/repo/fork_to_edit.go

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"fmt"
99
"net/http"
1010
"path"
11-
"strings"
1211

1312
git_model "code.gitea.io/gitea/models/git"
1413
access_model "code.gitea.io/gitea/models/perm/access"
@@ -167,27 +166,20 @@ func updateEditRepositoryIsEmpty(ctx *context.Context, editRepo *repo_model.Repo
167166
return
168167
}
169168

170-
editGitRepo, err := gitrepo.OpenRepository(git.DefaultContext, editRepo)
169+
editGitRepo, err := gitrepo.OpenRepository(ctx, editRepo)
171170
if err != nil {
172171
log.Error("gitrepo.OpenRepository: %v", err)
173172
return
174173
}
175-
if editGitRepo == nil {
176-
return
177-
}
174+
defer editGitRepo.Close()
178175

179176
if isEmpty, err := editGitRepo.IsEmpty(); err == nil && !isEmpty {
180177
_ = repo_model.UpdateRepositoryCols(ctx, &repo_model.Repository{ID: editRepo.ID, IsEmpty: false}, "is_empty")
181178
}
182-
editGitRepo.Close()
183179
}
184180

185181
func forkToEditFileCommon(ctx *context.Context, editOperation, treePath string, notEditableMessage any) {
186-
// Check if the filename (and additional path) is specified in the querystring
187-
// (filename is a misnomer, but kept for compatibility with GitHub)
188-
filePath, _ := path.Split(ctx.Req.URL.Query().Get("filename"))
189-
filePath = strings.Trim(filePath, "/")
190-
treeNames, treePaths := getParentTreeFields(path.Join(ctx.Repo.TreePath, filePath))
182+
treeNames, treePaths := getParentTreeFields(treePath)
191183

192184
ctx.Data["EditOperation"] = editOperation
193185
ctx.Data["TreePath"] = treePath
@@ -202,8 +194,6 @@ func ForkToEditFilePost(ctx *context.Context) {
202194

203195
editRepo, notEditableMessage := getEditRepository(ctx)
204196

205-
ctx.Data["PageHasPosted"] = true
206-
207197
// Fork repository, if it doesn't already exist
208198
if editRepo == nil && notEditableMessage == nil {
209199
forkRepo := forkRepositoryOrError(ctx, ctx.Doer, repo_service.ForkRepoOptions{

templates/repo/editor/fork.tmpl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
{{template "base/alert" .}}
66
<form class="ui edit form" method="post" action="{{.RepoLink}}/_fork_to_edit/{{.BranchName | PathEscapeSegments}}">
77
{{.CsrfTokenHtml}}
8-
<input type="hidden" name="page_has_posted" value="{{.PageHasPosted}}">
98
<div class="repo-editor-header">
109
<div class="ui breadcrumb field{{if .Err_TreePath}} error{{end}}">
1110
<a class="section" href="{{$.BranchLink}}">{{.Repository.Name}}</a>

templates/repo/view_content.tmpl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@
4141
<a href="{{.Repository.Link}}/find/{{.RefTypeNameSubURL}}" class="ui compact basic button">{{ctx.Locale.Tr "repo.find_file.go_to_file"}}</a>
4242
{{end}}
4343

44-
{{if and .RefFullName.IsBranch (not .IsViewFile) .Repository.CanEnableEditor}}
45-
<button class="ui dropdown basic compact jump button"
46-
{{if not .IsSigned}} disabled data-tooltip-content="{{ctx.Locale.Tr "repo.editor.must_be_signed_in"}}"{{end}}>
44+
{{if and .RefFullName.IsBranch (not .IsViewFile) .Repository.CanEnableEditor .IsSigned}}
45+
<button class="ui dropdown basic compact jump button">
4746
{{ctx.Locale.Tr "repo.editor.add_file"}}
4847
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
4948
<div class="menu">

0 commit comments

Comments
 (0)