Skip to content

Allow multiple forks of the same repo under one owner, distinguished by name #38967

Description

@AlexKypr

Gitea Version

1.27.2

What happened?

An owner (user or org) can only ever have one fork of a given source repository, regardless of what name they'd give it. This is enforced in GetUserFork (models/repo/fork.go), which queries WHERE fork_id = ? AND owner_id = ? with no name in the check, and is used by ForkRepository (services/repository/fork.go) to reject a second fork attempt with ErrForkAlreadyExist.

Note: ALLOW_FORK_INTO_SAME_OWNER doesn't affect this, but it only controls CanUserForkBetweenOwners (forking from yourself), a separate, earlier check. It doesn't relax GetUserFork at all.

Use case

I want to fork the same upstream repo repeatedly under different names to create independent variants/snapshots for different purposes (e.g. upstream/toolmyorg/tool-variant-a, myorg/tool-variant-b). Today the second attempt is always rejected, even though the destination names don't collide.

Proposed change

Scope the restriction to (fork_id, owner_id, name) instead of just (fork_id, owner_id), i.e. an owner can't fork the same source twice under the same name, but can under different names. This would mean updating GetUserFork's query and reviewing the other call sites that assume "one fork per owner" (HasForkedRepo in routers/web/repo/fork.go, routers/web/repo/branch.go, services/context/repo.go) for the same relaxation.

How are you running Gitea?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/proposalThe new feature has not been accepted yet but needs to be discussed first.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions