Refactor Create/Update file context and lib

Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
This commit is contained in:
Dmitriy Zaporozhets 2013-11-11 14:58:39 +02:00
parent c77d957b36
commit 986697a99b
No known key found for this signature in database
GPG key ID: 2CEAFD2671262EC2
5 changed files with 6 additions and 17 deletions

View file

@ -33,11 +33,10 @@ module Files
return error("Your changes could not be commited, because file with such name exists")
end
new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, path)
new_file_action = Gitlab::Satellite::NewFileAction.new(current_user, project, ref, file_path)
created_successfully = new_file_action.commit!(
params[:content],
params[:commit_message],
file_name,
params[:commit_message]
)
if created_successfully

View file

@ -24,8 +24,7 @@ module Files
new_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path)
created_successfully = new_file_action.commit!(
params[:content],
params[:commit_message],
params[:last_commit]
params[:commit_message]
)
if created_successfully

View file

@ -10,9 +10,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if pushing from the satellite to Gitolite failed or was rejected
# Returns true otherwise
def commit!(content, commit_message, last_commit)
return false unless can_edit?(last_commit)
def commit!(content, commit_message)
in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo)

View file

@ -8,13 +8,6 @@ module Gitlab
@file_path = file_path
@ref = ref
end
protected
def can_edit?(last_commit)
current_last_commit = Gitlab::Git::Commit.last_for_path(@project.repository, ref, file_path).sha
last_commit == current_last_commit
end
end
end
end

View file

@ -9,7 +9,7 @@ module Gitlab
# Returns false if committing the change fails
# Returns false if pushing from the satellite to Gitolite failed or was rejected
# Returns true otherwise
def commit!(content, commit_message, file_name)
def commit!(content, commit_message)
in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo)
@ -17,7 +17,7 @@ module Gitlab
repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}")
# update the file in the satellite's working dir
file_path_in_satellite = File.join(repo.working_dir, file_path || '', file_name)
file_path_in_satellite = File.join(repo.working_dir, file_path)
File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
# add new file