scm: git: use default branch from HEAD (#10207)

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8856 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Toshi MARUYAMA
2012-02-12 06:22:59 +00:00
parent 804482ef2b
commit 2fa19441a7
2 changed files with 21 additions and 4 deletions
+11 -4
View File
@@ -25,6 +25,10 @@ module Redmine
# Git executable name
GIT_BIN = Redmine::Configuration['scm_git_command'] || "git"
class GitBranch < Branch
attr_accessor :is_default
end
class << self
def client_command
@@bin ||= GIT_BIN
@@ -80,10 +84,11 @@ module Redmine
cmd_args = %w|branch --no-color --verbose --no-abbrev|
scm_cmd(*cmd_args) do |io|
io.each_line do |line|
branch_rev = line.match('\s*\*?\s*(.*?)\s*([0-9a-f]{40}).*$')
bran = Branch.new(branch_rev[1])
bran.revision = branch_rev[2]
bran.scmid = branch_rev[2]
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
@@ -105,6 +110,8 @@ module Redmine
def default_branch
bras = self.branches
return nil if bras.nil?
default_bras = bras.select{|x| x.is_default == true}
return default_bras.first if ! default_bras.empty?
bras.include?('master') ? 'master' : bras.first
end