diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-01 12:15:33 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-05-01 12:15:59 +0000 |
commit | 2b427d3361e2cfeedea1c81c9262e68512116625 (patch) | |
tree | 0803ea4075ba6fec686d3411d926fdc576c61009 /lib | |
parent | 5dbeb2d1625c3dcd46a67220ddce250d9bc3f7bd (diff) | |
download | gitlab-ce-2b427d3361e2cfeedea1c81c9262e68512116625.tar.gz |
Add latest changes from gitlab-org/security/gitlab@15-9-stable-ee
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/git/repository.rb | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index e054b6df98f..e1399b6642b 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -262,7 +262,11 @@ module Gitlab def archive_metadata(ref, storage_path, project_path, format = "tar.gz", append_sha:, path: nil) ref ||= root_ref - commit = Gitlab::Git::Commit.find(self, ref) + + commit_id = extract_commit_id_from_ref(ref) + return {} if commit_id.nil? + + commit = Gitlab::Git::Commit.find(self, commit_id) return {} if commit.nil? prefix = archive_prefix(ref, commit.id, project_path, append_sha: append_sha, path: path) @@ -1233,6 +1237,26 @@ module Gitlab def gitaly_delete_refs(*ref_names) gitaly_ref_client.delete_refs(refs: ref_names) if ref_names.any? end + + # The order is based on git priority to resolve ambiguous references + # + # `git show <ref>` + # + # In case of name clashes, it uses this order: + # 1. Commit + # 2. Tag + # 3. Branch + def extract_commit_id_from_ref(ref) + return ref if Gitlab::Git.commit_id?(ref) + + tag = find_tag(ref) + return tag.dereferenced_target.sha if tag + + branch = find_branch(ref) + return branch.dereferenced_target.sha if branch + + ref + end end end end |