Edit file conflicts - create new branch or update fork automatically
<!--IssueSummary start--> <details> <summary> Everyone can contribute. [Help move this issue forward](https://handbook.gitlab.com/handbook/marketing/developer-relations/contributor-success/community-contributors-workflows/#contributor-links) while earning points, leveling up and collecting rewards. </summary> - [Close this issue](https://contributors.gitlab.com/manage-issue?action=close&projectId=278964&issueIid=424579) </details> <!--IssueSummary end--> ### Summary When committing file from single file editor, if the fork is many commits behind, the edit will fail with the error message. "Error: Can't edit this file. The fork and upstream project have diverged. Edit the file on the fork , and create a merge request." ![image](/uploads/f46b51c7ba52d5faf760ff6b26bab974/image.png) The problem here is that fork is not diverged - it is just behind, and it could be updated without leaving the interface. ![image](/uploads/df81e51846015f4c838be5d3929ff842/image.png) ### Steps to reproduce 0. Make sure you have no write access to `gitlab-org/gitlab` repo 1. Update `master` in Gitlab fork to commit 5db8f422102c3748ffab76de285317660c4cfba6 2. Edit `getting_started.md` file (https://gitlab.com/gitlab-org/gitlab/-/edit/master/doc/api/graphql/getting_started.md) 3. Replace "Command line" section with the following content <details><summary>Click to expand</summary> ````md ### Command line You can run GraphQL queries from the command line on your local computer using `curl` or HTTPie. It is done by a `POST` request to `/api/graphql` with the query as the payload. You can authorize your request by generating a [personal access token](../../user/profile/personal_access_tokens.md) to use as a bearer token. This token requires at least the `read_api` scope. Example: ```shell GRAPHQL_TOKEN=<your-token> curl "https://gitlab.com/api/graphql" --header "Authorization: Bearer $GRAPHQL_TOKEN" \ --header "Content-Type: application/json" --request POST \ --data "{\"query\": \"query {currentUser {name}}\"}" ``` To nest strings in the query string, wrap the data in single quotes or escape the strings with `\\`: ```shell curl "https://gitlab.com/api/graphql" --header "Authorization: Bearer $GRAPHQL_TOKEN" \ --header "Content-Type: application/json" --request POST \ --data '{"query": "query {project(fullPath: \"<group>/<subgroup>/<project>\") {jobs {nodes {id duration}}}}"}' # or "{\"query\": \"query {project(fullPath: \\\"<group>/<subgroup>/<project>\\\") {jobs {nodes {id duration}}}}\"}" ``` Example using HTTPie: ```shell GRAPHQL_TOKEN= http POST "https://gitlab.com/api/graphql" "Authorization:Bearer $GRAPHQL_TOKEN" query="{currentUser {name}}" ``` Note that these tools do not natively support GraphQL pagination and you need to implement it yourself. ```` </details> 4. Click "Commit the changes" to see the error ### What is the current *bug* behavior? Edit fails if the fork default branch is behind. The message next to commit button says "GitLab will create a branch in your fork and start a merge request.", but no branch is created. ### What is the expected *correct* behavior? 1. Detect if the fork default branch can be updated to the latest (edited) revisions and propose that 2. In case fork is ahead, create a new branch with all preceding commits from upstream 3. Autogenerate branch name with AI (or fallback logic) ### Relevant logs and/or screenshots <!-- Paste any relevant logs - please use code blocks (```) to format console output, logs, and code as it's tough to read otherwise. --> ### Output of checks This bug happens on GitLab.com ### Possible fixes * https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/views/projects/blob/edit.html.haml * https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/controllers/concerns/creates_commit.rb
issue