Commit 233eb1c693178068cb769e1633df81e938c543ee
1 parent
7ef1c99d
Exists in
master
and in
4 other branches
Rename repo feature
Showing
5 changed files
with
48 additions
and
3 deletions
Show diff stats
app/controllers/application_controller.rb
| @@ -69,7 +69,7 @@ class ApplicationController < ActionController::Base | @@ -69,7 +69,7 @@ class ApplicationController < ActionController::Base | ||
| 69 | @project | 69 | @project |
| 70 | else | 70 | else |
| 71 | @project = nil | 71 | @project = nil |
| 72 | - render_404 | 72 | + render_404 and return |
| 73 | end | 73 | end |
| 74 | end | 74 | end |
| 75 | 75 |
app/controllers/projects_controller.rb
| @@ -33,12 +33,12 @@ class ProjectsController < ProjectResourceController | @@ -33,12 +33,12 @@ class ProjectsController < ProjectResourceController | ||
| 33 | end | 33 | end |
| 34 | 34 | ||
| 35 | def update | 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 | respond_to do |format| | 38 | respond_to do |format| |
| 39 | if status | 39 | if status |
| 40 | flash[:notice] = 'Project was successfully updated.' | 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 | format.js | 42 | format.js |
| 43 | else | 43 | else |
| 44 | format.html { render action: "edit" } | 44 | format.html { render action: "edit" } |
app/models/project.rb
| @@ -423,4 +423,28 @@ class Project < ActiveRecord::Base | @@ -423,4 +423,28 @@ class Project < ActiveRecord::Base | ||
| 423 | def forked? | 423 | def forked? |
| 424 | !(forked_project_link.nil? || forked_project_link.forked_from_project.nil?) | 424 | !(forked_project_link.nil? || forked_project_link.forked_from_project.nil?) |
| 425 | end | 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 | end | 450 | end |
app/observers/project_observer.rb
| @@ -12,6 +12,7 @@ class ProjectObserver < BaseObserver | @@ -12,6 +12,7 @@ class ProjectObserver < BaseObserver | ||
| 12 | 12 | ||
| 13 | def after_update(project) | 13 | def after_update(project) |
| 14 | project.send_move_instructions if project.namespace_id_changed? | 14 | project.send_move_instructions if project.namespace_id_changed? |
| 15 | + project.rename_repo if project.path_changed? | ||
| 15 | end | 16 | end |
| 16 | 17 | ||
| 17 | def after_destroy(project) | 18 | def after_destroy(project) |
app/views/projects/edit.html.haml
| @@ -11,6 +11,8 @@ | @@ -11,6 +11,8 @@ | ||
| 11 | %li.active | 11 | %li.active |
| 12 | = link_to 'Settings', '#tab-settings', 'data-toggle' => 'tab' | 12 | = link_to 'Settings', '#tab-settings', 'data-toggle' => 'tab' |
| 13 | %li | 13 | %li |
| 14 | + = link_to 'Rename repo', '#tab-rename', 'data-toggle' => 'tab' | ||
| 15 | + %li | ||
| 14 | = link_to 'Transfer', '#tab-transfer', 'data-toggle' => 'tab' | 16 | = link_to 'Transfer', '#tab-transfer', 'data-toggle' => 'tab' |
| 15 | %li | 17 | %li |
| 16 | = link_to 'Remove', '#tab-remove', 'data-toggle' => 'tab' | 18 | = link_to 'Remove', '#tab-remove', 'data-toggle' => 'tab' |
| @@ -137,6 +139,24 @@ | @@ -137,6 +139,24 @@ | ||
| 137 | - else | 139 | - else |
| 138 | %p.nothing_here_message Only project owner can transfer a project | 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 | .tab-pane#tab-remove | 160 | .tab-pane#tab-remove |
| 141 | - if can?(current_user, :remove_project, @project) | 161 | - if can?(current_user, :remove_project, @project) |
| 142 | .ui-box.ui-box-danger | 162 | .ui-box.ui-box-danger |