Support forking all branches or just the default branch
What does this MR do and why?
This MR adds support for selecting if the user would like to fork all branches or just the default branch.
Related:
- Minimal forking: only clone default branch (#24894 - closed)
- (FE) Draft: Add possibility for minimal forks (!130616 - closed)
- (Gitaly) Add support for forking a single branch (gitaly!6325 - merged)
How to set up and validate locally
- Create a new project, initialized with a
README.md
, I called minelfs-mirror-test
under theroot
name space - http://gdk.test:3000/root/lfs-mirror-test - Visit http://gdk.test:3000/root/lfs-mirror-test/-/branches/new and create a new branch called
wip
based offmain
- Test below using the Rails console and the API
Test via Rails console
- Visit http://gdk.test:3000/twitter/lfs-mirror-test to ensure it's a 404
- Bring in the Rails console by running
gdk rails c
- Run the following
name = 'lfs-mirror-test' current_user = User.find(1) project_to_fork = current_user.projects.where(name: name).first namespace_to_fork_into = Group.find_by_name('Twitter') fork_params = { namespace: namespace_to_fork_into, path: name, name: name, branch: 'main' } ::Projects::ForkService.new(project_to_fork, current_user, fork_params).execute
- You should now be able to visit http://gdk.test:3000/twitter/lfs-mirror-test/-/branches and only see the
main
branch listed
Test via API
- Visit http://gdk.test:3000/twitter/lfs-mirror-test to ensure it's a 404
- Ensure you have a PAT setup via http://gdk.test:3000/-/profile/personal_access_tokens with the
api
scope - Run the following in a
gdk rails c
session to determine the necessary project IDSname = 'lfs-mirror-test' current_user = User.find(1) project_to_fork = current_user.projects.where(name: name).first namespace_to_fork_into = Group.find_by_name('Twitter') puts %Q{export SOURCE_PROJECT_ID="#{project_to_fork.id}"} puts %Q{export NAMESPACE_TO_FORK_INTO_ID="#{namespace_to_fork_into.id}"}
- Run the following from the command line:
export TOKEN="glpat-<YOUR-TOKEN-VALUE>" export SOURCE_PROJECT_ID="<SEE-ABOVE>" export NAMESPACE_TO_FORK_INTO_ID="<SEE-ABOVE>" curl -qsv -X POST -H "PRIVATE-TOKEN: ${TOKEN}" -H "Content-Type: application/json" "http://gdk.test:3000/api/v4/projects/${SOURCE_PROJECT_ID}/fork?name=lfs-mirror-test&path=lfs-mirror-test&namespace_id=${NAMESPACE_TO_FORK_INTO_ID}&branch=main"
- You should now be able to visit http://gdk.test:3000/twitter/lfs-mirror-test/-/branches and only see the
main
branch listed
Removing forked project
Run the following to remove the forked project so you can test again:
- Bring in the Rails console by running
gdk rails c
- Run the following
name = 'lfs-mirror-test' current_user = User.find(1) project_to_fork = current_user.projects.where(name: name).first namespace_to_fork_into = Group.find_by_name('Twitter') ::Projects::DestroyService.new(namespace_to_fork_into.projects.where(name: name).first, current_user).execute
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #24894 (closed)
Edited by Ash McKenzie