diff --git a/routers/web/repo/editor.go b/routers/web/repo/editor.go
index d29bccceb7..86fbdbb005 100644
--- a/routers/web/repo/editor.go
+++ b/routers/web/repo/editor.go
@@ -95,7 +95,8 @@ type preparedEditorCommitForm[T any] struct {
form T
commonForm *forms.CommitCommonForm
CommitFormOptions *context.CommitFormOptions
- TargetBranchName string
+ OldBranchName string
+ NewBranchName string
GitCommitter *files_service.IdentityOptions
}
@@ -142,6 +143,7 @@ func prepareEditorCommitSubmittedForm[T forms.CommitCommonFormInterface](ctx *co
return nil
}
+ oldBranchName := ctx.Repo.BranchName
fromBaseBranch := ctx.FormString("from_base_branch")
if fromBaseBranch != "" {
err = editorPushBranchToForkedRepository(ctx, ctx.Doer, ctx.Repo.Repository.BaseRepo, fromBaseBranch, ctx.Repo.Repository, targetBranchName)
@@ -150,13 +152,16 @@ func prepareEditorCommitSubmittedForm[T forms.CommitCommonFormInterface](ctx *co
ctx.JSONError(ctx.Tr("repo.editor.fork_failed_to_push_branch", targetBranchName))
return nil
}
+ // since we have pushed the branch from base branch, so now we need to commit the changes directly
+ oldBranchName = targetBranchName
}
return &preparedEditorCommitForm[T]{
form: form,
commonForm: commonForm,
CommitFormOptions: commitFormOptions,
- TargetBranchName: targetBranchName,
+ OldBranchName: oldBranchName,
+ NewBranchName: targetBranchName,
GitCommitter: gitCommitter,
}
}
@@ -166,7 +171,7 @@ func redirectForCommitChoice[T any](ctx *context.Context, parsed *preparedEditor
if parsed.commonForm.CommitChoice == editorCommitChoiceNewBranch {
// Redirect to a pull request when possible
redirectToPullRequest := false
- repo, baseBranch, headBranch := ctx.Repo.Repository, ctx.Repo.BranchName, parsed.TargetBranchName
+ repo, baseBranch, headBranch := ctx.Repo.Repository, parsed.OldBranchName, parsed.NewBranchName
if ctx.Repo.Repository.IsFork && parsed.CommitFormOptions.CanCreateBasePullRequest {
redirectToPullRequest = true
baseBranch = repo.BaseRepo.DefaultBranch
@@ -183,7 +188,7 @@ func redirectForCommitChoice[T any](ctx *context.Context, parsed *preparedEditor
returnURI := ctx.FormString("return_uri")
if returnURI == "" || !httplib.IsCurrentGiteaSiteURL(ctx, returnURI) {
- returnURI = util.URLJoin(ctx.Repo.RepoLink, "src/branch", util.PathEscapeSegments(parsed.TargetBranchName), util.PathEscapeSegments(treePath))
+ returnURI = util.URLJoin(ctx.Repo.RepoLink, "src/branch", util.PathEscapeSegments(parsed.NewBranchName), util.PathEscapeSegments(treePath))
}
ctx.JSONRedirect(returnURI)
}
@@ -319,8 +324,8 @@ func EditFilePost(ctx *context.Context) {
_, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{
LastCommitID: parsed.form.LastCommit,
- OldBranch: ctx.Repo.BranchName,
- NewBranch: parsed.TargetBranchName,
+ OldBranch: parsed.OldBranchName,
+ NewBranch: parsed.NewBranchName,
Message: parsed.GetCommitMessage(defaultCommitMessage),
Files: []*files_service.ChangeRepoFile{
{
@@ -335,7 +340,7 @@ func EditFilePost(ctx *context.Context) {
Committer: parsed.GitCommitter,
})
if err != nil {
- editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
+ editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
return
}
@@ -362,8 +367,8 @@ func DeleteFilePost(ctx *context.Context) {
treePath := ctx.Repo.TreePath
_, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{
LastCommitID: parsed.form.LastCommit,
- OldBranch: ctx.Repo.BranchName,
- NewBranch: parsed.TargetBranchName,
+ OldBranch: parsed.OldBranchName,
+ NewBranch: parsed.NewBranchName,
Files: []*files_service.ChangeRepoFile{
{
Operation: "delete",
@@ -376,12 +381,12 @@ func DeleteFilePost(ctx *context.Context) {
Committer: parsed.GitCommitter,
})
if err != nil {
- editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
+ editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
return
}
ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", treePath))
- redirectTreePath := getClosestParentWithFiles(ctx.Repo.GitRepo, parsed.TargetBranchName, treePath)
+ redirectTreePath := getClosestParentWithFiles(ctx.Repo.GitRepo, parsed.NewBranchName, treePath)
redirectForCommitChoice(ctx, parsed, redirectTreePath)
}
@@ -406,8 +411,8 @@ func UploadFilePost(ctx *context.Context) {
defaultCommitMessage := ctx.Locale.TrString("repo.editor.upload_files_to_dir", util.IfZero(parsed.form.TreePath, "/"))
err := files_service.UploadRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.UploadRepoFileOptions{
LastCommitID: parsed.form.LastCommit,
- OldBranch: ctx.Repo.BranchName,
- NewBranch: parsed.TargetBranchName,
+ OldBranch: parsed.OldBranchName,
+ NewBranch: parsed.NewBranchName,
TreePath: parsed.form.TreePath,
Message: parsed.GetCommitMessage(defaultCommitMessage),
Files: parsed.form.Files,
@@ -416,7 +421,7 @@ func UploadFilePost(ctx *context.Context) {
Committer: parsed.GitCommitter,
})
if err != nil {
- editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
+ editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
return
}
redirectForCommitChoice(ctx, parsed, parsed.form.TreePath)
diff --git a/routers/web/repo/editor_apply_patch.go b/routers/web/repo/editor_apply_patch.go
index 2b62d337db..bd2811cc5f 100644
--- a/routers/web/repo/editor_apply_patch.go
+++ b/routers/web/repo/editor_apply_patch.go
@@ -33,8 +33,8 @@ func NewDiffPatchPost(ctx *context.Context) {
defaultCommitMessage := ctx.Locale.TrString("repo.editor.patch")
_, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
LastCommitID: parsed.form.LastCommit,
- OldBranch: ctx.Repo.BranchName,
- NewBranch: parsed.TargetBranchName,
+ OldBranch: parsed.OldBranchName,
+ NewBranch: parsed.NewBranchName,
Message: parsed.GetCommitMessage(defaultCommitMessage),
Content: strings.ReplaceAll(parsed.form.Content.Value(), "\r\n", "\n"),
Author: parsed.GitCommitter,
@@ -44,7 +44,7 @@ func NewDiffPatchPost(ctx *context.Context) {
err = util.ErrorWrapLocale(err, "repo.editor.fail_to_apply_patch")
}
if err != nil {
- editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
+ editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
return
}
redirectForCommitChoice(ctx, parsed, parsed.form.TreePath)
diff --git a/routers/web/repo/editor_cherry_pick.go b/routers/web/repo/editor_cherry_pick.go
index e8c8a3ea66..10c2741b1c 100644
--- a/routers/web/repo/editor_cherry_pick.go
+++ b/routers/web/repo/editor_cherry_pick.go
@@ -53,8 +53,8 @@ func CherryPickPost(ctx *context.Context) {
defaultCommitMessage := util.Iif(parsed.form.Revert, ctx.Locale.TrString("repo.commit.revert-header", fromCommitID), ctx.Locale.TrString("repo.commit.cherry-pick-header", fromCommitID))
opts := &files.ApplyDiffPatchOptions{
LastCommitID: parsed.form.LastCommit,
- OldBranch: ctx.Repo.BranchName,
- NewBranch: parsed.TargetBranchName,
+ OldBranch: parsed.OldBranchName,
+ NewBranch: parsed.NewBranchName,
Message: parsed.GetCommitMessage(defaultCommitMessage),
Author: parsed.GitCommitter,
Committer: parsed.GitCommitter,
@@ -78,7 +78,7 @@ func CherryPickPost(ctx *context.Context) {
}
}
if err != nil {
- editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
+ editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
return
}
}
diff --git a/routers/web/repo/view_file.go b/routers/web/repo/view_file.go
index ec0ad02828..09ebb75c1d 100644
--- a/routers/web/repo/view_file.go
+++ b/routers/web/repo/view_file.go
@@ -290,7 +290,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
func prepareToRenderButtons(ctx *context.Context, lfsLock *git_model.LFSLock) {
// archived or mirror repository, the buttons should not be shown
- if ctx.Repo.Repository.IsArchived || !ctx.Repo.Repository.CanEnableEditor() {
+ if !ctx.Repo.Repository.CanEnableEditor() {
return
}
diff --git a/services/context/repo.go b/services/context/repo.go
index 3cc57e962f..a06118e9bf 100644
--- a/services/context/repo.go
+++ b/services/context/repo.go
@@ -155,7 +155,7 @@ func PrepareCommitFormOptions(ctx *Context, doer *user_model.User, targetRepo *r
canCreateBasePullRequest := targetRepo.BaseRepo != nil && targetRepo.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests)
canCreatePullRequest := targetRepo.UnitEnabled(ctx, unit_model.TypePullRequests) || canCreateBasePullRequest
- cfb := &CommitFormOptions{
+ opts := &CommitFormOptions{
TargetRepo: targetRepo,
WillSubmitToFork: submitToForkedRepo,
CanCommitToBranch: canCommitToBranch,
@@ -175,11 +175,11 @@ func PrepareCommitFormOptions(ctx *Context, doer *user_model.User, targetRepo *r
editorPathParamRemaining = util.PathEscapeSegments(targetRepo.DefaultBranch) + "/" + util.PathEscapeSegments(ctx.Repo.TreePath) + "?from_base_branch=" + url.QueryEscape(branchName)
}
if editorAction == "_cherrypick" {
- cfb.TargetFormAction = targetRepo.Link() + "/" + editorAction + "/" + ctx.PathParam("sha") + "/" + editorPathParamRemaining
+ opts.TargetFormAction = targetRepo.Link() + "/" + editorAction + "/" + ctx.PathParam("sha") + "/" + editorPathParamRemaining
} else {
- cfb.TargetFormAction = targetRepo.Link() + "/" + editorAction + "/" + editorPathParamRemaining
+ opts.TargetFormAction = targetRepo.Link() + "/" + editorAction + "/" + editorPathParamRemaining
}
- return cfb, nil
+ return opts, nil
}
// CanUseTimetracker returns whether a user can use the timetracker.
diff --git a/templates/repo/view_file.tmpl b/templates/repo/view_file.tmpl
index b49818c6b7..8bf6509643 100644
--- a/templates/repo/view_file.tmpl
+++ b/templates/repo/view_file.tmpl
@@ -62,16 +62,8 @@
{{end}}
{{if .Repository.CanEnableEditor}}
- {{if .CanEditFile}}
- {{svg "octicon-pencil"}}
- {{else}}
- {{svg "octicon-pencil"}}
- {{end}}
- {{if .CanDeleteFile}}
- {{svg "octicon-trash"}}
- {{else}}
- {{svg "octicon-trash"}}
- {{end}}
+ {{svg "octicon-pencil"}}
+ {{svg "octicon-trash"}}
{{end}}
{{else if .EscapeStatus.Escaped}}