Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kazuhiko Shiozaki
gitlab-ce
Commits
b0f30006
Commit
b0f30006
authored
Nov 19, 2013
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/delete_file' of /home/git/repositories/gitlab/gitlabhq
parents
8841eec4
bd20ec1a
Changes
11
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
140 additions
and
12 deletions
+140
-12
app/contexts/files/delete_context.rb
app/contexts/files/delete_context.rb
+38
-0
app/controllers/projects/blob_controller.rb
app/controllers/projects/blob_controller.rb
+23
-2
app/views/projects/blob/_actions.html.haml
app/views/projects/blob/_actions.html.haml
+5
-1
app/views/projects/blob/_remove.html.haml
app/views/projects/blob/_remove.html.haml
+19
-0
app/views/projects/blob/show.html.haml
app/views/projects/blob/show.html.haml
+3
-0
config/routes.rb
config/routes.rb
+1
-1
lib/gitlab/satellite/files/delete_file_action.rb
lib/gitlab/satellite/files/delete_file_action.rb
+43
-0
lib/gitlab/satellite/files/edit_file_action.rb
lib/gitlab/satellite/files/edit_file_action.rb
+3
-3
lib/gitlab/satellite/files/new_file_action.rb
lib/gitlab/satellite/files/new_file_action.rb
+3
-3
lib/gitlab/satellite/merge_action.rb
lib/gitlab/satellite/merge_action.rb
+1
-1
lib/gitlab/satellite/satellite.rb
lib/gitlab/satellite/satellite.rb
+1
-1
No files found.
app/contexts/files/delete_context.rb
0 → 100644
View file @
b0f30006
module
Files
class
DeleteContext
<
BaseContext
def
execute
allowed
=
if
project
.
protected_branch?
(
ref
)
can?
(
current_user
,
:push_code_to_protected_branches
,
project
)
else
can?
(
current_user
,
:push_code
,
project
)
end
unless
allowed
return
error
(
"You are not allowed to push into this branch"
)
end
unless
repository
.
branch_names
.
include?
(
ref
)
return
error
(
"You can only create files if you are on top of a branch"
)
end
blob
=
repository
.
blob_at
(
ref
,
path
)
unless
blob
return
error
(
"You can only edit text files"
)
end
delete_file_action
=
Gitlab
::
Satellite
::
DeleteFileAction
.
new
(
current_user
,
project
,
ref
,
path
)
deleted_successfully
=
delete_file_action
.
commit!
(
nil
,
params
[
:commit_message
]
)
if
deleted_successfully
success
else
error
(
"Your changes could not be commited, because the file has been changed"
)
end
end
end
end
app/controllers/projects/blob_controller.rb
View file @
b0f30006
...
...
@@ -7,9 +7,30 @@ class Projects::BlobController < Projects::ApplicationController
before_filter
:authorize_code_access!
before_filter
:require_non_empty_project
before_filter
:blob
def
show
@blob
=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
end
def
destroy
result
=
Files
::
DeleteContext
.
new
(
@project
,
current_user
,
params
,
@ref
,
@path
).
execute
if
result
[
:status
]
==
:success
flash
[
:notice
]
=
"Your changes have been successfully commited"
redirect_to
project_tree_path
(
@project
,
@ref
)
else
flash
[
:alert
]
=
result
[
:error
]
render
:show
end
end
private
def
blob
@blob
||=
@repository
.
blob_at
(
@commit
.
id
,
@path
)
return
not_found!
unless
@blob
not_found!
unless
@blob
@blob
end
end
app/views/projects/blob/_actions.html.haml
View file @
b0f30006
...
...
@@ -4,7 +4,7 @@
-
if
allowed_tree_edit?
=
link_to
"edit"
,
project_edit_tree_path
(
@project
,
@id
),
class:
"btn btn-small"
-
else
%span
.btn.btn-small.disabled
E
dit
%span
.btn.btn-small.disabled
e
dit
=
link_to
"raw"
,
project_raw_path
(
@project
,
@id
),
class:
"btn btn-small"
,
target:
"_blank"
-# only show normal/blame view links for text files
-
if
@blob
.
text?
...
...
@@ -13,3 +13,7 @@
-
else
=
link_to
"blame"
,
project_blame_path
(
@project
,
@id
),
class:
"btn btn-small"
unless
@blob
.
empty?
=
link_to
"history"
,
project_commits_path
(
@project
,
@id
),
class:
"btn btn-small"
-
if
allowed_tree_edit?
=
link_to
'#modal-remove-blob'
,
class:
"remove-blob btn btn-small btn-remove"
,
"data-toggle"
=>
"modal"
do
remove
app/views/projects/blob/_remove.html.haml
0 → 100644
View file @
b0f30006
%div
#modal-remove-blob
.modal.hide
.modal-header
%a
.close
{
href:
"#"
,
"data-dismiss"
=>
"modal"
}
×
%h3
.page-title
Remove
#{
@blob
.
name
}
%p
.light
From branch
%strong
=
@ref
.modal-body
=
form_tag
project_blob_path
(
@project
,
@id
),
method: :delete
do
.control-group.commit_message-group
=
label_tag
'commit_message'
,
class:
"control-label"
do
Commit message
.controls
=
text_area_tag
'commit_message'
,
params
[
:commit_message
],
placeholder:
"Removed this file because..."
,
required:
true
,
rows:
3
.control-group
.controls
=
submit_tag
'Remove file'
,
class:
'btn btn-remove'
=
link_to
"Cancel"
,
'#'
,
class:
"btn btn-cancel"
,
"data-dismiss"
=>
"modal"
app/views/projects/blob/show.html.haml
View file @
b0f30006
...
...
@@ -2,3 +2,6 @@
=
render
'shared/ref_switcher'
,
destination:
'blob'
,
path:
@path
%div
#tree-holder
.tree-holder
=
render
'blob'
,
blob:
@blob
-
if
allowed_tree_edit?
=
render
'projects/blob/remove'
config/routes.rb
View file @
b0f30006
...
...
@@ -173,7 +173,7 @@ Gitlab::Application.routes.draw do
end
scope
module: :projects
do
resources
:blob
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
resources
:blob
,
only:
[
:show
,
:destroy
],
constraints:
{
id:
/.+/
}
resources
:raw
,
only:
[
:show
],
constraints:
{
id:
/.+/
}
resources
:tree
,
only:
[
:show
],
constraints:
{
id:
/.+/
,
format:
/(html|js)/
}
resources
:edit_tree
,
only:
[
:show
,
:update
],
constraints:
{
id:
/.+/
},
path:
'edit'
...
...
lib/gitlab/satellite/files/delete_file_action.rb
0 → 100644
View file @
b0f30006
require_relative
'file_action'
module
Gitlab
module
Satellite
class
DeleteFileAction
<
FileAction
# Deletes file and creates a new commit for it
#
# Returns false if committing the change fails
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
def
commit!
(
content
,
commit_message
)
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
# create target branch in satellite at the corresponding commit from bare repo
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
# update the file in the satellite's working dir
file_path_in_satellite
=
File
.
join
(
repo
.
working_dir
,
file_path
)
File
.
delete
(
file_path_in_satellite
)
# add removed file
repo
.
remove
(
file_path_in_satellite
)
# commit the changes
# will raise CommandFailed when commit fails
repo
.
git
.
commit
(
raise:
true
,
timeout:
true
,
a:
true
,
m:
commit_message
)
# push commit back to bare repo
# will raise CommandFailed when push fails
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
ref
)
# everything worked
true
end
rescue
Grit
::
Git
::
CommandFailed
=>
ex
Gitlab
::
GitLogger
.
error
(
ex
.
message
)
false
end
end
end
end
lib/gitlab/satellite/files/edit_file_action.rb
View file @
b0f30006
...
...
@@ -8,13 +8,13 @@ module Gitlab
#
# Returns false if the ref has been updated while editing the file
# Returns false if committing the change fails
# Returns false if pushing from the satellite to
Gitolite
failed or was rejected
# Returns false if pushing from the satellite to
bare repo
failed or was rejected
# Returns true otherwise
def
commit!
(
content
,
commit_message
)
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
# create target branch in satellite at the corresponding commit from
Gitolite
# create target branch in satellite at the corresponding commit from
bare repo
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
# update the file in the satellite's working dir
...
...
@@ -26,7 +26,7 @@ module Gitlab
repo
.
git
.
commit
(
raise:
true
,
timeout:
true
,
a:
true
,
m:
commit_message
)
# push commit back to
Gitolite
# push commit back to
bare repo
# will raise CommandFailed when push fails
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
ref
)
...
...
lib/gitlab/satellite/files/new_file_action.rb
View file @
b0f30006
...
...
@@ -7,13 +7,13 @@ module Gitlab
#
# Returns false if the ref has been updated while editing the file
# Returns false if committing the change fails
# Returns false if pushing from the satellite to
Gitolite
failed or was rejected
# Returns false if pushing from the satellite to
bare repo
failed or was rejected
# Returns true otherwise
def
commit!
(
content
,
commit_message
)
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
# create target branch in satellite at the corresponding commit from
Gitolite
# create target branch in satellite at the corresponding commit from
bare repo
repo
.
git
.
checkout
({
raise:
true
,
timeout:
true
,
b:
true
},
ref
,
"origin/
#{
ref
}
"
)
# update the file in the satellite's working dir
...
...
@@ -28,7 +28,7 @@ module Gitlab
repo
.
git
.
commit
(
raise:
true
,
timeout:
true
,
a:
true
,
m:
commit_message
)
# push commit back to
Gitolite
# push commit back to
bare repo
# will raise CommandFailed when push fails
repo
.
git
.
push
({
raise:
true
,
timeout:
true
},
:origin
,
ref
)
...
...
lib/gitlab/satellite/merge_action.rb
View file @
b0f30006
...
...
@@ -28,7 +28,7 @@ module Gitlab
in_locked_and_timed_satellite
do
|
merge_repo
|
prepare_satellite!
(
merge_repo
)
if
merge_in_satellite!
(
merge_repo
)
# push merge back to
Gitolite
# push merge back to
bare repo
# will raise CommandFailed when push fails
merge_repo
.
git
.
push
(
default_options
,
:origin
,
merge_request
.
target_branch
)
# remove source branch
...
...
lib/gitlab/satellite/satellite.rb
View file @
b0f30006
...
...
@@ -123,7 +123,7 @@ module Gitlab
remotes
.
each
{
|
name
|
repo
.
git
.
remote
(
default_options
,
'rm'
,
name
)}
end
# Updates the satellite from
Gitolite
# Updates the satellite from
bare repo
#
# Note: this will only update remote branches (i.e. origin/*)
def
update_from_source!
...
...
Write
Preview
Markdown
is supported
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