@@ -25,6 +25,10 module Redmine | |||||
25 | # Git executable name |
|
25 | # Git executable name | |
26 | GIT_BIN = Redmine::Configuration['scm_git_command'] || "git" |
|
26 | GIT_BIN = Redmine::Configuration['scm_git_command'] || "git" | |
27 |
|
27 | |||
|
28 | class GitBranch < Branch | |||
|
29 | attr_accessor :is_default | |||
|
30 | end | |||
|
31 | ||||
28 | class << self |
|
32 | class << self | |
29 | def client_command |
|
33 | def client_command | |
30 | @@bin ||= GIT_BIN |
|
34 | @@bin ||= GIT_BIN | |
@@ -80,10 +84,11 module Redmine | |||||
80 | cmd_args = %w|branch --no-color --verbose --no-abbrev| |
|
84 | cmd_args = %w|branch --no-color --verbose --no-abbrev| | |
81 | scm_cmd(*cmd_args) do |io| |
|
85 | scm_cmd(*cmd_args) do |io| | |
82 | io.each_line do |line| |
|
86 | io.each_line do |line| | |
83 | branch_rev = line.match('\s*\*?\s*(.*?)\s*([0-9a-f]{40}).*$') |
|
87 | branch_rev = line.match('\s*(\*?)\s*(.*?)\s*([0-9a-f]{40}).*$') | |
84 |
bran = Branch.new(branch_rev[ |
|
88 | bran = GitBranch.new(branch_rev[2]) | |
85 |
bran.revision = branch_rev[ |
|
89 | bran.revision = branch_rev[3] | |
86 |
bran.scmid = branch_rev[ |
|
90 | bran.scmid = branch_rev[3] | |
|
91 | bran.is_default = ( branch_rev[1] == '*' ) | |||
87 | @branches << bran |
|
92 | @branches << bran | |
88 | end |
|
93 | end | |
89 | end |
|
94 | end | |
@@ -105,6 +110,8 module Redmine | |||||
105 | def default_branch |
|
110 | def default_branch | |
106 | bras = self.branches |
|
111 | bras = self.branches | |
107 | return nil if bras.nil? |
|
112 | return nil if bras.nil? | |
|
113 | default_bras = bras.select{|x| x.is_default == true} | |||
|
114 | return default_bras.first if ! default_bras.empty? | |||
108 | bras.include?('master') ? 'master' : bras.first |
|
115 | bras.include?('master') ? 'master' : bras.first | |
109 | end |
|
116 | end | |
110 |
|
117 |
@@ -70,26 +70,36 begin | |||||
70 | assert_equal 'issue-8857', br_issue_8857.to_s |
|
70 | assert_equal 'issue-8857', br_issue_8857.to_s | |
71 | assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision |
|
71 | assert_equal '2a682156a3b6e77a8bf9cd4590e8db757f3c6c78', br_issue_8857.revision | |
72 | assert_equal br_issue_8857.scmid, br_issue_8857.revision |
|
72 | assert_equal br_issue_8857.scmid, br_issue_8857.revision | |
|
73 | assert_equal false, br_issue_8857.is_default | |||
73 | br_latin_1_path = brs[1] |
|
74 | br_latin_1_path = brs[1] | |
74 | assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s |
|
75 | assert_equal 'latin-1-path-encoding', br_latin_1_path.to_s | |
75 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision |
|
76 | assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', br_latin_1_path.revision | |
76 | assert_equal br_latin_1_path.scmid, br_latin_1_path.revision |
|
77 | assert_equal br_latin_1_path.scmid, br_latin_1_path.revision | |
|
78 | assert_equal false, br_latin_1_path.is_default | |||
77 | br_master = brs[2] |
|
79 | br_master = brs[2] | |
78 | assert_equal 'master', br_master.to_s |
|
80 | assert_equal 'master', br_master.to_s | |
79 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision |
|
81 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision | |
80 | assert_equal br_master.scmid, br_master.revision |
|
82 | assert_equal br_master.scmid, br_master.revision | |
|
83 | assert_equal false, br_master.is_default | |||
81 | br_master_20120212 = brs[3] |
|
84 | br_master_20120212 = brs[3] | |
82 | assert_equal 'master-20120212', br_master_20120212.to_s |
|
85 | assert_equal 'master-20120212', br_master_20120212.to_s | |
83 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision |
|
86 | assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master_20120212.revision | |
84 | assert_equal br_master_20120212.scmid, br_master_20120212.revision |
|
87 | assert_equal br_master_20120212.scmid, br_master_20120212.revision | |
|
88 | assert_equal true, br_master_20120212.is_default | |||
85 | br_latin_1 = brs[-2] |
|
89 | br_latin_1 = brs[-2] | |
86 | assert_equal 'test-latin-1', br_latin_1.to_s |
|
90 | assert_equal 'test-latin-1', br_latin_1.to_s | |
87 | assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision |
|
91 | assert_equal '67e7792ce20ccae2e4bb73eed09bb397819c8834', br_latin_1.revision | |
88 | assert_equal br_latin_1.scmid, br_latin_1.revision |
|
92 | assert_equal br_latin_1.scmid, br_latin_1.revision | |
|
93 | assert_equal false, br_latin_1.is_default | |||
89 | br_test = brs[-1] |
|
94 | br_test = brs[-1] | |
90 | assert_equal 'test_branch', br_test.to_s |
|
95 | assert_equal 'test_branch', br_test.to_s | |
91 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision |
|
96 | assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', br_test.revision | |
92 | assert_equal br_test.scmid, br_test.revision |
|
97 | assert_equal br_test.scmid, br_test.revision | |
|
98 | assert_equal false, br_test.is_default | |||
|
99 | end | |||
|
100 | ||||
|
101 | def test_default_branch | |||
|
102 | assert_equal 'master-20120212', @adapter.default_branch | |||
93 | end |
|
103 | end | |
94 |
|
104 | |||
95 | def test_tags |
|
105 | def test_tags |
General Comments 0
You need to be logged in to leave comments.
Login now