summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-10-26 00:33:53 +0200
committerRiyad Preukschas <riyad@informatik.uni-bremen.de>2012-10-26 00:33:53 +0200
commit55779b00ea695463056338af993c6332b710ea8f (patch)
tree1fe117b8071d294ee1588cb3e7b16ceca20d9ff4 /lib
parent8c89beb6f9bca14dd79fb1e0a81ebb65354edf73 (diff)
downloadgitlab-ce-55779b00ea695463056338af993c6332b710ea8f.tar.gz
Rename Gitlab::FileEditor to Gitlab::Satellite::EditFileAction
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/file_editor.rb58
-rw-r--r--lib/gitlab/satellite/edit_file_action.rb43
-rw-r--r--lib/gitlab/satellite/merge_action.rb4
3 files changed, 45 insertions, 60 deletions
diff --git a/lib/gitlab/file_editor.rb b/lib/gitlab/file_editor.rb
deleted file mode 100644
index dc3f9480460..00000000000
--- a/lib/gitlab/file_editor.rb
+++ /dev/null
@@ -1,58 +0,0 @@
-module Gitlab
- # GitLab file editor
- #
- # It gives you ability to make changes to files
- # & commit this changes from GitLab UI.
- class FileEditor
- attr_accessor :user, :project, :ref
-
- def initialize(user, project, ref)
- self.user = user
- self.project = project
- self.ref = ref
- end
-
- def update(path, content, commit_message, last_commit)
- return false unless can_edit?(path, last_commit)
-
- Grit::Git.with_timeout(10.seconds) do
- lock_file = Rails.root.join("tmp", "#{project.path}.lock")
-
- File.open(lock_file, "w+") do |f|
- f.flock(File::LOCK_EX)
-
- unless project.satellite.exists?
- raise "Satellite doesn't exist"
- end
-
- project.satellite.clear
-
- Dir.chdir(project.satellite.path) do
- r = Grit::Repo.new('.')
- r.git.sh "git reset --hard"
- r.git.sh "git fetch origin"
- r.git.sh "git config user.name \"#{user.name}\""
- r.git.sh "git config user.email \"#{user.email}\""
- r.git.sh "git checkout -b #{ref} origin/#{ref}"
- File.open(path, 'w'){|f| f.write(content)}
- r.git.sh "git add ."
- r.git.sh "git commit -am '#{commit_message}'"
- output = r.git.sh "git push origin #{ref}"
-
- if output =~ /reject/
- return false
- end
- end
- end
- end
- true
- end
-
- protected
-
- def can_edit?(path, last_commit)
- current_last_commit = @project.last_commit_for(ref, path).sha
- last_commit == current_last_commit
- end
- end
-end
diff --git a/lib/gitlab/satellite/edit_file_action.rb b/lib/gitlab/satellite/edit_file_action.rb
new file mode 100644
index 00000000000..8949f54c689
--- /dev/null
+++ b/lib/gitlab/satellite/edit_file_action.rb
@@ -0,0 +1,43 @@
+module Gitlab
+ module Satellite
+ # GitLab file editor
+ #
+ # It gives you ability to make changes to files
+ # & commit this changes from GitLab UI.
+ class EditFileAction < Action
+ attr_accessor :ref
+
+ def initialize(user, project, ref)
+ super user, project
+ @ref = ref
+ end
+
+ def update(path, content, commit_message, last_commit)
+ return false unless can_edit?(path, last_commit)
+
+ in_locked_and_timed_satellite do |repo|
+ prepare_satellite!(repo)
+
+ repo.git.sh "git checkout -b #{ref} origin/#{ref}"
+ File.open(path, 'w'){|f| f.write(content)}
+ repo.git.sh "git add ."
+ repo.git.sh "git commit -am '#{commit_message}'"
+ output = repo.git.sh "git push origin #{ref}"
+
+ # everything worked
+ true
+ end
+ rescue Grit::Git::CommandFailed => ex
+ Gitlab::GitLogger.error(ex.message)
+ false
+ end
+
+ protected
+
+ def can_edit?(path, last_commit)
+ current_last_commit = @project.last_commit_for(ref, path).sha
+ last_commit == current_last_commit
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/satellite/merge_action.rb b/lib/gitlab/satellite/merge_action.rb
index ffca6938901..edef8f6a7f1 100644
--- a/lib/gitlab/satellite/merge_action.rb
+++ b/lib/gitlab/satellite/merge_action.rb
@@ -55,11 +55,11 @@ module Gitlab
prepare_satellite!(repo)
# create target branch in satellite at the corresponding commit from Gitolite
- repo.git.checkout({b: true}, merge_request.target_branch, "origin/#{merge_request.target_branch}")
+ repo.git.checkout({raise: true, b: true}, merge_request.target_branch, "origin/#{merge_request.target_branch}")
# merge the source branch from Gitolite into the satellite
# will raise CommandFailed when merge fails
- repo.git.pull({no_ff: true, raise: true}, :origin, merge_request.source_branch)
+ repo.git.pull({raise: true, no_ff: true}, :origin, merge_request.source_branch)
rescue Grit::Git::CommandFailed => ex
Gitlab::GitLogger.error(ex.message)
false