Skip to content

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:

How to set up and validate locally

  1. Create a new project, initialized with a README.md, I called mine lfs-mirror-test under the root name space - http://gdk.test:3000/root/lfs-mirror-test
  2. Visit http://gdk.test:3000/root/lfs-mirror-test/-/branches/new and create a new branch called wip based off main
  3. Test below using the Rails console and the API

Test via Rails console

  1. Visit http://gdk.test:3000/twitter/lfs-mirror-test to ensure it's a 404
  2. Bring in the Rails console by running gdk rails c
  3. 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
  4. 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

  1. Visit http://gdk.test:3000/twitter/lfs-mirror-test to ensure it's a 404
  2. Ensure you have a PAT setup via http://gdk.test:3000/-/profile/personal_access_tokens with the api scope
  3. Run the following in a gdk rails c session to determine the necessary project IDS
    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')
    
    puts %Q{export SOURCE_PROJECT_ID="#{project_to_fork.id}"}
    puts %Q{export NAMESPACE_TO_FORK_INTO_ID="#{namespace_to_fork_into.id}"}
  4. 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"
  5. 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:

  1. Bring in the Rails console by running gdk rails c
  2. 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.

Related to #24894 (closed)

Edited by Ash McKenzie

Merge request reports

Loading