Commit a62195fe authored by tmaruyama's avatar tmaruyama
Browse files

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

git-svn-id: e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 845a851f
......@@ -25,6 +25,10 @@ module Redmine
# Git executable name
GIT_BIN = Redmine::Configuration['scm_git_command'] || "git"
class GitBranch < Branch
attr_accessor :is_default
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 =[1])
bran.revision = branch_rev[2]
bran.scmid = branch_rev[2]
branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$')
bran =[2])
bran.revision = branch_rev[3]
bran.scmid = branch_rev[3]
bran.is_default = ( branch_rev[1] == '*' )
@branches << bran
......@@ -105,6 +110,8 @@ module Redmine
def default_branch
bras = self.branches
return nil if bras.nil?
default_bras ={|x| x.is_default == true}
return default_bras.first if ! default_bras.empty?
bras.include?('master') ? 'master' : bras.first
......@@ -70,26 +70,36 @@ begin
assert_equal 'issue-8857', br_issue_8857.to_s
assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision
assert_equal br_issue_8857.scmid, br_issue_8857.revision
assert_equal false, br_issue_8857.is_default
br_latin_1_path = brs[1]
assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision
assert_equal br_latin_1_path.scmid, br_latin_1_path.revision
assert_equal false, br_latin_1_path.is_default
br_master = brs[2]
assert_equal 'master', br_master.to_s
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision
assert_equal br_master.scmid, br_master.revision
assert_equal false, br_master.is_default
br_master_20120212 = brs[3]
assert_equal 'master-20120212', br_master_20120212.to_s
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision
assert_equal br_master_20120212.scmid, br_master_20120212.revision
assert_equal true, br_master_20120212.is_default
br_latin_1 = brs[-2]
assert_equal 'test-latin-1', br_latin_1.to_s
assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision
assert_equal br_latin_1.scmid, br_latin_1.revision
assert_equal false, br_latin_1.is_default
br_test = brs[-1]
assert_equal 'test_branch', br_test.to_s
assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision
assert_equal br_test.scmid, br_test.revision
assert_equal false, br_test.is_default
def test_default_branch
assert_equal 'master-20120212', @adapter.default_branch
def test_tags
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment