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
7527408a
Commit
7527408a
authored
Jan 17, 2014
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/base64_content' into 'master'
Feature: base64 encoding for blob content
parents
dba98240
1c4870c5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
30 additions
and
11 deletions
+30
-11
app/assets/stylesheets/generic/files.scss
app/assets/stylesheets/generic/files.scss
+1
-1
app/contexts/files/create_context.rb
app/contexts/files/create_context.rb
+2
-1
app/contexts/files/update_context.rb
app/contexts/files/update_context.rb
+4
-3
app/views/projects/new_tree/show.html.haml
app/views/projects/new_tree/show.html.haml
+6
-0
doc/api/repositories.md
doc/api/repositories.md
+2
-0
lib/api/files.rb
lib/api/files.rb
+2
-2
lib/gitlab/satellite/files/edit_file_action.rb
lib/gitlab/satellite/files/edit_file_action.rb
+3
-2
lib/gitlab/satellite/files/file_action.rb
lib/gitlab/satellite/files/file_action.rb
+8
-0
lib/gitlab/satellite/files/new_file_action.rb
lib/gitlab/satellite/files/new_file_action.rb
+2
-2
No files found.
app/assets/stylesheets/generic/files.scss
View file @
7527408a
...
@@ -45,7 +45,7 @@
...
@@ -45,7 +45,7 @@
text-align
:
center
;
text-align
:
center
;
img
{
img
{
padding
:
100px
;
padding
:
100px
;
max-width
:
300px
;
max-width
:
50%
;
}
}
}
}
...
...
app/contexts/files/create_context.rb
View file @
7527408a
...
@@ -33,7 +33,8 @@ module Files
...
@@ -33,7 +33,8 @@ module Files
new_file_action
=
Gitlab
::
Satellite
::
NewFileAction
.
new
(
current_user
,
project
,
ref
,
file_path
)
new_file_action
=
Gitlab
::
Satellite
::
NewFileAction
.
new
(
current_user
,
project
,
ref
,
file_path
)
created_successfully
=
new_file_action
.
commit!
(
created_successfully
=
new_file_action
.
commit!
(
params
[
:content
],
params
[
:content
],
params
[
:commit_message
]
params
[
:commit_message
],
params
[
:encoding
]
)
)
if
created_successfully
if
created_successfully
...
...
app/contexts/files/update_context.rb
View file @
7527408a
...
@@ -23,10 +23,11 @@ module Files
...
@@ -23,10 +23,11 @@ module Files
return
error
(
"You can only edit text files"
)
return
error
(
"You can only edit text files"
)
end
end
new
_file_action
=
Gitlab
::
Satellite
::
EditFileAction
.
new
(
current_user
,
project
,
ref
,
path
)
edit
_file_action
=
Gitlab
::
Satellite
::
EditFileAction
.
new
(
current_user
,
project
,
ref
,
path
)
created_successfully
=
new
_file_action
.
commit!
(
created_successfully
=
edit
_file_action
.
commit!
(
params
[
:content
],
params
[
:content
],
params
[
:commit_message
]
params
[
:commit_message
],
params
[
:encoding
]
)
)
if
created_successfully
if
created_successfully
...
...
app/views/projects/new_tree/show.html.haml
View file @
7527408a
...
@@ -14,6 +14,12 @@
...
@@ -14,6 +14,12 @@
on
on
%span
=
@ref
%span
=
@ref
.form-group.commit_message-group
=
label_tag
:encoding
,
class:
"control-label"
do
Encoding
.col-sm-10
=
select_tag
:encoding
,
options_for_select
([
"base64"
,
"text"
],
"text"
),
class:
'form-control'
.form-group.commit_message-group
.form-group.commit_message-group
=
label_tag
'commit_message'
,
class:
"control-label"
do
=
label_tag
'commit_message'
,
class:
"control-label"
do
Commit message
Commit message
...
...
doc/api/repositories.md
View file @
7527408a
...
@@ -400,6 +400,7 @@ Parameters:
...
@@ -400,6 +400,7 @@ Parameters:
+
`file_path`
(optional) - Full path to new file. Ex. lib/class.rb
+
`file_path`
(optional) - Full path to new file. Ex. lib/class.rb
+
`branch_name`
(required) - The name of branch
+
`branch_name`
(required) - The name of branch
+
`encoding`
(optional) - 'text' or 'base64'. Text is default.
+
`content`
(required) - File content
+
`content`
(required) - File content
+
`commit_message`
(required) - Commit message
+
`commit_message`
(required) - Commit message
...
@@ -413,6 +414,7 @@ Parameters:
...
@@ -413,6 +414,7 @@ Parameters:
+
`file_path`
(required) - Full path to file. Ex. lib/class.rb
+
`file_path`
(required) - Full path to file. Ex. lib/class.rb
+
`branch_name`
(required) - The name of branch
+
`branch_name`
(required) - The name of branch
+
`encoding`
(optional) - 'text' or 'base64'. Text is default.
+
`content`
(required) - New file content
+
`content`
(required) - New file content
+
`commit_message`
(required) - Commit message
+
`commit_message`
(required) - Commit message
...
...
lib/api/files.rb
View file @
7527408a
...
@@ -18,7 +18,7 @@ module API
...
@@ -18,7 +18,7 @@ module API
#
#
post
":id/repository/files"
do
post
":id/repository/files"
do
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
]
branch_name
=
attrs
.
delete
(
:branch_name
)
branch_name
=
attrs
.
delete
(
:branch_name
)
file_path
=
attrs
.
delete
(
:file_path
)
file_path
=
attrs
.
delete
(
:file_path
)
result
=
::
Files
::
CreateContext
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
result
=
::
Files
::
CreateContext
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
...
@@ -48,7 +48,7 @@ module API
...
@@ -48,7 +48,7 @@ module API
#
#
put
":id/repository/files"
do
put
":id/repository/files"
do
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
required_attributes!
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
]
attrs
=
attributes_for_keys
[
:file_path
,
:branch_name
,
:content
,
:commit_message
,
:encoding
]
branch_name
=
attrs
.
delete
(
:branch_name
)
branch_name
=
attrs
.
delete
(
:branch_name
)
file_path
=
attrs
.
delete
(
:file_path
)
file_path
=
attrs
.
delete
(
:file_path
)
result
=
::
Files
::
UpdateContext
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
result
=
::
Files
::
UpdateContext
.
new
(
user_project
,
current_user
,
attrs
,
branch_name
,
file_path
).
execute
...
...
lib/gitlab/satellite/files/edit_file_action.rb
View file @
7527408a
...
@@ -10,7 +10,7 @@ module Gitlab
...
@@ -10,7 +10,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if committing the change fails
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
# Returns true otherwise
def
commit!
(
content
,
commit_message
)
def
commit!
(
content
,
commit_message
,
encoding
)
in_locked_and_timed_satellite
do
|
repo
|
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
prepare_satellite!
(
repo
)
...
@@ -26,7 +26,8 @@ module Gitlab
...
@@ -26,7 +26,8 @@ module Gitlab
return
false
return
false
end
end
File
.
open
(
file_path_in_satellite
,
'w'
)
{
|
f
|
f
.
write
(
content
)
}
# Write file
write_file
(
file_path_in_satellite
,
content
,
encoding
)
# commit the changes
# commit the changes
# will raise CommandFailed when commit fails
# will raise CommandFailed when commit fails
...
...
lib/gitlab/satellite/files/file_action.rb
View file @
7527408a
...
@@ -12,6 +12,14 @@ module Gitlab
...
@@ -12,6 +12,14 @@ module Gitlab
def
safe_path?
(
path
)
def
safe_path?
(
path
)
File
.
absolute_path
(
path
)
==
path
File
.
absolute_path
(
path
)
==
path
end
end
def
write_file
(
abs_file_path
,
content
,
file_encoding
=
'text'
)
if
file_encoding
==
'base64'
File
.
open
(
abs_file_path
,
'wb'
)
{
|
f
|
f
.
write
(
Base64
.
decode64
(
content
))
}
else
File
.
open
(
abs_file_path
,
'w'
)
{
|
f
|
f
.
write
(
content
)
}
end
end
end
end
end
end
end
end
lib/gitlab/satellite/files/new_file_action.rb
View file @
7527408a
...
@@ -9,7 +9,7 @@ module Gitlab
...
@@ -9,7 +9,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if committing the change fails
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns false if pushing from the satellite to bare repo failed or was rejected
# Returns true otherwise
# Returns true otherwise
def
commit!
(
content
,
commit_message
)
def
commit!
(
content
,
commit_message
,
encoding
)
in_locked_and_timed_satellite
do
|
repo
|
in_locked_and_timed_satellite
do
|
repo
|
prepare_satellite!
(
repo
)
prepare_satellite!
(
repo
)
...
@@ -29,7 +29,7 @@ module Gitlab
...
@@ -29,7 +29,7 @@ module Gitlab
FileUtils
.
mkdir_p
(
dir_name_in_satellite
)
FileUtils
.
mkdir_p
(
dir_name_in_satellite
)
# Write file
# Write file
File
.
open
(
file_path_in_satellite
,
'w'
)
{
|
f
|
f
.
write
(
content
)
}
write_file
(
file_path_in_satellite
,
content
,
encoding
)
# add new file
# add new file
repo
.
add
(
file_path_in_satellite
)
repo
.
add
(
file_path_in_satellite
)
...
...
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