# 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
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
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
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
+ end
+
+ def test_default_branch
+ assert_equal 'master-20120212', @adapter.default_branch
end
def test_tags