Skip to content
Snippets Groups Projects
Commit 233eb1c6 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Rename repo feature

parent 7ef1c99d
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -69,7 +69,7 @@ class ApplicationController < ActionController::Base
@project
else
@project = nil
render_404
render_404 and return
end
end
 
Loading
Loading
Loading
Loading
@@ -33,12 +33,12 @@ class ProjectsController < ProjectResourceController
end
 
def update
status = ::Projects::UpdateContext.new(project, current_user, params).execute
status = ::Projects::UpdateContext.new(@project, current_user, params).execute
 
respond_to do |format|
if status
flash[:notice] = 'Project was successfully updated.'
format.html { redirect_to edit_project_path(project), notice: 'Project was successfully updated.' }
format.html { redirect_to edit_project_path(@project), notice: 'Project was successfully updated.' }
format.js
else
format.html { render action: "edit" }
Loading
Loading
Loading
Loading
@@ -423,4 +423,28 @@ class Project < ActiveRecord::Base
def forked?
!(forked_project_link.nil? || forked_project_link.forked_from_project.nil?)
end
def rename_repo
old_path_with_namespace = File.join(namespace_dir, path_was)
new_path_with_namespace = File.join(namespace_dir, path)
if gitlab_shell.mv_repository(old_path_with_namespace, new_path_with_namespace)
# If repository moved successfully we need to remove old satellite
# and send update instructions to users.
# However we cannot allow rollback since we moved repository
# So we basically we mute exceptions in next actions
begin
gitlab_shell.rm_satellites(old_path_with_namespace)
send_move_instructions
rescue
# Returning false does not rolback after_* transaction but gives
# us information about failing some of tasks
false
end
else
# if we cannot move namespace directory we should rollback
# db changes in order to prevent out of sync between db and fs
raise Exception.new('repository cannot be renamed')
end
end
end
Loading
Loading
@@ -12,6 +12,7 @@ class ProjectObserver < BaseObserver
 
def after_update(project)
project.send_move_instructions if project.namespace_id_changed?
project.rename_repo if project.path_changed?
end
 
def after_destroy(project)
Loading
Loading
Loading
Loading
@@ -10,6 +10,8 @@
%ul.nav.nav-pills.nav-stacked
%li.active
= link_to 'Settings', '#tab-settings', 'data-toggle' => 'tab'
%li
= link_to 'Rename repo', '#tab-rename', 'data-toggle' => 'tab'
%li
= link_to 'Transfer', '#tab-transfer', 'data-toggle' => 'tab'
%li
Loading
Loading
@@ -137,6 +139,24 @@
- else
%p.nothing_here_message Only project owner can transfer a project
 
.tab-pane#tab-rename
.ui-box.ui-box-danger
%h5.title Rename repository
.errors-holder
.form-holder
= form_for(@project) do |f|
.control-group
= f.label :path do
%span Path
.controls
.clearfix
= f.text_field :path
%ul
%li Be careful. Rename of project repo can have unintended side effects
%li You will need to update your local repositories to point to the new location.
.form-actions
= f.submit 'Rename', class: "btn btn-remove"
.tab-pane#tab-remove
- if can?(current_user, :remove_project, @project)
.ui-box.ui-box-danger
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment