diff options
| author | Angus MacArthur <amacarthur@blackberry.com> | 2013-05-02 15:30:13 -0400 |
|---|---|---|
| committer | Angus MacArthur <amacarthur@blackberry.com> | 2013-05-02 16:41:24 -0400 |
| commit | de8df1be1a75cfde02a5a1d3f52a888b770c54e0 (patch) | |
| tree | b5cbc003a547ac5a71b803293798995273434da3 /app | |
| parent | ae33fdf297e03866ecc6c31c5470dd5ad72d1328 (diff) | |
| download | gitlab-ce-de8df1be1a75cfde02a5a1d3f52a888b770c54e0.tar.gz | |
Fix bug for repeated fork requests
When asking to fork a project and a project with the same name
already exists (likely from a previous fork), the recovery from
the fork failure would inadvertantly delete the repo of the
existing destination project.
Diffstat (limited to 'app')
| -rw-r--r-- | app/contexts/projects/fork_context.rb | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/app/contexts/projects/fork_context.rb b/app/contexts/projects/fork_context.rb index e206a1cdf87..f2a0684b01c 100644 --- a/app/contexts/projects/fork_context.rb +++ b/app/contexts/projects/fork_context.rb @@ -10,28 +10,36 @@ module Projects project = Project.new project.initialize_dup(@from_project) project.name = @from_project.name - project.path = @from_project.path + project.path = @from_project.path project.namespace = current_user.namespace + project.creator = current_user - Project.transaction do - #First save the DB entries as they can be rolled back if the repo fork fails - project.creator = current_user - project.build_forked_project_link(forked_to_project_id: project.id, forked_from_project_id: @from_project.id) - if project.save - project.users_projects.create(project_access: UsersProject::MASTER, user: current_user) + # If the project cannot save, we do not want to trigger the project destroy + # as this can have the side effect of deleting a repo attached to an existing + # project with the same name and namespace + if project.valid? + begin + Project.transaction do + #First save the DB entries as they can be rolled back if the repo fork fails + project.build_forked_project_link(forked_to_project_id: project.id, forked_from_project_id: @from_project.id) + if project.save + project.users_projects.create(project_access: UsersProject::MASTER, user: current_user) + end + #Now fork the repo + unless gitlab_shell.fork_repository(@from_project.path_with_namespace, project.namespace.path) + raise "forking failed in gitlab-shell" + end + project.ensure_satellite_exists + end + rescue => ex + project.errors.add(:base, "Fork transaction failed.") + project.destroy end - #Now fork the repo - unless gitlab_shell.fork_repository(@from_project.path_with_namespace, project.namespace.path) - raise "forking failed in gitlab-shell" - end - project.ensure_satellite_exists - + else + project.errors.add(:base, "Invalid fork destination") end project - rescue => ex - project.errors.add(:base, "Can't fork project. Please try again later") - project.destroy - end + end end end |
