2012-09-15 01:40:45 +04:00
|
|
|
# Redmine - project management software
|
2014-01-30 02:45:39 +04:00
|
|
|
# Copyright (C) 2006-2014 Jean-Philippe Lang
|
2012-09-15 01:40:45 +04:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2010-12-13 02:24:45 +03:00
|
|
|
|
2010-12-13 02:24:34 +03:00
|
|
|
require File.expand_path('../../../../../../test_helper', __FILE__)
|
2011-02-11 18:30:22 +03:00
|
|
|
begin
|
2013-05-21 16:57:11 +04:00
|
|
|
require 'mocha/setup'
|
2009-08-16 02:41:40 +04:00
|
|
|
|
2011-02-11 18:30:22 +03:00
|
|
|
class GitAdapterTest < ActiveSupport::TestCase
|
2011-06-10 07:30:19 +04:00
|
|
|
REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
|
2009-08-16 02:41:40 +04:00
|
|
|
|
2011-02-22 03:40:02 +03:00
|
|
|
FELIX_HEX = "Felix Sch\xC3\xA4fer"
|
2011-03-08 09:10:07 +03:00
|
|
|
CHAR_1_HEX = "\xc3\x9c"
|
2011-02-22 03:40:02 +03:00
|
|
|
|
2011-06-08 14:05:40 +04:00
|
|
|
## Git, Mercurial and CVS path encodings are binary.
|
|
|
|
## Subversion supports URL encoding for path.
|
|
|
|
## Redmine Mercurial adapter and extension use URL encoding.
|
|
|
|
## Git accepts only binary path in command line parameter.
|
|
|
|
## So, there is no way to use binary command line parameter in JRuby.
|
|
|
|
JRUBY_SKIP = (RUBY_PLATFORM == 'java')
|
|
|
|
JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
|
|
|
|
|
2011-02-11 18:30:22 +03:00
|
|
|
if File.directory?(REPOSITORY_PATH)
|
2012-06-19 03:57:27 +04:00
|
|
|
## Ruby uses ANSI api to fork a process on Windows.
|
|
|
|
## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
|
|
|
|
## and these are incompatible with ASCII.
|
|
|
|
## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
|
|
|
|
## http://code.google.com/p/msysgit/issues/detail?id=80
|
|
|
|
## So, Latin-1 path tests fail on Japanese Windows
|
|
|
|
WINDOWS_PASS = (Redmine::Platform.mswin? &&
|
|
|
|
Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
|
|
|
|
WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
|
|
|
|
|
2011-02-11 18:30:22 +03:00
|
|
|
def setup
|
2011-04-08 08:52:26 +04:00
|
|
|
adapter_class = Redmine::Scm::Adapters::GitAdapter
|
|
|
|
assert adapter_class
|
|
|
|
assert adapter_class.client_command
|
|
|
|
assert_equal true, adapter_class.client_available
|
|
|
|
assert_equal true, adapter_class.client_version_above?([1])
|
|
|
|
assert_equal true, adapter_class.client_version_above?([1, 0])
|
|
|
|
|
2011-03-08 09:10:07 +03:00
|
|
|
@adapter = Redmine::Scm::Adapters::GitAdapter.new(
|
|
|
|
REPOSITORY_PATH,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
'ISO-8859-1'
|
2012-02-08 07:03:39 +04:00
|
|
|
)
|
2011-03-08 09:10:07 +03:00
|
|
|
assert @adapter
|
2012-02-08 07:03:39 +04:00
|
|
|
@char_1 = CHAR_1_HEX.dup
|
2013-09-18 10:16:43 +04:00
|
|
|
@str_felix_hex = FELIX_HEX.dup
|
2011-03-08 09:10:07 +03:00
|
|
|
if @char_1.respond_to?(:force_encoding)
|
|
|
|
@char_1.force_encoding('UTF-8')
|
2013-09-18 10:16:43 +04:00
|
|
|
@str_felix_hex.force_encoding('ASCII-8BIT')
|
2011-03-08 09:10:07 +03:00
|
|
|
end
|
2011-02-11 18:30:22 +03:00
|
|
|
end
|
2009-08-16 02:41:40 +04:00
|
|
|
|
2011-02-15 08:58:31 +03:00
|
|
|
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
|
|
|
|
|
2011-02-11 18:30:22 +03:00
|
|
|
def test_branches
|
2011-10-28 09:18:28 +04:00
|
|
|
brs = []
|
|
|
|
@adapter.branches.each do |b|
|
|
|
|
brs << b
|
|
|
|
end
|
2012-02-12 10:22:33 +04:00
|
|
|
assert_equal 6, brs.length
|
|
|
|
br_issue_8857 = brs[0]
|
2012-02-09 12:20:37 +04:00
|
|
|
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
|
2012-02-12 10:22:59 +04:00
|
|
|
assert_equal false, br_issue_8857.is_default
|
2012-02-12 10:22:33 +04:00
|
|
|
br_latin_1_path = brs[1]
|
2012-02-09 10:43:42 +04:00
|
|
|
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
|
2012-02-12 10:22:59 +04:00
|
|
|
assert_equal false, br_latin_1_path.is_default
|
2012-02-12 10:22:33 +04:00
|
|
|
br_master = brs[2]
|
2012-02-09 10:43:42 +04:00
|
|
|
assert_equal 'master', br_master.to_s
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', br_master.revision
|
|
|
|
assert_equal br_master.scmid, br_master.revision
|
2012-02-12 10:22:59 +04:00
|
|
|
assert_equal false, br_master.is_default
|
2012-02-12 10:22:33 +04:00
|
|
|
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
|
2012-02-12 10:22:59 +04:00
|
|
|
assert_equal true, br_master_20120212.is_default
|
2012-02-09 10:43:42 +04:00
|
|
|
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
|
2012-02-12 10:22:59 +04:00
|
|
|
assert_equal false, br_latin_1.is_default
|
2012-02-09 10:43:42 +04:00
|
|
|
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
|
2012-02-12 10:22:59 +04:00
|
|
|
assert_equal false, br_test.is_default
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_default_branch
|
|
|
|
assert_equal 'master-20120212', @adapter.default_branch
|
2011-02-11 18:30:22 +03:00
|
|
|
end
|
2009-08-16 02:41:40 +04:00
|
|
|
|
2011-03-08 09:10:30 +03:00
|
|
|
def test_tags
|
|
|
|
assert_equal [
|
|
|
|
"tag00.lightweight",
|
|
|
|
"tag01.annotated",
|
|
|
|
], @adapter.tags
|
|
|
|
end
|
|
|
|
|
2011-05-12 16:09:17 +04:00
|
|
|
def test_revisions_master_all
|
2011-05-13 12:27:04 +04:00
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, "master",{}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
2011-05-06 15:45:58 +04:00
|
|
|
assert_equal 15, revs1.length
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 0].identifier
|
|
|
|
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
|
|
|
|
|
2011-05-13 12:27:04 +04:00
|
|
|
revs2 = []
|
|
|
|
@adapter.revisions('', nil, "master",
|
2012-02-08 07:03:39 +04:00
|
|
|
{:reverse => true}) do |rev|
|
2011-05-13 12:27:04 +04:00
|
|
|
revs2 << rev
|
|
|
|
end
|
2011-05-06 15:45:58 +04:00
|
|
|
assert_equal 15, revs2.length
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
|
|
|
|
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
|
|
|
|
end
|
|
|
|
|
2011-05-12 17:00:43 +04:00
|
|
|
def test_revisions_master_merged_rev
|
2011-05-13 12:27:35 +04:00
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('',
|
|
|
|
"713f4944648826f558cf548222f813dabe7cbb04",
|
|
|
|
"master",
|
|
|
|
{:reverse => true}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
2011-05-12 17:00:43 +04:00
|
|
|
assert_equal 8, revs1.length
|
|
|
|
assert_equal 'fba357b886984ee71185ad2065e65fc0417d9b92', revs1[ 0].identifier
|
|
|
|
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 1].identifier
|
|
|
|
# 4a07fe31b is not a child of 713f49446
|
|
|
|
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 2].identifier
|
|
|
|
# Merged revision
|
|
|
|
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 3].identifier
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
|
2011-05-12 17:01:10 +04:00
|
|
|
|
2011-05-13 12:27:35 +04:00
|
|
|
revs2 = []
|
|
|
|
@adapter.revisions('',
|
|
|
|
"fba357b886984ee71185ad2065e65fc0417d9b92",
|
|
|
|
"master",
|
|
|
|
{:reverse => true}) do |rev|
|
|
|
|
revs2 << rev
|
|
|
|
end
|
2011-05-12 17:01:10 +04:00
|
|
|
assert_equal 7, revs2.length
|
|
|
|
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs2[ 0].identifier
|
|
|
|
# 4a07fe31b is not a child of fba357b8869
|
|
|
|
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs2[ 1].identifier
|
|
|
|
# Merged revision
|
|
|
|
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs2[ 2].identifier
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs2[-1].identifier
|
2011-05-12 17:00:43 +04:00
|
|
|
end
|
|
|
|
|
2011-05-12 16:09:42 +04:00
|
|
|
def test_revisions_branch_latin_1_path_encoding_all
|
2011-05-13 12:28:03 +04:00
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, "latin-1-path-encoding",{}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
2011-05-12 16:09:42 +04:00
|
|
|
assert_equal 8, revs1.length
|
|
|
|
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[ 0].identifier
|
|
|
|
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[-1].identifier
|
|
|
|
|
2011-05-13 12:28:03 +04:00
|
|
|
revs2 = []
|
|
|
|
@adapter.revisions('', nil, "latin-1-path-encoding",
|
2012-02-08 07:03:39 +04:00
|
|
|
{:reverse => true}) do |rev|
|
2011-05-13 12:28:03 +04:00
|
|
|
revs2 << rev
|
|
|
|
end
|
2011-05-12 16:09:42 +04:00
|
|
|
assert_equal 8, revs2.length
|
|
|
|
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
|
|
|
|
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs2[ 0].identifier
|
|
|
|
end
|
|
|
|
|
2011-05-12 16:11:44 +04:00
|
|
|
def test_revisions_branch_latin_1_path_encoding_with_rev
|
2011-05-13 12:28:30 +04:00
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('',
|
|
|
|
'7234cb2750b63f47bff735edc50a1c0a433c2518',
|
|
|
|
"latin-1-path-encoding",
|
|
|
|
{:reverse => true}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
2011-05-12 16:11:44 +04:00
|
|
|
assert_equal 7, revs1.length
|
|
|
|
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 0].identifier
|
|
|
|
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
|
|
|
|
|
2011-05-13 12:28:30 +04:00
|
|
|
revs2 = []
|
|
|
|
@adapter.revisions('',
|
|
|
|
'57ca437c0acbbcb749821fdf3726a1367056d364',
|
|
|
|
"latin-1-path-encoding",
|
|
|
|
{:reverse => true}) do |rev|
|
|
|
|
revs2 << rev
|
|
|
|
end
|
2011-05-12 16:11:44 +04:00
|
|
|
assert_equal 3, revs2.length
|
|
|
|
assert_equal '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', revs2[ 0].identifier
|
|
|
|
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs2[-1].identifier
|
|
|
|
end
|
|
|
|
|
2011-05-13 03:45:04 +04:00
|
|
|
def test_revisions_invalid_rev
|
2012-02-11 02:56:54 +04:00
|
|
|
assert_equal [], @adapter.revisions('', '1234abcd', "master")
|
|
|
|
assert_raise Redmine::Scm::Adapters::CommandFailed do
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('',
|
2012-02-08 07:03:39 +04:00
|
|
|
'1234abcd',
|
|
|
|
"master",
|
|
|
|
{:reverse => true}) do |rev|
|
2012-02-11 02:56:54 +04:00
|
|
|
revs1 << rev
|
|
|
|
end
|
2011-05-13 12:28:51 +04:00
|
|
|
end
|
2011-05-13 03:45:04 +04:00
|
|
|
end
|
|
|
|
|
2012-02-09 03:38:35 +04:00
|
|
|
def test_revisions_includes_master_two_revs
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, nil,
|
|
|
|
{:reverse => true,
|
|
|
|
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
|
|
|
|
:excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43']}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
|
|
|
assert_equal 2, revs1.length
|
|
|
|
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
|
|
|
|
end
|
|
|
|
|
2012-02-09 10:05:10 +04:00
|
|
|
def test_revisions_includes_master_two_revs_from_origin
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, nil,
|
|
|
|
{:reverse => true,
|
2012-02-09 19:07:11 +04:00
|
|
|
:includes => ['899a15dba03a3b350b89c3f537e4bbe02a03cdc9'],
|
|
|
|
:excludes => []}) do |rev|
|
2012-02-09 10:05:10 +04:00
|
|
|
revs1 << rev
|
|
|
|
end
|
|
|
|
assert_equal 2, revs1.length
|
|
|
|
assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', revs1[ 0].identifier
|
|
|
|
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', revs1[ 1].identifier
|
|
|
|
end
|
|
|
|
|
2012-02-09 03:38:35 +04:00
|
|
|
def test_revisions_includes_merged_revs
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, nil,
|
|
|
|
{:reverse => true,
|
|
|
|
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
|
|
|
|
:excludes => ['fba357b886984ee71185ad2065e65fc0417d9b92']}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
|
|
|
assert_equal 7, revs1.length
|
|
|
|
assert_equal '7e61ac704deecde634b51e59daa8110435dcb3da', revs1[ 0].identifier
|
|
|
|
assert_equal '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', revs1[ 1].identifier
|
|
|
|
assert_equal '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', revs1[ 2].identifier
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[-1].identifier
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_revisions_includes_two_heads
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, nil,
|
|
|
|
{:reverse => true,
|
|
|
|
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c',
|
|
|
|
'1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127'],
|
|
|
|
:excludes => ['4f26664364207fa8b1af9f8722647ab2d4ac5d43',
|
|
|
|
'4fc55c43bf3d3dc2efb66145365ddc17639ce81e']}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
|
|
|
assert_equal 4, revs1.length
|
|
|
|
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
|
|
|
|
assert_equal '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', revs1[-2].identifier
|
|
|
|
assert_equal '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127', revs1[-1].identifier
|
|
|
|
end
|
|
|
|
|
2012-02-09 12:34:24 +04:00
|
|
|
def test_revisions_disjointed_histories_revisions
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, nil,
|
|
|
|
{:reverse => true,
|
|
|
|
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c',
|
|
|
|
'92397af84d22f27389c822848ecd5b463c181583'],
|
|
|
|
:excludes => ['95488a44bc25f7d1f97d775a31359539ff333a63',
|
|
|
|
'4f26664364207fa8b1af9f8722647ab2d4ac5d43'] }) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
|
|
|
assert_equal 4, revs1.length
|
|
|
|
assert_equal 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b', revs1[ 0].identifier
|
|
|
|
assert_equal '83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', revs1[ 1].identifier
|
|
|
|
assert_equal 'bc201c95999c4f10d018b0aa03b541cd6a2ff0ee', revs1[-2].identifier
|
|
|
|
assert_equal '92397af84d22f27389c822848ecd5b463c181583', revs1[-1].identifier
|
|
|
|
end
|
|
|
|
|
2012-02-09 03:38:35 +04:00
|
|
|
def test_revisions_invalid_rev_excludes
|
2012-02-11 02:56:54 +04:00
|
|
|
assert_equal [],
|
|
|
|
@adapter.revisions('', nil, nil,
|
|
|
|
{:reverse => true,
|
|
|
|
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
|
|
|
|
:excludes => ['0123abcd4567']})
|
|
|
|
assert_raise Redmine::Scm::Adapters::CommandFailed do
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('', nil, nil,
|
|
|
|
{:reverse => true,
|
|
|
|
:includes => ['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c'],
|
|
|
|
:excludes => ['0123abcd4567']}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
2012-02-09 03:38:35 +04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-02-11 18:30:22 +03:00
|
|
|
def test_getting_revisions_with_spaces_in_filename
|
|
|
|
assert_equal 1, @adapter.revisions("filemane with spaces.txt",
|
2012-02-08 07:04:03 +04:00
|
|
|
nil, "master").length
|
2011-02-11 18:30:22 +03:00
|
|
|
end
|
|
|
|
|
2011-10-28 08:59:06 +04:00
|
|
|
def test_parents
|
|
|
|
revs1 = []
|
|
|
|
@adapter.revisions('',
|
|
|
|
nil,
|
|
|
|
"master",
|
|
|
|
{:reverse => true}) do |rev|
|
|
|
|
revs1 << rev
|
|
|
|
end
|
|
|
|
assert_equal 15, revs1.length
|
|
|
|
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
|
|
|
|
revs1[0].identifier
|
|
|
|
assert_equal nil, revs1[0].parents
|
|
|
|
assert_equal "899a15dba03a3b350b89c3f537e4bbe02a03cdc9",
|
|
|
|
revs1[1].identifier
|
|
|
|
assert_equal 1, revs1[1].parents.length
|
|
|
|
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
|
|
|
|
revs1[1].parents[0]
|
|
|
|
assert_equal "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
|
|
|
|
revs1[10].identifier
|
|
|
|
assert_equal 2, revs1[10].parents.length
|
|
|
|
assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8",
|
|
|
|
revs1[10].parents[0]
|
|
|
|
assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da",
|
|
|
|
revs1[10].parents[1]
|
|
|
|
end
|
|
|
|
|
2011-02-11 18:30:22 +03:00
|
|
|
def test_getting_revisions_with_leading_and_trailing_spaces_in_filename
|
|
|
|
assert_equal " filename with a leading space.txt ",
|
|
|
|
@adapter.revisions(" filename with a leading space.txt ",
|
2012-02-08 07:04:03 +04:00
|
|
|
nil, "master")[0].paths[0][:path]
|
2011-02-11 18:30:22 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_getting_entries_with_leading_and_trailing_spaces_in_filename
|
|
|
|
assert_equal " filename with a leading space.txt ",
|
|
|
|
@adapter.entries('',
|
|
|
|
'83ca5fd546063a3c7dc2e568ba3355661a9e2b2c')[3].name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_annotate
|
|
|
|
annotate = @adapter.annotate('sources/watchers_controller.rb')
|
|
|
|
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
|
|
|
|
assert_equal 41, annotate.lines.size
|
2011-03-08 18:05:41 +03:00
|
|
|
assert_equal "# This program is free software; you can redistribute it and/or",
|
|
|
|
annotate.lines[4].strip
|
2011-02-11 18:30:22 +03:00
|
|
|
assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
|
|
|
|
annotate.revisions[4].identifier
|
|
|
|
assert_equal "jsmith", annotate.revisions[4].author
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_annotate_moved_file
|
|
|
|
annotate = @adapter.annotate('renamed_test.txt')
|
|
|
|
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
|
|
|
|
assert_equal 2, annotate.lines.size
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_last_rev
|
|
|
|
last_rev = @adapter.lastrev("README",
|
|
|
|
"4f26664364207fa8b1af9f8722647ab2d4ac5d43")
|
|
|
|
assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.scmid
|
|
|
|
assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", last_rev.identifier
|
|
|
|
assert_equal "Adam Soltys <asoltys@gmail.com>", last_rev.author
|
2014-02-14 09:05:24 +04:00
|
|
|
assert_equal Time.gm(2009, 6, 24, 5, 27, 38), last_rev.time
|
2011-02-11 18:30:22 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_last_rev_with_spaces_in_filename
|
|
|
|
last_rev = @adapter.lastrev("filemane with spaces.txt",
|
|
|
|
"ed5bb786bbda2dee66a2d50faf51429dbc043a7b")
|
2011-02-22 03:40:02 +03:00
|
|
|
last_rev_author = last_rev.author
|
2011-02-11 18:30:22 +03:00
|
|
|
assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.scmid
|
|
|
|
assert_equal "ed5bb786bbda2dee66a2d50faf51429dbc043a7b", last_rev.identifier
|
2013-09-18 10:16:43 +04:00
|
|
|
assert_equal "#{@str_felix_hex} <felix@fachschaften.org>",
|
2011-02-11 18:30:22 +03:00
|
|
|
last_rev.author
|
2014-02-14 09:05:24 +04:00
|
|
|
assert_equal Time.gm(2010, 9, 18, 19, 59, 46), last_rev.time
|
2011-02-11 18:30:22 +03:00
|
|
|
end
|
2011-02-15 08:58:31 +03:00
|
|
|
|
2011-03-08 09:10:07 +03:00
|
|
|
def test_latin_1_path
|
2011-03-09 07:13:58 +03:00
|
|
|
if WINDOWS_PASS
|
2012-06-02 22:36:23 +04:00
|
|
|
puts WINDOWS_SKIP_STR
|
2011-06-08 14:05:40 +04:00
|
|
|
elsif JRUBY_SKIP
|
|
|
|
puts JRUBY_SKIP_STR
|
2011-03-08 09:10:07 +03:00
|
|
|
else
|
|
|
|
p2 = "latin-1-dir/test-#{@char_1}-2.txt"
|
|
|
|
['4fc55c43bf3d3dc2efb66145365ddc17639ce81e', '4fc55c43bf3'].each do |r1|
|
|
|
|
assert @adapter.diff(p2, r1)
|
|
|
|
assert @adapter.cat(p2, r1)
|
|
|
|
assert_equal 1, @adapter.annotate(p2, r1).lines.length
|
|
|
|
['64f1f3e89ad1cb57976ff0ad99a107012ba3481d', '64f1f3e89ad1cb5797'].each do |r2|
|
|
|
|
assert @adapter.diff(p2, r1, r2)
|
2011-05-06 06:06:08 +04:00
|
|
|
end
|
|
|
|
end
|
2011-03-08 09:10:07 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-09-18 10:16:55 +04:00
|
|
|
def test_latin_1_user_annotate
|
|
|
|
['83ca5fd546063a3c7dc2e568ba3355661a9e2b2c', '83ca5fd546063a'].each do |r1|
|
|
|
|
annotate = @adapter.annotate(" filename with a leading space.txt ", r1)
|
|
|
|
assert_kind_of Redmine::Scm::Adapters::Annotate, annotate
|
|
|
|
assert_equal 1, annotate.lines.size
|
|
|
|
assert_equal "And this is a file with a leading and trailing space...",
|
|
|
|
annotate.lines[0].strip
|
|
|
|
assert_equal "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
|
|
|
|
annotate.revisions[0].identifier
|
|
|
|
assert_equal @str_felix_hex, annotate.revisions[0].author
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-03-08 09:37:18 +03:00
|
|
|
def test_entries_tag
|
2011-05-05 15:42:24 +04:00
|
|
|
entries1 = @adapter.entries(nil, 'tag01.annotated',
|
|
|
|
options = {:report_last_commit => true})
|
2011-03-08 09:37:18 +03:00
|
|
|
assert entries1
|
|
|
|
assert_equal 3, entries1.size
|
|
|
|
assert_equal 'sources', entries1[1].name
|
|
|
|
assert_equal 'sources', entries1[1].path
|
|
|
|
assert_equal 'dir', entries1[1].kind
|
|
|
|
readme = entries1[2]
|
|
|
|
assert_equal 'README', readme.name
|
|
|
|
assert_equal 'README', readme.path
|
|
|
|
assert_equal 'file', readme.kind
|
|
|
|
assert_equal 27, readme.size
|
|
|
|
assert_equal '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', readme.lastrev.identifier
|
|
|
|
assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time
|
|
|
|
end
|
|
|
|
|
2011-03-08 09:37:39 +03:00
|
|
|
def test_entries_branch
|
2011-05-05 15:42:24 +04:00
|
|
|
entries1 = @adapter.entries(nil, 'test_branch',
|
|
|
|
options = {:report_last_commit => true})
|
2011-03-08 09:37:39 +03:00
|
|
|
assert entries1
|
|
|
|
assert_equal 4, entries1.size
|
|
|
|
assert_equal 'sources', entries1[1].name
|
|
|
|
assert_equal 'sources', entries1[1].path
|
|
|
|
assert_equal 'dir', entries1[1].kind
|
|
|
|
readme = entries1[2]
|
|
|
|
assert_equal 'README', readme.name
|
|
|
|
assert_equal 'README', readme.path
|
|
|
|
assert_equal 'file', readme.kind
|
|
|
|
assert_equal 159, readme.size
|
|
|
|
assert_equal '713f4944648826f558cf548222f813dabe7cbb04', readme.lastrev.identifier
|
|
|
|
assert_equal Time.gm(2009, 6, 19, 4, 37, 23), readme.lastrev.time
|
|
|
|
end
|
|
|
|
|
2012-10-28 11:12:23 +04:00
|
|
|
def test_entries_wrong_path_encoding
|
|
|
|
adpt = Redmine::Scm::Adapters::GitAdapter.new(
|
|
|
|
REPOSITORY_PATH,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
'EUC-JP'
|
|
|
|
)
|
|
|
|
entries1 = adpt.entries('latin-1-dir', '64f1f3e8')
|
|
|
|
assert entries1
|
|
|
|
assert_equal 3, entries1.size
|
|
|
|
f1 = entries1[1]
|
|
|
|
assert_equal nil, f1.name
|
|
|
|
assert_equal nil, f1.path
|
|
|
|
assert_equal 'file', f1.kind
|
|
|
|
end
|
|
|
|
|
2011-03-08 15:08:14 +03:00
|
|
|
def test_entries_latin_1_files
|
2011-03-08 09:38:23 +03:00
|
|
|
entries1 = @adapter.entries('latin-1-dir', '64f1f3e8')
|
|
|
|
assert entries1
|
|
|
|
assert_equal 3, entries1.size
|
|
|
|
f1 = entries1[1]
|
|
|
|
assert_equal "test-#{@char_1}-2.txt", f1.name
|
|
|
|
assert_equal "latin-1-dir/test-#{@char_1}-2.txt", f1.path
|
|
|
|
assert_equal 'file', f1.kind
|
|
|
|
end
|
|
|
|
|
2011-03-08 15:08:14 +03:00
|
|
|
def test_entries_latin_1_dir
|
2011-03-09 07:13:58 +03:00
|
|
|
if WINDOWS_PASS
|
2012-06-02 22:36:23 +04:00
|
|
|
puts WINDOWS_SKIP_STR
|
2011-06-08 14:05:40 +04:00
|
|
|
elsif JRUBY_SKIP
|
|
|
|
puts JRUBY_SKIP_STR
|
2011-03-08 15:08:14 +03:00
|
|
|
else
|
2011-03-09 07:13:58 +03:00
|
|
|
entries1 = @adapter.entries("latin-1-dir/test-#{@char_1}-subdir",
|
|
|
|
'1ca7f5ed')
|
2011-03-08 15:08:14 +03:00
|
|
|
assert entries1
|
|
|
|
assert_equal 3, entries1.size
|
|
|
|
f1 = entries1[1]
|
|
|
|
assert_equal "test-#{@char_1}-2.txt", f1.name
|
|
|
|
assert_equal "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-2.txt", f1.path
|
|
|
|
assert_equal 'file', f1.kind
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-09-17 14:41:33 +04:00
|
|
|
def test_entry
|
|
|
|
entry = @adapter.entry()
|
|
|
|
assert_equal "", entry.path
|
|
|
|
assert_equal "dir", entry.kind
|
|
|
|
entry = @adapter.entry('')
|
|
|
|
assert_equal "", entry.path
|
|
|
|
assert_equal "dir", entry.kind
|
|
|
|
assert_nil @adapter.entry('invalid')
|
|
|
|
assert_nil @adapter.entry('/invalid')
|
|
|
|
assert_nil @adapter.entry('/invalid/')
|
|
|
|
assert_nil @adapter.entry('invalid/invalid')
|
|
|
|
assert_nil @adapter.entry('invalid/invalid/')
|
|
|
|
assert_nil @adapter.entry('/invalid/invalid')
|
|
|
|
assert_nil @adapter.entry('/invalid/invalid/')
|
|
|
|
["README", "/README"].each do |path|
|
|
|
|
entry = @adapter.entry(path, '7234cb2750b63f')
|
|
|
|
assert_equal "README", entry.path
|
|
|
|
assert_equal "file", entry.kind
|
|
|
|
end
|
|
|
|
["sources", "/sources", "/sources/"].each do |path|
|
|
|
|
entry = @adapter.entry(path, '7234cb2750b63f')
|
|
|
|
assert_equal "sources", entry.path
|
|
|
|
assert_equal "dir", entry.kind
|
|
|
|
end
|
|
|
|
["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
|
|
|
|
entry = @adapter.entry(path, '7234cb2750b63f')
|
|
|
|
assert_equal "sources/watchers_controller.rb", entry.path
|
|
|
|
assert_equal "file", entry.kind
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2011-05-21 06:40:19 +04:00
|
|
|
def test_path_encoding_default_utf8
|
|
|
|
adpt1 = Redmine::Scm::Adapters::GitAdapter.new(
|
|
|
|
REPOSITORY_PATH
|
|
|
|
)
|
|
|
|
assert_equal "UTF-8", adpt1.path_encoding
|
|
|
|
adpt2 = Redmine::Scm::Adapters::GitAdapter.new(
|
|
|
|
REPOSITORY_PATH,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
nil,
|
|
|
|
""
|
|
|
|
)
|
|
|
|
assert_equal "UTF-8", adpt2.path_encoding
|
|
|
|
end
|
|
|
|
|
2011-07-08 06:04:45 +04:00
|
|
|
def test_cat_path_invalid
|
|
|
|
assert_nil @adapter.cat('invalid')
|
|
|
|
end
|
|
|
|
|
2011-07-08 06:05:09 +04:00
|
|
|
def test_cat_revision_invalid
|
|
|
|
assert @adapter.cat('README')
|
2012-04-27 05:33:04 +04:00
|
|
|
assert_nil @adapter.cat('README', '1234abcd5678')
|
2011-07-08 06:05:09 +04:00
|
|
|
end
|
|
|
|
|
2011-07-08 06:05:32 +04:00
|
|
|
def test_diff_path_invalid
|
|
|
|
assert_equal [], @adapter.diff('invalid', '713f4944648826f5')
|
|
|
|
end
|
|
|
|
|
2011-07-08 06:05:55 +04:00
|
|
|
def test_diff_revision_invalid
|
2012-04-27 05:33:04 +04:00
|
|
|
assert_nil @adapter.diff(nil, '1234abcd5678')
|
|
|
|
assert_nil @adapter.diff(nil, '713f4944648826f5', '1234abcd5678')
|
|
|
|
assert_nil @adapter.diff(nil, '1234abcd5678', '713f4944648826f5')
|
2011-07-08 06:05:55 +04:00
|
|
|
end
|
|
|
|
|
2011-07-08 06:06:16 +04:00
|
|
|
def test_annotate_path_invalid
|
|
|
|
assert_nil @adapter.annotate('invalid')
|
|
|
|
end
|
|
|
|
|
2011-07-08 06:06:38 +04:00
|
|
|
def test_annotate_revision_invalid
|
|
|
|
assert @adapter.annotate('README')
|
2012-04-27 05:33:04 +04:00
|
|
|
assert_nil @adapter.annotate('README', '1234abcd5678')
|
2011-07-08 06:06:38 +04:00
|
|
|
end
|
|
|
|
|
2011-02-15 08:58:31 +03:00
|
|
|
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
|
|
|
|
|
2011-02-11 18:30:22 +03:00
|
|
|
else
|
|
|
|
puts "Git test repository NOT FOUND. Skipping unit tests !!!"
|
|
|
|
def test_fake; assert true end
|
2010-02-28 15:09:09 +03:00
|
|
|
end
|
2011-02-11 18:30:22 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
rescue LoadError
|
|
|
|
class GitMochaFake < ActiveSupport::TestCase
|
|
|
|
def test_fake; assert(false, "Requires mocha to run those tests") end
|
2009-08-16 02:41:40 +04:00
|
|
|
end
|
|
|
|
end
|