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

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
f834dca
Edit file workflow for creating a fork and proposing changes
brechtvl Apr 18, 2025
a9c552e
Fix tests and lint
brechtvl Apr 22, 2025
6d23290
Also support new/upload/patch/delete operations, refactor permissions
brechtvl Apr 22, 2025
c74b5fc
Check for protected branch also when committing to new branch
brechtvl Apr 23, 2025
64fa570
Add tests
brechtvl Apr 23, 2025
4da881b
Fix wrong redirect URL after fork, add test
brechtvl Apr 23, 2025
f29e486
Move fork to edit logic to a separate file
brechtvl Apr 23, 2025
a1e1730
Remove change from earlier version of the implementation
brechtvl Apr 23, 2025
d3f4f9d
Don't allow committing to existing branch when choosing new branch
brechtvl Apr 24, 2025
bc2d5aa
Share more checks with regular fork code, no reason not to
brechtvl Apr 24, 2025
333ff0e
Add a few more tests for failure cases
brechtvl Apr 24, 2025
b51ff01
Fix broken test due to stricter new branch check
brechtvl Apr 24, 2025
2410c43
Compare repositories by ID, add Gitea copyright to new file
brechtvl Apr 24, 2025
6ba37a0
Fix missing diff preview, revert order to what it was before, add test
brechtvl Apr 24, 2025
f2fc205
Fix translation lookup error due to missing WontSignReason
brechtvl Apr 27, 2025
170d6b6
Disable new/edit/delete button when not signed in
brechtvl Apr 29, 2025
bf23a19
Merge branch 'main' into fork-on-edit
brechtvl May 6, 2025
14549b8
Address comments from wxiaoguang
brechtvl May 6, 2025
693e600
Remove unused ids in fork template
brechtvl May 6, 2025
e78c6c4
markRepositoryAsNonEmpty
wxiaoguang May 7, 2025
e92d6a2
Use ctx.ServerError instead of custom message
brechtvl May 7, 2025
6ff820a
Fix permission check for uploading files, move GetEditableRepository …
brechtvl May 7, 2025
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 @@ -1335,9 +1335,9 @@ 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.must_be_signed_in = You must be signed in to make or propose changes.
editor.file_delete_success = File "%s" has been deleted.
editor.name_your_file = Name your file…
editor.filename_help = Add a directory by typing its name followed by a slash ('/'). Remove a directory by typing backspace at the beginning of the input field.
Expand Down Expand Up @@ -1395,6 +1395,15 @@ 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_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 @@ -458,7 +458,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 @@ -407,7 +407,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