Skip to content
Snippets Groups Projects
Unverified Commit 986697a9 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets
Browse files

Refactor Create/Update file context and lib

parent c77d957b
No related branches found
No related tags found
1 merge request!1Fix Links To Gitlab Cloud
Loading
@@ -33,11 +33,10 @@ module Files
Loading
@@ -33,11 +33,10 @@ module Files
return error("Your changes could not be commited, because file with such name exists") return error("Your changes could not be commited, because file with such name exists")
end 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!( created_successfully = new_file_action.commit!(
params[:content], params[:content],
params[:commit_message], params[:commit_message]
file_name,
) )
   
if created_successfully if created_successfully
Loading
Loading
Loading
@@ -24,8 +24,7 @@ module Files
Loading
@@ -24,8 +24,7 @@ module Files
new_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path) new_file_action = Gitlab::Satellite::EditFileAction.new(current_user, project, ref, path)
created_successfully = new_file_action.commit!( created_successfully = new_file_action.commit!(
params[:content], params[:content],
params[:commit_message], params[:commit_message]
params[:last_commit]
) )
   
if created_successfully if created_successfully
Loading
Loading
Loading
@@ -10,9 +10,7 @@ module Gitlab
Loading
@@ -10,9 +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 Gitolite failed or was rejected # Returns false if pushing from the satellite to Gitolite failed or was rejected
# Returns true otherwise # Returns true otherwise
def commit!(content, commit_message, last_commit) def commit!(content, commit_message)
return false unless can_edit?(last_commit)
in_locked_and_timed_satellite do |repo| in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo) prepare_satellite!(repo)
   
Loading
Loading
Loading
@@ -8,13 +8,6 @@ module Gitlab
Loading
@@ -8,13 +8,6 @@ module Gitlab
@file_path = file_path @file_path = file_path
@ref = ref @ref = ref
end 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 end
end end
Loading
@@ -9,7 +9,7 @@ module Gitlab
Loading
@@ -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 Gitolite failed or was rejected # Returns false if pushing from the satellite to Gitolite failed or was rejected
# Returns true otherwise # Returns true otherwise
def commit!(content, commit_message, file_name) def commit!(content, commit_message)
in_locked_and_timed_satellite do |repo| in_locked_and_timed_satellite do |repo|
prepare_satellite!(repo) prepare_satellite!(repo)
   
Loading
@@ -17,7 +17,7 @@ module Gitlab
Loading
@@ -17,7 +17,7 @@ module Gitlab
repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}") repo.git.checkout({raise: true, timeout: true, b: true}, ref, "origin/#{ref}")
   
# update the file in the satellite's working dir # 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) } File.open(file_path_in_satellite, 'w') { |f| f.write(content) }
   
# add new file # add new file
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment