diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-12-04 13:29:25 +0300 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-12-12 18:05:38 +0300 |
commit | dad4c0b645d499c93fba14ce1e691da151929071 (patch) | |
tree | 4c06fa010755af6a3cbaf0f795f9f1681665144b /lib | |
parent | 2a181d68c810e89ff5d2e49999775d8b58adb394 (diff) |
Move Repository#write_ref to Git::Repository#write_ref
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 73889328f36..0f28d68eb4b 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1069,12 +1069,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:) |