Skip to content

Commit

Permalink
scm: git: add methods of getting git version and add unit lib test (#…
Browse files Browse the repository at this point in the history
…4273).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@4829 e93f8b46-1217-0410-a6f0-8f06a7374b81
  • Loading branch information
marutosi committed Feb 15, 2011
1 parent e3b3152 commit 4f1b1d9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lib/redmine/scm/adapters/git_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,24 @@ def sq_bin
@@sq_bin ||= shell_quote(GIT_BIN)
end

def client_version
@@client_version ||= (scm_command_version || [])
end

def client_available
!client_version.empty?
end

def scm_command_version
scm_version = scm_version_from_command_line
if m = scm_version.match(%r{\A(.*?)((\d+\.)+\d+)})
m[2].scan(%r{\d+}).collect(&:to_i)
end
end

def scm_version_from_command_line
shellout("#{sq_bin} --version") { |io| io.read }.to_s
end
end

def info
Expand Down
17 changes: 17 additions & 0 deletions test/unit/lib/redmine/scm/adapters/git_adapter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,15 @@ def setup
@adapter = Redmine::Scm::Adapters::GitAdapter.new(REPOSITORY_PATH)
end

def test_scm_version
to_test = { "git version 1.7.3.4\n" => [1,7,3,4],
"1.6.1\n1.7\n1.8" => [1,6,1],
"1.6.2\r\n1.8.1\r\n1.9.1" => [1,6,2]}
to_test.each do |s, v|
test_scm_version_for(s, v)
end
end

def test_branches
assert_equal @adapter.branches, ['master', 'test_branch']
end
Expand Down Expand Up @@ -78,6 +87,14 @@ def test_last_rev_with_spaces_in_filename
last_rev.author
assert_equal "2010-09-18 19:59:46".to_time, last_rev.time
end

private

def test_scm_version_for(scm_command_version, version)
@adapter.class.expects(:scm_version_from_command_line).returns(scm_command_version)
assert_equal version, @adapter.class.scm_command_version
end

else
puts "Git test repository NOT FOUND. Skipping unit tests !!!"
def test_fake; assert true end
Expand Down

0 comments on commit 4f1b1d9

Please sign in to comment.