Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-13 15:29:13 +0300
committerDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>2015-08-13 15:29:13 +0300
commitc8614cbbe76a97dc70576451a75907059b4f876c (patch)
tree7938897c3aeb452fd020d5ac515c91ccd3b74891 /app/services
parent34690142bf42e0a3d48b1b30075387abefe86318 (diff)
Capture pre-receive exception
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'app/services')
-rw-r--r--app/services/commit_service.rb24
-rw-r--r--app/services/files/base_service.rb2
2 files changed, 19 insertions, 7 deletions
diff --git a/app/services/commit_service.rb b/app/services/commit_service.rb
index a5603f26692..92d1585840b 100644
--- a/app/services/commit_service.rb
+++ b/app/services/commit_service.rb
@@ -1,29 +1,41 @@
require 'securerandom'
class CommitService
+ class PreReceiveError < StandardError; end
+ class CommitError < StandardError; end
+
def self.transaction(project, current_user, ref)
repository = project.repository
path_to_repo = repository.path_to_repo
+ empty_repo = repository.empty?
# Create temporary ref
random_string = SecureRandom.hex
tmp_ref = "refs/tmp/#{random_string}/head"
- target = repository.find_branch(ref).target
- repository.rugged.references.create(tmp_ref, target)
+
+ unless empty_repo
+ target = repository.find_branch(ref).target
+ repository.rugged.references.create(tmp_ref, target)
+ end
# Make commit in tmp ref
sha = yield(tmp_ref)
unless sha
- raise 'Failed to create commit'
+ raise CommitError.new('Failed to create commit')
end
# Run GitLab pre-receive hook
status = PreCommitService.new(project, current_user).execute(sha, ref)
if status
- # Update head
- repository.rugged.references.update(Gitlab::Git::BRANCH_REF_PREFIX + ref, sha)
+ if empty_repo
+ # Create branch
+ repository.rugged.references.create(Gitlab::Git::BRANCH_REF_PREFIX + ref, sha)
+ else
+ # Update head
+ repository.rugged.references.update(Gitlab::Git::BRANCH_REF_PREFIX + ref, sha)
+ end
# Run GitLab post receive hook
PostCommitService.new(project, current_user).execute(sha, ref)
@@ -31,7 +43,7 @@ class CommitService
# Remove tmp ref and return error to user
repository.rugged.references.delete(tmp_ref)
- raise 'Commit was rejected by pre-reveive hook'
+ raise PreReceiveError.new('Commit was rejected by pre-reveive hook')
end
end
end
diff --git a/app/services/files/base_service.rb b/app/services/files/base_service.rb
index 1f7b92e222b..507e21f5818 100644
--- a/app/services/files/base_service.rb
+++ b/app/services/files/base_service.rb
@@ -26,7 +26,7 @@ module Files
else
error("Something went wrong. Your changes were not committed")
end
- rescue ValidationError => ex
+ rescue CommitService::CommitError, CommitService::PreReceiveError, ValidationError => ex
error(ex.message)
end