mirror of https://github.com/go-gitea/gitea.git
fix parsed branch and ui
This commit is contained in:
parent
fc915fe5cc
commit
dad9e4a00a
|
|
@ -95,7 +95,8 @@ type preparedEditorCommitForm[T any] struct {
|
||||||
form T
|
form T
|
||||||
commonForm *forms.CommitCommonForm
|
commonForm *forms.CommitCommonForm
|
||||||
CommitFormOptions *context.CommitFormOptions
|
CommitFormOptions *context.CommitFormOptions
|
||||||
TargetBranchName string
|
OldBranchName string
|
||||||
|
NewBranchName string
|
||||||
GitCommitter *files_service.IdentityOptions
|
GitCommitter *files_service.IdentityOptions
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -142,6 +143,7 @@ func prepareEditorCommitSubmittedForm[T forms.CommitCommonFormInterface](ctx *co
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oldBranchName := ctx.Repo.BranchName
|
||||||
fromBaseBranch := ctx.FormString("from_base_branch")
|
fromBaseBranch := ctx.FormString("from_base_branch")
|
||||||
if fromBaseBranch != "" {
|
if fromBaseBranch != "" {
|
||||||
err = editorPushBranchToForkedRepository(ctx, ctx.Doer, ctx.Repo.Repository.BaseRepo, fromBaseBranch, ctx.Repo.Repository, targetBranchName)
|
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))
|
ctx.JSONError(ctx.Tr("repo.editor.fork_failed_to_push_branch", targetBranchName))
|
||||||
return nil
|
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]{
|
return &preparedEditorCommitForm[T]{
|
||||||
form: form,
|
form: form,
|
||||||
commonForm: commonForm,
|
commonForm: commonForm,
|
||||||
CommitFormOptions: commitFormOptions,
|
CommitFormOptions: commitFormOptions,
|
||||||
TargetBranchName: targetBranchName,
|
OldBranchName: oldBranchName,
|
||||||
|
NewBranchName: targetBranchName,
|
||||||
GitCommitter: gitCommitter,
|
GitCommitter: gitCommitter,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -166,7 +171,7 @@ func redirectForCommitChoice[T any](ctx *context.Context, parsed *preparedEditor
|
||||||
if parsed.commonForm.CommitChoice == editorCommitChoiceNewBranch {
|
if parsed.commonForm.CommitChoice == editorCommitChoiceNewBranch {
|
||||||
// Redirect to a pull request when possible
|
// Redirect to a pull request when possible
|
||||||
redirectToPullRequest := false
|
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 {
|
if ctx.Repo.Repository.IsFork && parsed.CommitFormOptions.CanCreateBasePullRequest {
|
||||||
redirectToPullRequest = true
|
redirectToPullRequest = true
|
||||||
baseBranch = repo.BaseRepo.DefaultBranch
|
baseBranch = repo.BaseRepo.DefaultBranch
|
||||||
|
|
@ -183,7 +188,7 @@ func redirectForCommitChoice[T any](ctx *context.Context, parsed *preparedEditor
|
||||||
|
|
||||||
returnURI := ctx.FormString("return_uri")
|
returnURI := ctx.FormString("return_uri")
|
||||||
if returnURI == "" || !httplib.IsCurrentGiteaSiteURL(ctx, returnURI) {
|
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)
|
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{
|
_, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{
|
||||||
LastCommitID: parsed.form.LastCommit,
|
LastCommitID: parsed.form.LastCommit,
|
||||||
OldBranch: ctx.Repo.BranchName,
|
OldBranch: parsed.OldBranchName,
|
||||||
NewBranch: parsed.TargetBranchName,
|
NewBranch: parsed.NewBranchName,
|
||||||
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
||||||
Files: []*files_service.ChangeRepoFile{
|
Files: []*files_service.ChangeRepoFile{
|
||||||
{
|
{
|
||||||
|
|
@ -335,7 +340,7 @@ func EditFilePost(ctx *context.Context) {
|
||||||
Committer: parsed.GitCommitter,
|
Committer: parsed.GitCommitter,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
|
editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -362,8 +367,8 @@ func DeleteFilePost(ctx *context.Context) {
|
||||||
treePath := ctx.Repo.TreePath
|
treePath := ctx.Repo.TreePath
|
||||||
_, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{
|
_, err := files_service.ChangeRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.ChangeRepoFilesOptions{
|
||||||
LastCommitID: parsed.form.LastCommit,
|
LastCommitID: parsed.form.LastCommit,
|
||||||
OldBranch: ctx.Repo.BranchName,
|
OldBranch: parsed.OldBranchName,
|
||||||
NewBranch: parsed.TargetBranchName,
|
NewBranch: parsed.NewBranchName,
|
||||||
Files: []*files_service.ChangeRepoFile{
|
Files: []*files_service.ChangeRepoFile{
|
||||||
{
|
{
|
||||||
Operation: "delete",
|
Operation: "delete",
|
||||||
|
|
@ -376,12 +381,12 @@ func DeleteFilePost(ctx *context.Context) {
|
||||||
Committer: parsed.GitCommitter,
|
Committer: parsed.GitCommitter,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
|
editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Flash.Success(ctx.Tr("repo.editor.file_delete_success", treePath))
|
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)
|
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, "/"))
|
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{
|
err := files_service.UploadRepoFiles(ctx, ctx.Repo.Repository, ctx.Doer, &files_service.UploadRepoFileOptions{
|
||||||
LastCommitID: parsed.form.LastCommit,
|
LastCommitID: parsed.form.LastCommit,
|
||||||
OldBranch: ctx.Repo.BranchName,
|
OldBranch: parsed.OldBranchName,
|
||||||
NewBranch: parsed.TargetBranchName,
|
NewBranch: parsed.NewBranchName,
|
||||||
TreePath: parsed.form.TreePath,
|
TreePath: parsed.form.TreePath,
|
||||||
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
||||||
Files: parsed.form.Files,
|
Files: parsed.form.Files,
|
||||||
|
|
@ -416,7 +421,7 @@ func UploadFilePost(ctx *context.Context) {
|
||||||
Committer: parsed.GitCommitter,
|
Committer: parsed.GitCommitter,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
|
editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
redirectForCommitChoice(ctx, parsed, parsed.form.TreePath)
|
redirectForCommitChoice(ctx, parsed, parsed.form.TreePath)
|
||||||
|
|
|
||||||
|
|
@ -33,8 +33,8 @@ func NewDiffPatchPost(ctx *context.Context) {
|
||||||
defaultCommitMessage := ctx.Locale.TrString("repo.editor.patch")
|
defaultCommitMessage := ctx.Locale.TrString("repo.editor.patch")
|
||||||
_, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
|
_, err := files.ApplyDiffPatch(ctx, ctx.Repo.Repository, ctx.Doer, &files.ApplyDiffPatchOptions{
|
||||||
LastCommitID: parsed.form.LastCommit,
|
LastCommitID: parsed.form.LastCommit,
|
||||||
OldBranch: ctx.Repo.BranchName,
|
OldBranch: parsed.OldBranchName,
|
||||||
NewBranch: parsed.TargetBranchName,
|
NewBranch: parsed.NewBranchName,
|
||||||
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
||||||
Content: strings.ReplaceAll(parsed.form.Content.Value(), "\r\n", "\n"),
|
Content: strings.ReplaceAll(parsed.form.Content.Value(), "\r\n", "\n"),
|
||||||
Author: parsed.GitCommitter,
|
Author: parsed.GitCommitter,
|
||||||
|
|
@ -44,7 +44,7 @@ func NewDiffPatchPost(ctx *context.Context) {
|
||||||
err = util.ErrorWrapLocale(err, "repo.editor.fail_to_apply_patch")
|
err = util.ErrorWrapLocale(err, "repo.editor.fail_to_apply_patch")
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
|
editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
redirectForCommitChoice(ctx, parsed, parsed.form.TreePath)
|
redirectForCommitChoice(ctx, parsed, parsed.form.TreePath)
|
||||||
|
|
|
||||||
|
|
@ -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))
|
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{
|
opts := &files.ApplyDiffPatchOptions{
|
||||||
LastCommitID: parsed.form.LastCommit,
|
LastCommitID: parsed.form.LastCommit,
|
||||||
OldBranch: ctx.Repo.BranchName,
|
OldBranch: parsed.OldBranchName,
|
||||||
NewBranch: parsed.TargetBranchName,
|
NewBranch: parsed.NewBranchName,
|
||||||
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
Message: parsed.GetCommitMessage(defaultCommitMessage),
|
||||||
Author: parsed.GitCommitter,
|
Author: parsed.GitCommitter,
|
||||||
Committer: parsed.GitCommitter,
|
Committer: parsed.GitCommitter,
|
||||||
|
|
@ -78,7 +78,7 @@ func CherryPickPost(ctx *context.Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
editorHandleFileOperationError(ctx, parsed.TargetBranchName, err)
|
editorHandleFileOperationError(ctx, parsed.NewBranchName, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -290,7 +290,7 @@ func prepareToRenderFile(ctx *context.Context, entry *git.TreeEntry) {
|
||||||
|
|
||||||
func prepareToRenderButtons(ctx *context.Context, lfsLock *git_model.LFSLock) {
|
func prepareToRenderButtons(ctx *context.Context, lfsLock *git_model.LFSLock) {
|
||||||
// archived or mirror repository, the buttons should not be shown
|
// 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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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)
|
canCreateBasePullRequest := targetRepo.BaseRepo != nil && targetRepo.BaseRepo.UnitEnabled(ctx, unit_model.TypePullRequests)
|
||||||
canCreatePullRequest := targetRepo.UnitEnabled(ctx, unit_model.TypePullRequests) || canCreateBasePullRequest
|
canCreatePullRequest := targetRepo.UnitEnabled(ctx, unit_model.TypePullRequests) || canCreateBasePullRequest
|
||||||
|
|
||||||
cfb := &CommitFormOptions{
|
opts := &CommitFormOptions{
|
||||||
TargetRepo: targetRepo,
|
TargetRepo: targetRepo,
|
||||||
WillSubmitToFork: submitToForkedRepo,
|
WillSubmitToFork: submitToForkedRepo,
|
||||||
CanCommitToBranch: canCommitToBranch,
|
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)
|
editorPathParamRemaining = util.PathEscapeSegments(targetRepo.DefaultBranch) + "/" + util.PathEscapeSegments(ctx.Repo.TreePath) + "?from_base_branch=" + url.QueryEscape(branchName)
|
||||||
}
|
}
|
||||||
if editorAction == "_cherrypick" {
|
if editorAction == "_cherrypick" {
|
||||||
cfb.TargetFormAction = targetRepo.Link() + "/" + editorAction + "/" + ctx.PathParam("sha") + "/" + editorPathParamRemaining
|
opts.TargetFormAction = targetRepo.Link() + "/" + editorAction + "/" + ctx.PathParam("sha") + "/" + editorPathParamRemaining
|
||||||
} else {
|
} 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.
|
// CanUseTimetracker returns whether a user can use the timetracker.
|
||||||
|
|
|
||||||
|
|
@ -62,16 +62,8 @@
|
||||||
</a>
|
</a>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{if .Repository.CanEnableEditor}}
|
{{if .Repository.CanEnableEditor}}
|
||||||
{{if .CanEditFile}}
|
<a class="btn-octicon" data-tooltip-content="{{.EditFileTooltip}}" href="{{.RepoLink}}/_edit/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .TreePath}}">{{svg "octicon-pencil"}}</a>
|
||||||
<a class="btn-octicon" data-tooltip-content="{{.EditFileTooltip}}" href="{{.RepoLink}}/_edit/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .TreePath}}">{{svg "octicon-pencil"}}</a>
|
<a class="btn-octicon btn-octicon-danger" data-tooltip-content="{{.DeleteFileTooltip}}" href="{{.RepoLink}}/_delete/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .TreePath}}">{{svg "octicon-trash"}}</a>
|
||||||
{{else}}
|
|
||||||
<span class="btn-octicon disabled" data-tooltip-content="{{.EditFileTooltip}}">{{svg "octicon-pencil"}}</span>
|
|
||||||
{{end}}
|
|
||||||
{{if .CanDeleteFile}}
|
|
||||||
<a class="btn-octicon btn-octicon-danger" data-tooltip-content="{{.DeleteFileTooltip}}" href="{{.RepoLink}}/_delete/{{PathEscapeSegments .BranchName}}/{{PathEscapeSegments .TreePath}}">{{svg "octicon-trash"}}</a>
|
|
||||||
{{else}}
|
|
||||||
<span class="btn-octicon disabled" data-tooltip-content="{{.DeleteFileTooltip}}">{{svg "octicon-trash"}}</span>
|
|
||||||
{{end}}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else if .EscapeStatus.Escaped}}
|
{{else if .EscapeStatus.Escaped}}
|
||||||
<button class="ui mini basic button unescape-button tw-mr-1 tw-hidden">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
|
<button class="ui mini basic button unescape-button tw-mr-1 tw-hidden">{{ctx.Locale.Tr "repo.unescape_control_characters"}}</button>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue