diff options
author | Robert Speicher <robert@gitlab.com> | 2018-01-10 19:13:50 +0000 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2018-01-10 19:13:50 +0000 |
commit | 4fc0a0901791cd385e38fb437d167e65847fb015 (patch) | |
tree | 91939f7017af3bc3f6721dc9135be03d48f260ee /lib | |
parent | 968430fe8c4eaa1de5799d9e629375c3bbe38853 (diff) | |
parent | 657065b73eb7253d60c9a63c74a75c0f9c3085ca (diff) | |
download | gitlab-ce-4fc0a0901791cd385e38fb437d167e65847fb015.tar.gz |
Merge branch 'git-write-ref-prep' into 'master'
Gitlab::Git::Repository#write_ref client-prep take 2
Closes gitaly#793
See merge request gitlab-org/gitlab-ce!16287
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 17 |
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) |