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
Léo-Paul Géneau
gitlab-ce
Commits
a530e9da
Commit
a530e9da
authored
Feb 24, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Address review
parent
9e39b317
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
41 additions
and
25 deletions
+41
-25
app/models/repository.rb
app/models/repository.rb
+2
-2
app/services/files/multi_service.rb
app/services/files/multi_service.rb
+6
-6
lib/gitlab/git/index.rb
lib/gitlab/git/index.rb
+21
-15
spec/lib/gitlab/git/index_spec.rb
spec/lib/gitlab/git/index_spec.rb
+10
-0
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+2
-2
No files found.
app/models/repository.rb
View file @
a530e9da
...
@@ -753,7 +753,7 @@ class Repository
...
@@ -753,7 +753,7 @@ class Repository
author_email:
nil
,
author_name:
nil
,
author_email:
nil
,
author_name:
nil
,
start_branch_name:
nil
,
start_project:
project
)
start_branch_name:
nil
,
start_project:
project
)
entry
=
tree_entry_at
(
start_branch_name
||
branch_name
,
path
)
entry
=
start_project
.
repository
.
tree_entry_at
(
start_branch_name
||
branch_name
,
path
)
if
entry
if
entry
if
entry
[
:type
]
==
:blob
if
entry
[
:type
]
==
:blob
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
...
@@ -865,7 +865,7 @@ class Repository
...
@@ -865,7 +865,7 @@ class Repository
end
end
actions
.
each
do
|
options
|
actions
.
each
do
|
options
|
index
.
__send__
(
options
.
delete
(
:action
),
options
)
index
.
public_send
(
options
.
delete
(
:action
),
options
)
end
end
options
=
{
options
=
{
...
...
app/services/files/multi_service.rb
View file @
a530e9da
...
@@ -22,6 +22,12 @@ module Files
...
@@ -22,6 +22,12 @@ module Files
def
validate
def
validate
super
super
params
[
:actions
].
each_with_index
do
|
action
,
index
|
params
[
:actions
].
each_with_index
do
|
action
,
index
|
if
ACTIONS
.
include?
(
action
[
:action
].
to_s
)
action
[
:action
]
=
action
[
:action
].
to_sym
else
raise_error
(
"Unknown action type `
#{
action
[
:action
]
}
`."
)
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
...
@@ -32,12 +38,6 @@ module Files
...
@@ -32,12 +38,6 @@ module Files
regex_check
(
action
[
:file_path
])
regex_check
(
action
[
:file_path
])
regex_check
(
action
[
:previous_path
])
if
action
[
:previous_path
]
regex_check
(
action
[
:previous_path
])
if
action
[
:previous_path
]
if
ACTIONS
.
include?
(
action
[
:action
].
to_s
)
action
[
:action
]
=
action
[
:action
].
to_sym
else
raise_error
(
"Unknown action type `
#{
action
[
:action
]
}
`."
)
end
if
project
.
empty_repo?
&&
action
[
:action
]
!=
:create
if
project
.
empty_repo?
&&
action
[
:action
]
!=
:create
raise_error
(
"No files to
#{
action
[
:action
]
}
."
)
raise_error
(
"No files to
#{
action
[
:action
]
}
."
)
end
end
...
...
lib/gitlab/git/index.rb
View file @
a530e9da
...
@@ -10,20 +10,20 @@ module Gitlab
...
@@ -10,20 +10,20 @@ module Gitlab
@raw_index
=
repository
.
rugged
.
index
@raw_index
=
repository
.
rugged
.
index
end
end
delegate
:read_tree
,
to: :raw_index
delegate
:read_tree
,
:get
,
to: :raw_index
def
write_tree
def
write_tree
raw_index
.
write_tree
(
repository
.
rugged
)
raw_index
.
write_tree
(
repository
.
rugged
)
end
end
def
get
(
*
args
)
def
dir_exists?
(
path
)
raw_index
.
get
(
*
args
)
raw_index
.
find
{
|
entry
|
entry
[
:path
].
start_with?
(
"
#{
path
}
/"
)
}
end
end
def
create
(
options
)
def
create
(
options
)
normalize_options!
(
options
)
options
=
normalize_options
(
options
)
file_entry
=
raw_index
.
get
(
options
[
:file_path
])
file_entry
=
get
(
options
[
:file_path
])
if
file_entry
if
file_entry
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"Filename already exists"
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"Filename already exists"
)
end
end
...
@@ -32,13 +32,17 @@ module Gitlab
...
@@ -32,13 +32,17 @@ module Gitlab
end
end
def
create_dir
(
options
)
def
create_dir
(
options
)
normalize_options!
(
options
)
options
=
normalize_options
(
options
)
file_entry
=
raw_index
.
get
(
options
[
:file_path
])
file_entry
=
get
(
options
[
:file_path
])
if
file_entry
if
file_entry
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"Directory already exists as a file"
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"Directory already exists as a file"
)
end
end
if
dir_exists?
(
options
[
:file_path
])
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"Directory already exists"
)
end
options
=
options
.
dup
options
=
options
.
dup
options
[
:file_path
]
+=
'/.gitkeep'
options
[
:file_path
]
+=
'/.gitkeep'
options
[
:content
]
=
''
options
[
:content
]
=
''
...
@@ -47,9 +51,9 @@ module Gitlab
...
@@ -47,9 +51,9 @@ module Gitlab
end
end
def
update
(
options
)
def
update
(
options
)
normalize_options!
(
options
)
options
=
normalize_options
(
options
)
file_entry
=
raw_index
.
get
(
options
[
:file_path
])
file_entry
=
get
(
options
[
:file_path
])
unless
file_entry
unless
file_entry
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"File doesn't exist"
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"File doesn't exist"
)
end
end
...
@@ -58,9 +62,9 @@ module Gitlab
...
@@ -58,9 +62,9 @@ module Gitlab
end
end
def
move
(
options
)
def
move
(
options
)
normalize_options!
(
options
)
options
=
normalize_options
(
options
)
file_entry
=
raw_index
.
get
(
options
[
:previous_path
])
file_entry
=
get
(
options
[
:previous_path
])
unless
file_entry
unless
file_entry
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"File doesn't exist"
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"File doesn't exist"
)
end
end
...
@@ -71,9 +75,9 @@ module Gitlab
...
@@ -71,9 +75,9 @@ module Gitlab
end
end
def
delete
(
options
)
def
delete
(
options
)
normalize_options!
(
options
)
options
=
normalize_options
(
options
)
file_entry
=
raw_index
.
get
(
options
[
:file_path
])
file_entry
=
get
(
options
[
:file_path
])
unless
file_entry
unless
file_entry
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"File doesn't exist"
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
"File doesn't exist"
)
end
end
...
@@ -83,13 +87,15 @@ module Gitlab
...
@@ -83,13 +87,15 @@ module Gitlab
private
private
def
normalize_options!
(
options
)
def
normalize_options
(
options
)
options
=
options
.
dup
options
[
:file_path
]
=
normalize_path
(
options
[
:file_path
])
if
options
[
:file_path
]
options
[
:file_path
]
=
normalize_path
(
options
[
:file_path
])
if
options
[
:file_path
]
options
[
:previous_path
]
=
normalize_path
(
options
[
:previous_path
])
if
options
[
:previous_path
]
options
[
:previous_path
]
=
normalize_path
(
options
[
:previous_path
])
if
options
[
:previous_path
]
options
end
end
def
normalize_path
(
path
)
def
normalize_path
(
path
)
pathname
=
Gitlab
::
Git
::
PathHelper
.
normalize_path
(
path
)
pathname
=
Gitlab
::
Git
::
PathHelper
.
normalize_path
(
path
.
dup
)
if
pathname
.
each_filename
.
include?
(
'..'
)
if
pathname
.
each_filename
.
include?
(
'..'
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
'Invalid path'
)
raise
Gitlab
::
Git
::
Repository
::
InvalidBlobName
.
new
(
'Invalid path'
)
...
...
spec/lib/gitlab/git/index_spec.rb
View file @
a530e9da
...
@@ -92,6 +92,16 @@ describe Gitlab::Git::Index, seed_helper: true do
...
@@ -92,6 +92,16 @@ describe Gitlab::Git::Index, seed_helper: true do
expect
{
index
.
create_dir
(
options
)
}.
to
raise_error
(
'Directory already exists as a file'
)
expect
{
index
.
create_dir
(
options
)
}.
to
raise_error
(
'Directory already exists as a file'
)
end
end
end
end
context
'when a directory at that path exists'
do
before
do
options
[
:file_path
]
=
'files/executables'
end
it
'raises an error'
do
expect
{
index
.
create_dir
(
options
)
}.
to
raise_error
(
'Directory already exists'
)
end
end
end
end
describe
'#update'
do
describe
'#update'
do
...
...
spec/models/repository_spec.rb
View file @
a530e9da
...
@@ -291,7 +291,7 @@ describe Repository, models: true do
...
@@ -291,7 +291,7 @@ describe Repository, models: true do
end
end
end
end
describe
"#c
ommit
_dir"
do
describe
"#c
reate
_dir"
do
it
"commits a change that creates a new directory"
do
it
"commits a change that creates a new directory"
do
expect
do
expect
do
repository
.
create_dir
(
user
,
'newdir'
,
repository
.
create_dir
(
user
,
'newdir'
,
...
@@ -424,7 +424,7 @@ describe Repository, models: true do
...
@@ -424,7 +424,7 @@ describe Repository, models: true do
end
end
end
end
describe
"#
remov
e_file"
do
describe
"#
delet
e_file"
do
it
'removes file successfully'
do
it
'removes file successfully'
do
expect
do
expect
do
repository
.
delete_file
(
user
,
'README'
,
repository
.
delete_file
(
user
,
'README'
,
...
...
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