diff options
| author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-02 23:41:07 -0700 |
|---|---|---|
| committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2013-05-02 23:41:07 -0700 |
| commit | f40d4e6685ca749c69bfc480a747a430f6c9825f (patch) | |
| tree | 0cfdb3e6276c6b4cce664b89c4da37f55adaac55 /app/contexts | |
| parent | 36efe0f5807e92c2a0b6ec71b828387e6684a9ab (diff) | |
| parent | ec63804831d1a55171abfb7fc0894af20d4298e8 (diff) | |
| download | gitlab-ce-f40d4e6685ca749c69bfc480a747a430f6c9825f.tar.gz | |
Merge pull request #3597 from amacarthur/fork-pull-request
updated fork feature to use gitlab-shell for v5 of gitlab
Diffstat (limited to 'app/contexts')
| -rw-r--r-- | app/contexts/projects/fork_context.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/contexts/projects/fork_context.rb b/app/contexts/projects/fork_context.rb new file mode 100644 index 00000000000..f2a0684b01c --- /dev/null +++ b/app/contexts/projects/fork_context.rb @@ -0,0 +1,45 @@ +module Projects + class ForkContext < BaseContext + include Gitlab::ShellAdapter + + def initialize(project, user) + @from_project, @current_user = project, user + end + + def execute + project = Project.new + project.initialize_dup(@from_project) + project.name = @from_project.name + project.path = @from_project.path + project.namespace = current_user.namespace + project.creator = 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 + else + project.errors.add(:base, "Invalid fork destination") + end + project + + end + end +end |
