Stop a project being returned as a fork of itself

What does this MR do and why?

Restores forking for users whose only forkable namespace is their personal namespace. The Fork button on a project page now offers a new fork instead of linking back to the project the user is already on.

Problem

Currently on master, such a user cannot fork a project from its page once they have deleted their own fork of it, because the Fork button links back to that same page while the forks counter shows 0. A fork network keeps its root project as a member, and find_forks_in matches any network project in the namespace without excluding the one being asked about, so Namespace#find_fork_of can answer with that project itself. The same wrong answer sends "Go to your fork" to the source project while the fork still exists.

Review notes

  • Why fix find_fork_of and not find_forks_in? find_forks_in answers which of the given projects are in the network, and the root is one of them. find_fork_of answers which project in this namespace is a fork of another, where the project is never a valid answer.
  • What do the query plans say? Only the subquery picking the candidate projects changes, by one != predicate. Locally it lands as a filter on the existing index-only scan over index_projects_on_namespace_id_and_id, with the same plan shape and the same cost estimate, so no new index. I have no Database Lab access as an external contributor, so please confirm that against production-sized data.
  • What is left alone? A fork marked for deletion still counts, so the button points at the renamed ...-deletion_scheduled-<id> project. Same cause, but the user can still restore that project, which makes it a product question rather than a defect. Tracked at #369498 (closed).

🛠️ with ❤️ at Siemens

References

Screenshots or screen recordings

Before After

How to set up and validate locally

  1. Sign in as a user who belongs to no group that allows project creation.
  2. Create a public project in their personal namespace, then fork it into that same namespace.
  3. Delete the fork.
  4. Open the source project page. The Fork button links to /-/forks/new instead of back to the project.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Gerardo Navarro

Merge request reports

Loading
Loading