diff options
author | Douwe Maan <douwe@gitlab.com> | 2018-02-22 11:34:03 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2018-02-22 11:34:03 +0000 |
commit | e503efa320b05939f290f09e79c3b6fe98fb7803 (patch) | |
tree | faf2ecf1a279f37f42cd7ead9006e41f6a4de467 /lib | |
parent | 6ad7eceb5cfac766b1942ac7b85380869071b58d (diff) | |
parent | e70fe78281ba07d9a0eb863d66ddf6a13917fde1 (diff) | |
download | gitlab-ce-e503efa320b05939f290f09e79c3b6fe98fb7803.tar.gz |
Merge branch 'zj-branch-contains-git-message' into 'master'
Allow branchnames to be named the same as the commit it points to
See merge request gitlab-org/gitlab-ce!17231
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 26 |
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 03fa474af95..c4deb4f7a47 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -1355,7 +1355,7 @@ module Gitlab if is_enabled gitaly_ref_client.branch_names_contains_sha(sha) else - refs_contains_sha(:branch, sha) + refs_contains_sha('refs/heads/', sha) end end end @@ -1365,7 +1365,7 @@ module Gitlab if is_enabled gitaly_ref_client.tag_names_contains_sha(sha) else - refs_contains_sha(:tag, sha) + refs_contains_sha('refs/tags/', sha) end end end @@ -1464,19 +1464,25 @@ module Gitlab end end - def refs_contains_sha(ref_type, sha) - args = %W(#{ref_type} --contains #{sha}) - names = run_git(args).first + def refs_contains_sha(refs_prefix, sha) + refs_prefix << "/" unless refs_prefix.ends_with?('/') - return [] unless names.respond_to?(:split) + # By forcing the output to %(refname) each line wiht a ref will start with + # the ref prefix. All other lines can be discarded. + args = %W(for-each-ref --contains=#{sha} --format=%(refname) #{refs_prefix}) + names, code = run_git(args) - names = names.split("\n").map(&:strip) + return [] unless code.zero? - names.each do |name| - name.slice! '* ' + refs = [] + left_slice_count = refs_prefix.length + names.lines.each do |line| + next unless line.start_with?(refs_prefix) + + refs << line.rstrip[left_slice_count..-1] end - names + refs end def rugged_write_config(full_path:) |