Commit 05c2c15cd1672a46e2b31e2ba1e71b872e8993e3
1 parent
963ec234
Exists in
master
and in
4 other branches
Fix Gitlab::Git::Repository#commit returns wrong commit, if commit_id is "tag name".
Showing
2 changed files
with
11 additions
and
4 deletions
Show diff stats
lib/extracts_path.rb
@@ -98,9 +98,7 @@ module ExtractsPath | @@ -98,9 +98,7 @@ module ExtractsPath | ||
98 | 98 | ||
99 | @ref, @path = extract_ref(@id) | 99 | @ref, @path = extract_ref(@id) |
100 | 100 | ||
101 | - # It is used "@project.repository.commits(@ref, @path, 1, 0)", | ||
102 | - # because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name. | ||
103 | - @commit = @project.repository.commits(@ref, @path, 1, 0).first | 101 | + @commit = @project.repository.commit(@ref) |
104 | 102 | ||
105 | @tree = Tree.new(@project.repository, @commit.id, @ref, @path) | 103 | @tree = Tree.new(@project.repository, @commit.id, @ref, @path) |
106 | 104 |
lib/gitlab/git/repository.rb
@@ -49,7 +49,16 @@ module Gitlab | @@ -49,7 +49,16 @@ module Gitlab | ||
49 | 49 | ||
50 | def commit(commit_id = nil) | 50 | def commit(commit_id = nil) |
51 | commit = if commit_id | 51 | commit = if commit_id |
52 | - repo.commit(commit_id) | 52 | + # Find repo.refs first, |
53 | + # because if commit_id is "tag name", | ||
54 | + # repo.commit(commit_id) returns wrong commit sha | ||
55 | + # that is git tag object sha. | ||
56 | + ref = repo.refs.find {|r| r.name == commit_id} | ||
57 | + if ref | ||
58 | + ref.commit | ||
59 | + else | ||
60 | + repo.commit(commit_id) | ||
61 | + end | ||
53 | else | 62 | else |
54 | repo.commits(root_ref).first | 63 | repo.commits(root_ref).first |
55 | end | 64 | end |