From 986697a99bde07ea0d7e878f8618f801b6b81a8c Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 11 Nov 2013 14:58:39 +0200 Subject: [PATCH] Refactor Create/Update file context and lib Signed-off-by: Dmitriy Zaporozhets --- app/contexts/files/create_context.rb | 5 ++--- app/contexts/files/update_context.rb | 3 +-- lib/gitlab/satellite/files/edit_file_action.rb | 4 +--- lib/gitlab/satellite/files/file_action.rb | 7 ------- lib/gitlab/satellite/files/new_file_action.rb | 4 ++-- 5 files changed, 6 insertions(+), 17 deletions(-) diff --git a/app/contexts/files/create_context.rb b/app/contexts/files/create_context.rb index e1554c47b..ae73b11bd 100644 --- a/app/contexts/files/create_context.rb +++ b/app/contexts/files/create_context.rb @@ -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 diff --git a/app/contexts/files/update_context.rb b/app/contexts/files/update_context.rb index 000d3d02f..f40c74969 100644 --- a/app/contexts/files/update_context.rb +++ b/app/contexts/files/update_context.rb @@ -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 diff --git a/lib/gitlab/satellite/files/edit_file_action.rb b/lib/gitlab/satellite/files/edit_file_action.rb index 72e12fb07..3747c6afc 100644 --- a/lib/gitlab/satellite/files/edit_file_action.rb +++ b/lib/gitlab/satellite/files/edit_file_action.rb @@ -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) diff --git a/lib/gitlab/satellite/files/file_action.rb b/lib/gitlab/satellite/files/file_action.rb index 4ac53c2cd..7c08e2921 100644 --- a/lib/gitlab/satellite/files/file_action.rb +++ b/lib/gitlab/satellite/files/file_action.rb @@ -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 diff --git a/lib/gitlab/satellite/files/new_file_action.rb b/lib/gitlab/satellite/files/new_file_action.rb index 70a5ea219..97b19809c 100644 --- a/lib/gitlab/satellite/files/new_file_action.rb +++ b/lib/gitlab/satellite/files/new_file_action.rb @@ -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 -- 2.11.0