Add support of base64 encoded content
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
parent
dba982403b
commit
21bc41c6ee
3 changed files with 13 additions and 4 deletions
|
@ -10,7 +10,7 @@ module Gitlab
|
|||
# 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)
|
||||
def commit!(content, commit_message, encoding)
|
||||
in_locked_and_timed_satellite do |repo|
|
||||
prepare_satellite!(repo)
|
||||
|
||||
|
@ -26,7 +26,8 @@ module Gitlab
|
|||
return false
|
||||
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
|
||||
# will raise CommandFailed when commit fails
|
||||
|
|
|
@ -12,6 +12,14 @@ module Gitlab
|
|||
def safe_path?(path)
|
||||
File.absolute_path(path) == path
|
||||
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
|
||||
|
|
|
@ -9,7 +9,7 @@ module Gitlab
|
|||
# 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)
|
||||
def commit!(content, commit_message, encoding)
|
||||
in_locked_and_timed_satellite do |repo|
|
||||
prepare_satellite!(repo)
|
||||
|
||||
|
@ -29,7 +29,7 @@ module Gitlab
|
|||
FileUtils.mkdir_p(dir_name_in_satellite)
|
||||
|
||||
# Write file
|
||||
File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
|
||||
write_file(file_path_in_satellite, content, encoding)
|
||||
|
||||
# add new file
|
||||
repo.add(file_path_in_satellite)
|
||||
|
|
Loading…
Reference in a new issue