Edit file conflicts - create new branch or update fork automatically
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."
The problem here is that fork is not diverged - it is just behind, and it could be updated without leaving the interface.
Steps to reproduce
- Make sure you have no write access to
gitlab-org/gitlab
repo - Update
master
in Gitlab fork to commit 5db8f422 - Edit
getting_started.md
file (https://gitlab.com/gitlab-org/gitlab/-/edit/master/doc/api/graphql/getting_started.md) - Replace "Command line" section with the following content
Click to expand
### 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.
- 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?
- Detect if the fork default branch can be updated to the latest (edited) revisions and propose that
- In case fork is ahead, create a new branch with all preceding commits from upstream
- Autogenerate branch name with AI (or fallback logic)
Relevant logs and/or screenshots
Output of checks
This bug happens on GitLab.com