Commit 1722e96b authored by Justin Geibel's avatar Justin Geibel Committed by Felix Schäfer

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.
parent 4956e9ca
......@@ -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
......
......@@ -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)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment