diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-12-20 15:05:52 +0100 |
---|---|---|
committer | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2017-12-20 15:05:52 +0100 |
commit | e01439e8192d6440e30ef8b94ade5642f68745fe (patch) | |
tree | c3c23d19477c0da61c273596a40378e9497344bb | |
parent | 3bc95729930fc90ea1aa7e535d86030244e881cc (diff) | |
download | gitlab-ce-41143-fix-write-ref-bug.tar.gz |
nil-guard41143-fix-write-ref-bug
-rw-r--r-- | lib/gitlab/git/repository.rb | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 964439ffcd6..f960732d172 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1087,10 +1087,12 @@ module Gitlab def update_ref(ref_path, ref, old_ref: nil, force: false) 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.include?("\x00") + raise ArgumentError, "invalid old_ref #{old_ref.inspect}" if old_ref && old_ref.include?("\x00") ref = "refs/heads/#{ref}" unless ref.start_with?("refs") || ref =~ /\A[a-f0-9]+\z/i - old_ref = "refs/heads/#{old_ref}" unless old_ref.start_with?("refs") || old_ref =~ /\A[a-f0-9]+\z/i + if old_ref + old_ref = "refs/heads/#{old_ref}" unless old_ref.start_with?("refs") || old_ref =~ /\A[a-f0-9]+\z/i + end run_git!(%W[update-ref --stdin -z]) do |stdin| stdin.write("update #{ref_path}\x00#{ref}\x00#{old_ref}\x00") |