From 05c2c15cd1672a46e2b31e2ba1e71b872e8993e3 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki <sathiroyuki@gmail.com> Date: Thu, 25 Apr 2013 19:58:25 +0000 Subject: [PATCH] Fix Gitlab::Git::Repository#commit returns wrong commit, if commit_id is "tag name". --- lib/extracts_path.rb | 4 +--- lib/gitlab/git/repository.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 009c5fcada..1b7c698d0a 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -98,9 +98,7 @@ module ExtractsPath @ref, @path = extract_ref(@id) - # It is used "@project.repository.commits(@ref, @path, 1, 0)", - # because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name. - @commit = @project.repository.commits(@ref, @path, 1, 0).first + @commit = @project.repository.commit(@ref) @tree = Tree.new(@project.repository, @commit.id, @ref, @path) diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb index ddead51d44..0218f2fe0e 100644 --- a/lib/gitlab/git/repository.rb +++ b/lib/gitlab/git/repository.rb @@ -49,7 +49,16 @@ module Gitlab def commit(commit_id = nil) commit = if commit_id - repo.commit(commit_id) + # Find repo.refs first, + # because if commit_id is "tag name", + # repo.commit(commit_id) returns wrong commit sha + # that is git tag object sha. + ref = repo.refs.find {|r| r.name == commit_id} + if ref + ref.commit + else + repo.commit(commit_id) + end else repo.commits(root_ref).first end -- 2.30.9