diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-06 13:41:41 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-06 13:41:41 +0000 |
commit | c052cc60d2d816fd6506cc6fdacb680cfef85a2c (patch) | |
tree | fe18cab61222404b8d598bbd4023f772dd5e762a /lib/gitlab | |
parent | ae06966da16860568740fd607fdf98377fcada81 (diff) | |
download | gitlab-ce-c052cc60d2d816fd6506cc6fdacb680cfef85a2c.tar.gz |
Add latest changes from gitlab-org/gitlab@15-10-stable-ee
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/git/repository.rb | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index 95633400aee..40cb4521f6a 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -262,7 +262,15 @@ 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) + + if Feature.enabled?(:resolve_ambiguous_archives, container) + commit_id = extract_commit_id_from_ref(ref) + return {} if commit_id.nil? + else + commit_id = ref + end + + 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) @@ -1223,6 +1231,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 |