Instructions to reset the GitLab fork status
Due to migration clearing the fork status of existing GitLab forks, some repositories are disconnected and cannot create merge requests to the upstream repository. The easiest way to "fix" this is to delete the old repository and clone again. However this will lose older branches, CI jobs, etc.
Uli mentioned the possibility to reset the fork relationship. The API is documented here. I tested this out and found that it requires clearing the stale fork relationship first.
To automate fixing the fork relationship:
- Go to any site on https://gitlab.com/ (for example, this issue) on your desktop/laptop.
- Open the Web Console in Developer Tools.
- Firefox: press Ctrl-Shift-K (or Command-Option-K on macOS). See instructions.
- Chrome: press Ctrl-Shift-J (or Command-Option-J on macOS). See instructions.
- Copy the code below and paste it in the console. Execute it.
- You should get a dialog with
Everything should be OK!
.
Code:
alert(await (async () => {
let project_name = 'wireshark';
let project_id = 7898047;
let token = document.querySelector('meta[name=csrf-token]').content;
if (!gon.current_username) return 'Not logged in or not on gitlab.com?';
else if (!token) return 'auth token not found';
// Remove existing (broken) fork relationship if any.
await fetch(`https://gitlab.com/api/v4/projects/${gon.current_username}%2F${project_name}/fork`, {method:'DELETE', headers:{'x-csrf-token':token}});
// Reset fork relationship
let r = await fetch(`https://gitlab.com/api/v4/projects/${gon.current_username}%2F${project_name}/fork/${project_id}`, {method:'POST', headers:{'x-csrf-token':token}});
if (r.status !== 201) return `Error ${r.status} ${await r.text()}`;
return 'Everything should be OK!';
})());
Not sure if this should be documented elsewhere, but having the code here should avoid any mangling by email clients. During development of this snippet I also managed to accidentally delete my fork, but that has been fixed in the above code.