diff --git app/models/repository/git.rb app/models/repository/git.rb index ea3607b..c812f33 100644 --- app/models/repository/git.rb +++ app/models/repository/git.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Redmine - project management software # Copyright (C) 2006-2014 Jean-Philippe Lang # Copyright (C) 2007 Patrick Aljord patcito@ŋmail.com @@ -68,7 +69,13 @@ class Repository::Git < Repository # Returns the readable identifier for the given git changeset def self.format_changeset_identifier(changeset) - changeset.revision[0, 8] + str = changeset.revision[0, 8] + h = changeset.repository.extra_info + unless h.nil? || h['refs'].nil? + ref = h['refs'][changeset.revision.to_s] + str += ' [' + ref.join(', ') + ']' if ref.respond_to?('join') + end + str end def branches @@ -79,6 +86,10 @@ class Repository::Git < Repository scm.tags end + def refs + scm.refs + end + def default_branch scm.default_branch rescue Exception => e @@ -130,6 +141,8 @@ class Repository::Git < Repository def fetch_changesets scm_brs = branches return if scm_brs.nil? || scm_brs.empty? + merge_extra_info('refs' => refs) + self.save h1 = extra_info || {} h = h1.dup diff --git lib/redmine/scm/adapters/git_adapter.rb lib/redmine/scm/adapters/git_adapter.rb index 284a3f4..4337da8 100644 --- lib/redmine/scm/adapters/git_adapter.rb +++ lib/redmine/scm/adapters/git_adapter.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Redmine - project management software # Copyright (C) 2006-2014 Jean-Philippe Lang # @@ -80,30 +81,52 @@ module Redmine def branches return @branches if @branches - @branches = [] - cmd_args = %w|branch --no-color --verbose --no-abbrev| - git_cmd(cmd_args) do |io| - io.each_line do |line| - branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$') - bran = GitBranch.new(branch_rev[2]) - bran.revision = branch_rev[3] - bran.scmid = branch_rev[3] - bran.is_default = ( branch_rev[1] == '*' ) - @branches << bran - end - end - @branches.sort! - rescue ScmCommandAborted - nil + refs + @branches end def tags return @tags if @tags - cmd_args = %w|tag| + refs + @tags + end + + def refs + return @refs if @refs + cmd_args = %w|show-ref --head --tags --heads --dereference| git_cmd(cmd_args) do |io| - @tags = io.readlines.sort!.map{|t| t.strip} + head = nil + @refs = {} + @branches = [] + @tags = [] + io.each do |line| + rev,ref = line.split + if m = ref.match(%r|^HEAD$|) + head = rev + elsif m = ref.match(%r|^refs/heads/(.*)|) + @refs[rev] ||= [] + @refs[rev] << m[1] + b = GitBranch.new(m[1]) + b.revision = rev + b.scmid = rev + b.is_default = false + @branches << b + elsif m = ref.match(%r|^refs/tags/(.*)\^{}$|) + @refs[rev] ||= [] + @refs[rev] << "tag: #{m[1]}" + @tags << m[1] + end + end + @branches.sort!.map!{ |b| + b.is_default = true if b.revision == head + b + } + @tags.sort! end + @refs rescue ScmCommandAborted + @branches = nil + @tags = nil nil end