From 2fa19441a7ffbbc77da403a9a6d7a384756913cb Mon Sep 17 00:00:00 2001 From: Toshi MARUYAMA Date: Sun, 12 Feb 2012 06:22:59 +0000 Subject: 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 --- lib/redmine/scm/adapters/git_adapter.rb | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'lib') diff --git a/lib/redmine/scm/adapters/git_adapter.rb b/lib/redmine/scm/adapters/git_adapter.rb index 9639b41f9..c7bdbe13c 100644 --- a/lib/redmine/scm/adapters/git_adapter.rb +++ b/lib/redmine/scm/adapters/git_adapter.rb @@ -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 -- cgit v1.2.3