Commit 233eb1c693178068cb769e1633df81e938c543ee

Authored by Dmitriy Zaporozhets
1 parent 7ef1c99d

Rename repo feature

app/controllers/application_controller.rb
... ... @@ -69,7 +69,7 @@ class ApplicationController < ActionController::Base
69 69 @project
70 70 else
71 71 @project = nil
72   - render_404
  72 + render_404 and return
73 73 end
74 74 end
75 75  
... ...
app/controllers/projects_controller.rb
... ... @@ -33,12 +33,12 @@ class ProjectsController < ProjectResourceController
33 33 end
34 34  
35 35 def update
36   - status = ::Projects::UpdateContext.new(project, current_user, params).execute
  36 + status = ::Projects::UpdateContext.new(@project, current_user, params).execute
37 37  
38 38 respond_to do |format|
39 39 if status
40 40 flash[:notice] = 'Project was successfully updated.'
41   - format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' }
  41 + format.html { redirect_to edit_project_path(@project), notice: 'Project was successfully updated.' }
42 42 format.js
43 43 else
44 44 format.html { render action: "edit" }
... ...
app/models/project.rb
... ... @@ -423,4 +423,28 @@ class Project < ActiveRecord::Base
423 423 def forked?
424 424 !(forked_project_link.nil? || forked_project_link.forked_from_project.nil?)
425 425 end
  426 +
  427 + def rename_repo
  428 + old_path_with_namespace = File.join(namespace_dir, path_was)
  429 + new_path_with_namespace = File.join(namespace_dir, path)
  430 +
  431 + if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
  432 + # If repository moved successfully we need to remove old satellite
  433 + # and send update instructions to users.
  434 + # However we cannot allow rollback since we moved repository
  435 + # So we basically we mute exceptions in next actions
  436 + begin
  437 + gitlab_shell.rm_satellites(old_path_with_namespace)
  438 + send_move_instructions
  439 + rescue
  440 + # Returning false does not rolback after_* transaction but gives
  441 + # us information about failing some of tasks
  442 + false
  443 + end
  444 + else
  445 + # if we cannot move namespace directory we should rollback
  446 + # db changes in order to prevent out of sync between db and fs
  447 + raise Exception.new('repository cannot be renamed')
  448 + end
  449 + end
426 450 end
... ...
app/observers/project_observer.rb
... ... @@ -12,6 +12,7 @@ class ProjectObserver < BaseObserver
12 12  
13 13 def after_update(project)
14 14 project.send_move_instructions if project.namespace_id_changed?
  15 + project.rename_repo if project.path_changed?
15 16 end
16 17  
17 18 def after_destroy(project)
... ...
app/views/projects/edit.html.haml
... ... @@ -11,6 +11,8 @@
11 11 %li.active
12 12 = link_to 'Settings', '#tab-settings', 'data-toggle' => 'tab'
13 13 %li
  14 + = link_to 'Rename repo', '#tab-rename', 'data-toggle' => 'tab'
  15 + %li
14 16 = link_to 'Transfer', '#tab-transfer', 'data-toggle' => 'tab'
15 17 %li
16 18 = link_to 'Remove', '#tab-remove', 'data-toggle' => 'tab'
... ... @@ -137,6 +139,24 @@
137 139 - else
138 140 %p.nothing_here_message Only project owner can transfer a project
139 141  
  142 + .tab-pane#tab-rename
  143 + .ui-box.ui-box-danger
  144 + %h5.title Rename repository
  145 + .errors-holder
  146 + .form-holder
  147 + = form_for(@project) do |f|
  148 + .control-group
  149 + = f.label :path do
  150 + %span Path
  151 + .controls
  152 + .clearfix
  153 + = f.text_field :path
  154 + %ul
  155 + %li Be careful. Rename of project repo can have unintended side effects
  156 + %li You will need to update your local repositories to point to the new location.
  157 + .form-actions
  158 + = f.submit 'Rename', class: "btn btn-remove"
  159 +
140 160 .tab-pane#tab-remove
141 161 - if can?(current_user, :remove_project, @project)
142 162 .ui-box.ui-box-danger
... ...