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
1f5e809c
Commit
1f5e809c
authored
Mar 13, 2018
by
James Edwards-Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use correct encoding with Lfs::FileTransfromer
parent
ca66a04f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
19 deletions
+68
-19
app/services/files/multi_service.rb
app/services/files/multi_service.rb
+3
-2
app/services/lfs/file_transformer.rb
app/services/lfs/file_transformer.rb
+13
-3
spec/services/files/multi_service_spec.rb
spec/services/files/multi_service_spec.rb
+30
-10
spec/services/lfs/file_transformer_spec.rb
spec/services/lfs/file_transformer_spec.rb
+22
-4
No files found.
app/services/files/multi_service.rb
View file @
1f5e809c
...
@@ -15,8 +15,9 @@ module Files
...
@@ -15,8 +15,9 @@ module Files
def
actions_after_lfs_transformation
(
transformer
,
actions
)
def
actions_after_lfs_transformation
(
transformer
,
actions
)
actions
.
map
do
|
action
|
actions
.
map
do
|
action
|
if
action
[
:action
]
==
'create'
if
action
[
:action
]
==
'create'
content
=
transformer
.
new_file
(
action
[
:file_path
],
action
[
:content
])
result
=
transformer
.
new_file
(
action
[
:file_path
],
action
[
:content
],
encoding:
action
[
:encoding
])
action
[
:content
]
=
content
action
[
:content
]
=
result
.
content
action
[
:encoding
]
=
result
.
encoding
end
end
action
action
...
...
app/services/lfs/file_transformer.rb
View file @
1f5e809c
...
@@ -20,16 +20,26 @@ module Lfs
...
@@ -20,16 +20,26 @@ module Lfs
@branch_name
=
branch_name
@branch_name
=
branch_name
end
end
def
new_file
(
file_path
,
file_content
)
def
new_file
(
file_path
,
file_content
,
encoding:
nil
)
if
project
.
lfs_enabled?
&&
lfs_file?
(
file_path
)
if
project
.
lfs_enabled?
&&
lfs_file?
(
file_path
)
file_content
=
Base64
.
decode64
(
file_content
)
if
encoding
==
'base64'
lfs_pointer_file
=
Gitlab
::
Git
::
LfsPointerFile
.
new
(
file_content
)
lfs_pointer_file
=
Gitlab
::
Git
::
LfsPointerFile
.
new
(
file_content
)
lfs_object
=
create_lfs_object!
(
lfs_pointer_file
,
file_content
)
lfs_object
=
create_lfs_object!
(
lfs_pointer_file
,
file_content
)
link_lfs_object!
(
lfs_object
)
link_lfs_object!
(
lfs_object
)
lfs_pointer_file
.
pointer
Result
.
new
(
content:
lfs_pointer_file
.
pointer
,
encoding:
'text'
)
else
else
file_content
Result
.
new
(
content:
file_content
,
encoding:
encoding
)
end
end
class
Result
attr_reader
:content
,
:encoding
def
initialize
(
content
:,
encoding
:)
@content
=
content
@encoding
=
encoding
end
end
end
end
...
...
spec/services/files/multi_service_spec.rb
View file @
1f5e809c
...
@@ -16,18 +16,18 @@ describe Files::MultiService do
...
@@ -16,18 +16,18 @@ describe Files::MultiService do
Gitlab
::
Git
::
Commit
.
last_for_path
(
project
.
repository
,
branch_name
,
original_file_path
).
sha
Gitlab
::
Git
::
Commit
.
last_for_path
(
project
.
repository
,
branch_name
,
original_file_path
).
sha
end
end
let
(
:actions
)
do
let
(
:default_action
)
do
[
{
{
action:
action
,
action:
action
,
file_path:
new_file_path
,
file_path:
new_file_path
,
previous_path:
original_file_path
,
previous_path:
original_file_path
,
content:
file_content
,
content:
file_content
,
last_commit_id:
original_commit_id
last_commit_id:
original_commit_id
}
}
]
end
end
let
(
:actions
)
{
[
default_action
]
}
let
(
:commit_params
)
do
let
(
:commit_params
)
do
{
{
commit_message:
"Update File"
,
commit_message:
"Update File"
,
...
@@ -135,6 +135,26 @@ describe Files::MultiService do
...
@@ -135,6 +135,26 @@ describe Files::MultiService do
expect
(
LfsObject
.
last
.
file
.
read
).
to
eq
file_content
expect
(
LfsObject
.
last
.
file
.
read
).
to
eq
file_content
end
end
context
'with base64 encoded content'
do
let
(
:raw_file_content
)
{
'Raw content'
}
let
(
:file_content
)
{
Base64
.
encode64
(
raw_file_content
)
}
let
(
:actions
)
{
[
default_action
.
merge
(
encoding:
'base64'
)]
}
it
'creates an LFS pointer'
do
subject
.
execute
blob
=
repository
.
blob_at
(
'lfs'
,
new_file_path
)
expect
(
blob
.
data
).
to
start_with
(
'version https://git-lfs.github.com/spec/v1'
)
end
it
"creates an LfsObject with the file's content"
do
subject
.
execute
expect
(
LfsObject
.
last
.
file
.
read
).
to
eq
raw_file_content
end
end
it
'links the LfsObject to the project'
do
it
'links the LfsObject to the project'
do
expect
do
expect
do
subject
.
execute
subject
.
execute
...
...
spec/services/lfs/file_transformer_spec.rb
View file @
1f5e809c
...
@@ -16,6 +16,18 @@ describe Lfs::FileTransformer do
...
@@ -16,6 +16,18 @@ describe Lfs::FileTransformer do
subject
.
new_file
(
file_path
,
file_content
)
subject
.
new_file
(
file_path
,
file_content
)
end
end
it
'returns untransformed content'
do
result
=
subject
.
new_file
(
file_path
,
file_content
)
expect
(
result
.
content
).
to
eq
(
file_content
)
end
it
'returns untransformed encoding'
do
result
=
subject
.
new_file
(
file_path
,
file_content
,
encoding:
'base64'
)
expect
(
result
.
encoding
).
to
eq
(
'base64'
)
end
end
end
context
'with lfs enabled'
do
context
'with lfs enabled'
do
...
@@ -38,17 +50,23 @@ describe Lfs::FileTransformer do
...
@@ -38,17 +50,23 @@ describe Lfs::FileTransformer do
expect
(
LfsObject
.
last
.
file
.
read
).
to
eq
file_content
expect
(
LfsObject
.
last
.
file
.
read
).
to
eq
file_content
end
end
it
'creates an LFS pointer'
do
it
'returns an LFS pointer'
do
new_content
=
subject
.
new_file
(
file_path
,
file_content
)
result
=
subject
.
new_file
(
file_path
,
file_content
)
expect
(
result
.
content
).
to
start_with
(
'version https://git-lfs.github.com/spec/v1'
)
end
it
'returns LFS pointer encoding as text'
do
result
=
subject
.
new_file
(
file_path
,
file_content
,
encoding:
'base64'
)
expect
(
new_content
).
to
start_with
(
'version https://git-lfs.github.com/spec/v1
'
)
expect
(
result
.
encoding
).
to
eq
(
'text
'
)
end
end
context
"when doesn't use LFS"
do
context
"when doesn't use LFS"
do
let
(
:file_path
)
{
'other.filetype'
}
let
(
:file_path
)
{
'other.filetype'
}
it
"doesn't create LFS pointers"
do
it
"doesn't create LFS pointers"
do
new_content
=
subject
.
new_file
(
file_path
,
file_content
)
new_content
=
subject
.
new_file
(
file_path
,
file_content
)
.
content
expect
(
new_content
).
not_to
start_with
(
'version https://git-lfs.github.com/spec/v1'
)
expect
(
new_content
).
not_to
start_with
(
'version https://git-lfs.github.com/spec/v1'
)
expect
(
new_content
).
to
eq
(
file_content
)
expect
(
new_content
).
to
eq
(
file_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