diff options
author | Robert Speicher <robert@gitlab.com> | 2017-12-12 19:36:58 +0300 |
---|---|---|
committer | Robert Speicher <robert@gitlab.com> | 2017-12-12 19:36:58 +0300 |
commit | b655a4a790b05f6023563b35a3823728480c33fc (patch) | |
tree | 3d179933792e405809148060faae000d482def40 /lib | |
parent | 2cbfc992c9005ed193b2d547a5537313dbf2ca0e (diff) | |
parent | dad4c0b645d499c93fba14ce1e691da151929071 (diff) |
Merge branch 'repo-write-ref-client-prep' into 'master'
Move Repository#write_ref to Git::Repository#write_ref
Closes gitaly#793
See merge request gitlab-org/gitlab-ce!15712
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index fbdd646ea13..0e0a1987c7d 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1073,12 +1073,17 @@ module Gitlab end end - def write_ref(ref_path, ref) + def write_ref(ref_path, ref, force: false) raise ArgumentError, "invalid ref_path #{ref_path.inspect}" if ref_path.include?(' ') raise ArgumentError, "invalid ref #{ref.inspect}" if ref.include?("\x00") - input = "update #{ref_path}\x00#{ref}\x00\x00" - run_git!(%w[update-ref --stdin -z]) { |stdin| stdin.write(input) } + ref = "refs/heads/#{ref}" unless ref.start_with?("refs") || ref =~ /\A[a-f0-9]+\z/i + + rugged.references.create(ref_path, ref, force: force) + rescue Rugged::ReferenceError => ex + raise GitError, "could not create ref #{ref_path}: #{ex}" + rescue Rugged::OSError => ex + raise GitError, "could not create ref #{ref_path}: #{ex}" end def fetch_ref(source_repository, source_ref:, target_ref:) |