]> source.dussan.org Git - redmine.git/commitdiff
scm: git: use default branch from HEAD (#10207)
authorToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sun, 12 Feb 2012 06:22:59 +0000 (06:22 +0000)
committerToshi MARUYAMA <marutosijp2@yahoo.co.jp>
Sun, 12 Feb 2012 06:22:59 +0000 (06:22 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@8856 e93f8b46-1217-0410-a6f0-8f06a7374b81

lib/redmine/scm/adapters/git_adapter.rb
test/unit/lib/redmine/scm/adapters/git_adapter_test.rb

index 9639b41f98a06710c2fbd150262ca4d20c051afd..c7bdbe13cc53cefbd126223fe53aa4ae4cb3062d 100644 (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
 
index e9049956a2fcf7d4dbd43a0f6e086d91e84b26be..e9e5b5c60020adf8c363391f3234db10eb2c52a1 100644 (file)
@@ -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
+      end
+
+      def test_default_branch
+        assert_equal 'master-20120212', @adapter.default_branch
       end
 
       def test_tags