Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
heptapod
heptapod
Commits
fb6512277c0a
Commit
fb651227
authored
May 25, 2013
by
Dmitriy Zaporozhets
Browse files
Rename repo feature
parent
982c6f90655d
Changes
5
Hide whitespace changes
Inline
Side-by-side
app/controllers/application_controller.rb
View file @
fb651227
...
...
@@ -69,7 +69,7 @@
@project
else
@project
=
nil
render_404
render_404
and
return
end
end
...
...
app/controllers/projects_controller.rb
View file @
fb651227
...
...
@@ -33,8 +33,8 @@
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.'
...
...
@@ -37,8 +37,8 @@
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"
}
...
...
app/models/project.rb
View file @
fb651227
...
...
@@ -423,4 +423,28 @@
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
app/observers/project_observer.rb
View file @
fb651227
...
...
@@ -12,6 +12,7 @@
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
)
...
...
app/views/projects/edit.html.haml
View file @
fb651227
...
...
@@ -11,6 +11,8 @@
%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
=
link_to
'Remove'
,
'#tab-remove'
,
'data-toggle'
=>
'tab'
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment