summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Speicher <robert@gitlab.com>2018-01-22 16:09:45 +0000
committerRobert Speicher <robert@gitlab.com>2018-01-22 16:09:45 +0000
commitf344f7cecc926a998c2f498f943193337acef953 (patch)
tree06cfd73f8930692e17c550f6c5a2bd0ca2e76f45
parentb871764787068ce13fa03475e3f1d1a739cdc1b6 (diff)
parent728d7e0cf7b1570bc53f143a69612365e493d7a8 (diff)
downloadgitlab-ce-f344f7cecc926a998c2f498f943193337acef953.tar.gz
Merge branch 'gitaly-write-ref-error-handling' into 'master'
Wrap Rugged-exceptions in Gitlab::Git::Repository#write_ref See merge request gitlab-org/gitlab-ce!16570
-rw-r--r--app/models/repository.rb10
-rw-r--r--lib/gitlab/git/repository.rb32
2 files changed, 20 insertions, 22 deletions
diff --git a/app/models/repository.rb b/app/models/repository.rb
index b4bc0f87458..73c4899cb9b 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -259,15 +259,7 @@ class Repository
return if kept_around?(sha)
# This will still fail if the file is corrupted (e.g. 0 bytes)
- begin
- raw_repository.write_ref(keep_around_ref_name(sha), sha, shell: false)
- rescue Rugged::ReferenceError => ex
- Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
- rescue Rugged::OSError => ex
- raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/
-
- Rails.logger.error "Unable to create #{REF_KEEP_AROUND} reference for repository #{path}: #{ex}"
- end
+ raw_repository.write_ref(keep_around_ref_name(sha), sha, shell: false)
end
def kept_around?(sha)
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 455c9902a0a..8bfc3fe52c5 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1091,19 +1091,6 @@ module Gitlab
end
end
- def shell_write_ref(ref_path, ref, old_ref)
- raise ArgumentError, "invalid ref_path #{ref_path.inspect}" if ref_path.include?(' ')
- raise ArgumentError, "invalid ref #{ref.inspect}" if ref.include?("\x00")
- raise ArgumentError, "invalid old_ref #{old_ref.inspect}" if !old_ref.nil? && old_ref.include?("\x00")
-
- input = "update #{ref_path}\x00#{ref}\x00#{old_ref}\x00"
- run_git!(%w[update-ref --stdin -z]) { |stdin| stdin.write(input) }
- end
-
- def rugged_write_ref(ref_path, ref)
- rugged.references.create(ref_path, ref, force: true)
- end
-
def fetch_ref(source_repository, source_ref:, target_ref:)
Gitlab::Git.check_namespace!(source_repository)
source_repository = RemoteRepository.new(source_repository) unless source_repository.is_a?(RemoteRepository)
@@ -1365,6 +1352,25 @@ module Gitlab
private
+ def shell_write_ref(ref_path, ref, old_ref)
+ raise ArgumentError, "invalid ref_path #{ref_path.inspect}" if ref_path.include?(' ')
+ raise ArgumentError, "invalid ref #{ref.inspect}" if ref.include?("\x00")
+ raise ArgumentError, "invalid old_ref #{old_ref.inspect}" if !old_ref.nil? && old_ref.include?("\x00")
+
+ input = "update #{ref_path}\x00#{ref}\x00#{old_ref}\x00"
+ run_git!(%w[update-ref --stdin -z]) { |stdin| stdin.write(input) }
+ end
+
+ def rugged_write_ref(ref_path, ref)
+ rugged.references.create(ref_path, ref, force: true)
+ rescue Rugged::ReferenceError => ex
+ Rails.logger.error "Unable to create #{ref_path} reference for repository #{path}: #{ex}"
+ rescue Rugged::OSError => ex
+ raise unless ex.message =~ /Failed to create locked file/ && ex.message =~ /File exists/
+
+ Rails.logger.error "Unable to create #{ref_path} reference for repository #{path}: #{ex}"
+ end
+
def fresh_worktree?(path)
File.exist?(path) && !clean_stuck_worktree(path)
end