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
Tatuya Kamada
gitlab-ce
Commits
c72e7155
Commit
c72e7155
authored
Feb 24, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Raise error when no content is provided
parent
a530e9da
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
23 additions
and
9 deletions
+23
-9
app/services/files/create_service.rb
app/services/files/create_service.rb
+4
-0
app/services/files/multi_service.rb
app/services/files/multi_service.rb
+15
-7
app/services/files/update_service.rb
app/services/files/update_service.rb
+4
-0
lib/gitlab/git/index.rb
lib/gitlab/git/index.rb
+0
-2
No files found.
app/services/files/create_service.rb
View file @
c72e7155
...
@@ -16,6 +16,10 @@ module Files
...
@@ -16,6 +16,10 @@ module Files
def
validate
def
validate
super
super
if
@file_content
.
empty?
raise_error
(
"You must provide content."
)
end
if
@file_path
=~
Gitlab
::
Regex
.
directory_traversal_regex
if
@file_path
=~
Gitlab
::
Regex
.
directory_traversal_regex
raise_error
(
raise_error
(
'Your changes could not be committed, because the file name '
+
'Your changes could not be committed, because the file name '
+
...
...
app/services/files/multi_service.rb
View file @
c72e7155
...
@@ -27,7 +27,7 @@ module Files
...
@@ -27,7 +27,7 @@ module Files
else
else
raise_error
(
"Unknown action type `
#{
action
[
:action
]
}
`."
)
raise_error
(
"Unknown action type `
#{
action
[
:action
]
}
`."
)
end
end
unless
action
[
:file_path
].
present?
unless
action
[
:file_path
].
present?
raise_error
(
"You must specify a file_path."
)
raise_error
(
"You must specify a file_path."
)
end
end
...
@@ -100,6 +100,20 @@ module Files
...
@@ -100,6 +100,20 @@ module Files
if
repository
.
blob_at_branch
(
params
[
:branch
],
action
[
:file_path
])
if
repository
.
blob_at_branch
(
params
[
:branch
],
action
[
:file_path
])
raise_error
(
"Your changes could not be committed because a file with the name `
#{
action
[
:file_path
]
}
` already exists."
)
raise_error
(
"Your changes could not be committed because a file with the name `
#{
action
[
:file_path
]
}
` already exists."
)
end
end
if
action
[
:content
].
empty?
raise_error
(
"You must provide content."
)
end
end
def
validate_update
(
action
)
if
action
[
:content
].
empty?
raise_error
(
"You must provide content."
)
end
if
file_has_changed?
raise
FileChangedError
.
new
(
"You are attempting to update a file `
#{
action
[
:file_path
]
}
` that has changed since you started editing it."
)
end
end
end
def
validate_delete
(
action
)
def
validate_delete
(
action
)
...
@@ -122,11 +136,5 @@ module Files
...
@@ -122,11 +136,5 @@ module Files
params
[
:actions
][
index
][
:content
]
=
blob
.
data
params
[
:actions
][
index
][
:content
]
=
blob
.
data
end
end
end
end
def
validate_update
(
action
)
if
file_has_changed?
raise
FileChangedError
.
new
(
"You are attempting to update a file `
#{
action
[
:file_path
]
}
` that has changed since you started editing it."
)
end
end
end
end
end
end
app/services/files/update_service.rb
View file @
c72e7155
...
@@ -18,6 +18,10 @@ module Files
...
@@ -18,6 +18,10 @@ module Files
def
validate
def
validate
super
super
if
@file_content
.
empty?
raise_error
(
"You must provide content."
)
end
if
file_has_changed?
if
file_has_changed?
raise
FileChangedError
.
new
(
"You are attempting to update a file that has changed since you started editing it."
)
raise
FileChangedError
.
new
(
"You are attempting to update a file that has changed since you started editing it."
)
end
end
...
...
lib/gitlab/git/index.rb
View file @
c72e7155
...
@@ -106,8 +106,6 @@ module Gitlab
...
@@ -106,8 +106,6 @@ module Gitlab
def
add_blob
(
options
,
mode:
nil
)
def
add_blob
(
options
,
mode:
nil
)
content
=
options
[
:content
]
content
=
options
[
:content
]
return
unless
content
content
=
Base64
.
decode64
(
content
)
if
options
[
:encoding
]
==
'base64'
content
=
Base64
.
decode64
(
content
)
if
options
[
:encoding
]
==
'base64'
detect
=
CharlockHolmes
::
EncodingDetector
.
new
.
detect
(
content
)
detect
=
CharlockHolmes
::
EncodingDetector
.
new
.
detect
(
content
)
...
...
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