Change default branch behaviour for git repos #749

If git repository HEAD points to a branch, use that as the default branch.
Otherwise fall back to previous method.
This commit is contained in:
Justin Geibel 2011-12-03 17:01:01 -05:00 committed by Felix Schäfer
parent 4956e9ca93
commit 1722e96bb0
2 changed files with 14 additions and 0 deletions

View File

@ -100,6 +100,13 @@ module Redmine
def default_branch
bras = self.branches
return nil if bras.nil?
head = nil
scm_cmd('symbolic-ref', 'HEAD') do |io|
head = io.readline
end
/^refs\/heads\/(.*)$/.match(head)
bras.include?($1) ? $1 : bras.first
rescue ScmCommandAborted, EOFError
bras.include?('master') ? 'master' : bras.first
end

View File

@ -231,6 +231,13 @@ begin
end
end
def test_default_branch
@adapter.send :scm_cmd, 'branch', '-m', 'master', 'non-master-default-branch'
assert_equal 'non-master-default-branch', @adapter.default_branch
ensure
@adapter.send :scm_cmd, 'branch', '-m', 'non-master-default-branch', 'master'
end
private
def test_scm_version_for(scm_command_version, version)