Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorZeger-Jan van de Weg <git@zjvandeweg.nl>2018-02-20 11:06:00 +0300
committerZeger-Jan van de Weg <git@zjvandeweg.nl>2018-02-21 21:08:26 +0300
commite70fe78281ba07d9a0eb863d66ddf6a13917fde1 (patch)
tree9a182fa06fdb2555d8ca1238d7e960ec7e0a6ade /lib
parent9ff91bc481683e3619e0745b03161a12a5afd497 (diff)
Handle branch and tag names which are commit ids
Adds a test where a branch name is also a valid commit id. Git, the binary should create an error message which is difficult to parse and leading to errors later, as seen in: gitlab-org/gitlab-ce#43222 To catch these cases in the future, gitlab-test@1942eed5cc108b19c7405106e81fa96125d0be22 was created. Which a branch name matching the commit
Diffstat (limited to 'lib')
-rw-r--r--lib/gitlab/git/repository.rb26
1 files changed, 16 insertions, 10 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index a10bc0dd32b..072ad312ab8 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -1349,7 +1349,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
@@ -1359,7 +1359,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
@@ -1458,19 +1458,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:)