Commit 05c2c15cd1672a46e2b31e2ba1e71b872e8993e3

Authored by Sato Hiroyuki
1 parent 963ec234

Fix Gitlab::Git::Repository#commit returns wrong commit, if commit_id is "tag name".

lib/extracts_path.rb
... ... @@ -98,9 +98,7 @@ module ExtractsPath
98 98  
99 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 103 @tree = Tree.new(@project.repository, @commit.id, @ref, @path)
106 104  
... ...
lib/gitlab/git/repository.rb
... ... @@ -49,7 +49,16 @@ module Gitlab
49 49  
50 50 def commit(commit_id = nil)
51 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 62 else
54 63 repo.commits(root_ref).first
55 64 end
... ...