Skip to content

Edit file workflow for creating a fork and proposing changes #34240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion models/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ func (repo *Repository) AllowsPulls(ctx context.Context) bool {

// CanEnableEditor returns true if repository meets the requirements of web editor.
func (repo *Repository) CanEnableEditor() bool {
return !repo.IsMirror
return !repo.IsMirror && !repo.IsArchived
}

// DescriptionHTML does special handles to description and return HTML string.
Expand Down
11 changes: 10 additions & 1 deletion options/locale/locale_en-US.ini
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,6 @@ editor.cannot_edit_non_text_files = Binary files cannot be edited in the web int
editor.edit_this_file = Edit File
editor.this_file_locked = File is locked
editor.must_be_on_a_branch = You must be on a branch to make or propose changes to this file.
editor.fork_before_edit = You must fork this repository to make or propose changes to this file.
editor.delete_this_file = Delete File
editor.must_have_write_access = You must have write access to make or propose changes to this file.
editor.file_delete_success = File "%s" has been deleted.
Expand Down Expand Up @@ -1394,6 +1393,16 @@ editor.user_no_push_to_branch = User cannot push to branch
editor.require_signed_commit = Branch requires a signed commit
editor.cherry_pick = Cherry-pick %s onto:
editor.revert = Revert %s onto:
editor.fork_create = Fork Repository to Propose Changes
editor.fork_create_description = You can not edit this repository directly. Instead you can create a fork, make edits and create a pull request.
editor.fork_edit_description = You can not edit this repository directly. The changes will be written to your fork <b>%s</b>, so you can create a pull request.
editor.fork_failed_to_push_branch = Failed to push branch %s to your repoitory.
editor.cannot_find_editable_repo = Can not find repository to apply the edit to. Was it deleted while editing?
editor.fork_not_editable = Fork Repository Not Editable
editor.fork_internal_error = Internal error loading repository information about <b>%s</b>.
editor.fork_is_archived = Your repository <b>%s</b> is archived. Unarchive it in repository settings to make changes.
editor.fork_code_disabled = Code is disabled in your repository <b>%s</b>. Enable code in repository settings to make changes.
editor.fork_no_permission = You do not have permission to write to repository <b>%s</b>.

commits.desc = Browse source code change history.
commits.commits = Commits
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func reqRepoWriter(unitTypes ...unit.Type) func(ctx *context.APIContext) {
// reqRepoBranchWriter user should have a permission to write to a branch, or be a site admin
func reqRepoBranchWriter(ctx *context.APIContext) {
options, ok := web.GetForm(ctx).(api.FileOptionInterface)
if !ok || (!ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, options.Branch()) && !ctx.IsUserSiteAdmin()) {
if !ok || (!context.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.Repository, options.Branch()) && !ctx.IsUserSiteAdmin()) {
ctx.APIError(http.StatusForbidden, "user should have a permission to write to this branch")
return
}
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/repo/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func GetEditorconfig(ctx *context.APIContext) {

// canWriteFiles returns true if repository is editable and user has proper access level.
func canWriteFiles(ctx *context.APIContext, branch string) bool {
return ctx.Repo.CanWriteToBranch(ctx, ctx.Doer, branch) &&
return context.CanWriteToBranch(ctx, ctx.Doer, ctx.Repo.Repository, branch) &&
!ctx.Repo.Repository.IsMirror &&
!ctx.Repo.Repository.IsArchived
}
Expand Down
6 changes: 3 additions & 3 deletions routers/web/repo/cherry_pick.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ func CherryPick(ctx *context.Context) {
ctx.Data["commit_message"] = splits[1]
}

canCommit := renderCommitRights(ctx)
canCommit := renderCommitRights(ctx, ctx.Repo.Repository)
ctx.Data["TreePath"] = ""

if canCommit {
ctx.Data["commit_choice"] = frmCommitChoiceDirect
} else {
ctx.Data["commit_choice"] = frmCommitChoiceNewBranch
}
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx)
ctx.Data["new_branch_name"] = GetUniquePatchBranchName(ctx, ctx.Repo.Repository)
ctx.Data["last_commit"] = ctx.Repo.CommitID
ctx.Data["LineWrapExtensions"] = strings.Join(setting.Repository.Editor.LineWrapExtensions, ",")
ctx.Data["BranchLink"] = ctx.Repo.RepoLink + "/src/" + ctx.Repo.RefTypeNameSubURL()
Expand All @@ -75,7 +75,7 @@ func CherryPickPost(ctx *context.Context) {
ctx.Data["CherryPickType"] = "cherry-pick"
}

canCommit := renderCommitRights(ctx)
canCommit := renderCommitRights(ctx, ctx.Repo.Repository)
branchName := ctx.Repo.BranchName
if form.CommitChoice == frmCommitChoiceNewBranch {
branchName = form.NewBranchName
Expand Down
Loading