diff options
author | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2012-02-12 06:22:59 +0000 |
---|---|---|
committer | Toshi MARUYAMA <marutosijp2@yahoo.co.jp> | 2012-02-12 06:22:59 +0000 |
commit | 2fa19441a7ffbbc77da403a9a6d7a384756913cb (patch) | |
tree | 7b0ee4304563f2e81be5495e9bfacd9cad0bc9ce /lib | |
parent | 804482ef2b5e36cb474bc3b8e10e52ab19ca0d21 (diff) | |
download | redmine-2fa19441a7ffbbc77da403a9a6d7a384756913cb.tar.gz redmine-2fa19441a7ffbbc77da403a9a6d7a384756913cb.zip |
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
Diffstat (limited to 'lib')
-rw-r--r-- | lib/redmine/scm/adapters/git_adapter.rb | 15 |
1 files changed, 11 insertions, 4 deletions
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 |