summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2018-01-08 16:24:59 +0100
committerKim "BKC" Carlbäcker <kim.carlbacker@gmail.com>2018-01-09 15:20:44 +0100
commit657065b73eb7253d60c9a63c74a75c0f9c3085ca (patch)
tree773ab1b61c38cfe0582a8111dbbf02d88106f84f /lib
parentdf74461014bbdbc691f4f4039b02962dad292362 (diff)
downloadgitlab-ce-git-write-ref-prep.tar.gz
Client-prep Gitlab::Git::Repository#write_refgit-write-ref-prep
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/repository.rb17
1 files changed, 15 insertions, 2 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 283134e043e..fa9bc57dd79 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1103,14 +1103,27 @@ module Gitlab
end
end
- def write_ref(ref_path, ref)
+ def write_ref(ref_path, ref, old_ref: nil, shell: true)
+ if shell
+ shell_write_ref(ref_path, ref, old_ref)
+ else
+ rugged_write_ref(ref_path, ref)
+ 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\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)