amp-git 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +23 -0
- data/Gemfile +15 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +68 -0
- data/VERSION +1 -0
- data/features/amp-git.feature +9 -0
- data/features/step_definitions/amp-git_steps.rb +0 -0
- data/features/support/env.rb +4 -0
- data/lib/amp-git/encoding/binary_delta.rb +171 -0
- data/lib/amp-git/repo_format/changeset.rb +348 -0
- data/lib/amp-git/repo_format/commit_object.rb +87 -0
- data/lib/amp-git/repo_format/index.rb +169 -0
- data/lib/amp-git/repo_format/loose_object.rb +78 -0
- data/lib/amp-git/repo_format/packfile.rb +263 -0
- data/lib/amp-git/repo_format/packfile_index.rb +196 -0
- data/lib/amp-git/repo_format/raw_object.rb +56 -0
- data/lib/amp-git/repo_format/staging_area.rb +215 -0
- data/lib/amp-git/repo_format/tag_object.rb +87 -0
- data/lib/amp-git/repo_format/tree_object.rb +98 -0
- data/lib/amp-git/repo_format/versioned_file.rb +133 -0
- data/lib/amp-git/repositories/local_repository.rb +192 -0
- data/lib/amp-git/repository.rb +57 -0
- data/lib/amp-git.rb +49 -0
- data/lib/amp_plugin.rb +1 -0
- data/spec/amp-git_spec.rb +15 -0
- data/spec/repository_spec.rb +74 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +29 -0
- data/test/index_tests/index +0 -0
- data/test/index_tests/test_helper.rb +16 -0
- data/test/index_tests/test_index.rb +69 -0
- data/test/packfile_tests/hasindex.idx +0 -0
- data/test/packfile_tests/hasindex.pack +0 -0
- data/test/packfile_tests/pack-4e1941122fd346526b0a3eee2d92f3277a0092cd.pack +0 -0
- data/test/packfile_tests/pack-d23ff2538f970371144ae7182c28730b11eb37c1.idx +0 -0
- data/test/packfile_tests/test_helper.rb +16 -0
- data/test/packfile_tests/test_packfile.rb +75 -0
- data/test/packfile_tests/test_packfile_index_v2.rb +90 -0
- data/test/packfile_tests/test_packfile_with_index.rb +76 -0
- data/test/test_commit_object.rb +60 -0
- data/test/test_git_delta.rb +67 -0
- data/test/test_helper.rb +71 -0
- data/test/test_loose_object.rb +51 -0
- data/test/test_tag_object.rb +72 -0
- data/test/test_tree_object.rb +55 -0
- metadata +215 -0
@@ -0,0 +1,75 @@
|
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
##################################################################
|
3
|
+
# Licensing Information #
|
4
|
+
# #
|
5
|
+
# The following code is licensed, as standalone code, under #
|
6
|
+
# the Ruby License, unless otherwise directed within the code. #
|
7
|
+
# #
|
8
|
+
# For information on the license of this code when distributed #
|
9
|
+
# with and used in conjunction with the other modules in the #
|
10
|
+
# Amp project, please see the root-level LICENSE file. #
|
11
|
+
# #
|
12
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
13
|
+
# #
|
14
|
+
##################################################################
|
15
|
+
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
17
|
+
|
18
|
+
class TestPackfile < AmpTestCase
|
19
|
+
include Amp::Core::Repositories::Git
|
20
|
+
PACK_FILE = "pack-4e1941122fd346526b0a3eee2d92f3277a0092cd.pack"
|
21
|
+
|
22
|
+
def setup
|
23
|
+
@opener = Amp::Core::Support::RootedOpener.new(File.expand_path(File.dirname(__FILE__)))
|
24
|
+
@opener.default = :open_file # for testing purposes!
|
25
|
+
@packfile = PackFile.new(PACK_FILE, @opener)
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_load_packfile
|
29
|
+
assert_not_nil @packfile
|
30
|
+
end
|
31
|
+
|
32
|
+
headers = [[[0b0001_1101], [1, 13]],
|
33
|
+
[[0b1010_1001, 0b0010_1011], [2, 697]],
|
34
|
+
[[0b1001_0000, 0b0000_0000], [1, 0]],
|
35
|
+
[[0b1111_1111, 0b1010_1001, 0b0000_1011], [7, 23199]]]
|
36
|
+
|
37
|
+
headers.each_with_index do |(input, output), idx|
|
38
|
+
class_eval <<-EOF
|
39
|
+
def test_header_#{idx}
|
40
|
+
input = StringIO.new(#{input.map {|x| x.chr}.join.inspect})
|
41
|
+
type, size = Amp::Core::Repositories::Git::PackFile::PackFileEntry.read_header(input)
|
42
|
+
assert_equal #{output[0]}, type
|
43
|
+
assert_equal #{output[1]}, size
|
44
|
+
end
|
45
|
+
EOF
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_commit_lookup
|
49
|
+
some_commit_obj = @packfile.object_for_hash(StringUtils.unhexlify("862a669a8ddf39a4c60be6bd40c97dc242b6128e"))
|
50
|
+
assert_not_nil some_commit_obj
|
51
|
+
assert_kind_of CommitObject, some_commit_obj
|
52
|
+
assert_equal "2ac9f8fa1628a094cced3534b63084d5f480d10a", hexlify(some_commit_obj.tree_ref)
|
53
|
+
assert_equal ["840c43e100120cd282cf9b334b08aa5fbe2634a0"], some_commit_obj.parent_refs.map {|x| hexlify(x)}
|
54
|
+
assert_equal "Michael Edgar <michael.j.edgar@dartmouth.edu>", some_commit_obj.author
|
55
|
+
assert_equal "Michael Edgar <michael.j.edgar@dartmouth.edu>", some_commit_obj.committer
|
56
|
+
assert_equal Time.at(1273260273), some_commit_obj.date
|
57
|
+
assert_equal "Regenerated gemspec for version 1.1.0", some_commit_obj.message
|
58
|
+
end
|
59
|
+
|
60
|
+
# The previous test gets the first commit. no searching going on. This gets a further one.
|
61
|
+
def test_further_lookup
|
62
|
+
some_commit_obj = @packfile.object_for_hash(StringUtils.unhexlify("958cd2af1c2676e9e90c7ea45bfe384acdcf42e0"))
|
63
|
+
assert_not_nil some_commit_obj
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_tree_lookup
|
67
|
+
some_tree_obj = @packfile.object_for_hash(StringUtils.unhexlify("2ac9f8fa1628a094cced3534b63084d5f480d10a"))
|
68
|
+
assert_not_nil some_tree_obj
|
69
|
+
entry_names = %w(.document .gitignore LICENSE README.md Rakefile VERSION lib spec yard-struct.gemspec).sort
|
70
|
+
assert_equal entry_names, some_tree_obj.entry_names.sort
|
71
|
+
lookedup_entry = TreeObject::TreeEntry.new("Rakefile", 0100644, StringUtils.unhexlify("53bbb0b38868a1bd2059a1174f54de63764013af"))
|
72
|
+
assert_equal lookedup_entry, some_tree_obj.tree_lookup("Rakefile")
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
##################################################################
|
3
|
+
# Licensing Information #
|
4
|
+
# #
|
5
|
+
# The following code is licensed, as standalone code, under #
|
6
|
+
# the Ruby License, unless otherwise directed within the code. #
|
7
|
+
# #
|
8
|
+
# For information on the license of this code when distributed #
|
9
|
+
# with and used in conjunction with the other modules in the #
|
10
|
+
# Amp project, please see the root-level LICENSE file. #
|
11
|
+
# #
|
12
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
13
|
+
# #
|
14
|
+
##################################################################
|
15
|
+
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
17
|
+
|
18
|
+
##
|
19
|
+
# While TestPackfile has some index-related tests in it, they aren't on an
|
20
|
+
# interesting enough version 2 index file. This test suite uses an index file
|
21
|
+
# with a modest 1k entries in it, which will test its searching abilities a bit
|
22
|
+
# better.
|
23
|
+
class TestPackfileIndexV2 < AmpTestCase
|
24
|
+
include Amp::Core::Repositories::Git
|
25
|
+
BIG_INDEX_FILE = "pack-d23ff2538f970371144ae7182c28730b11eb37c1.idx"
|
26
|
+
|
27
|
+
def setup
|
28
|
+
@opener = Amp::Core::Support::RootedOpener.new(File.expand_path(File.dirname(__FILE__)))
|
29
|
+
@opener.default = :open_file # for testing purposes!
|
30
|
+
fp = @opener.open(BIG_INDEX_FILE)
|
31
|
+
@index = PackFileIndex.parse(fp)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_load_packfile
|
35
|
+
assert_not_nil @index
|
36
|
+
assert_kind_of PackFileIndexV2, @index
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_packfile_size
|
40
|
+
assert_equal 0x0402, @index.size
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_fanout_values
|
44
|
+
assert_equal 0x04, @index.fanout[0]
|
45
|
+
assert_equal 0x12, @index.fanout[3]
|
46
|
+
assert_equal 0x62, @index.fanout[20]
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_search_range_for_hash
|
50
|
+
ranges = [0x0...0x04, 0x04...0x05, 0x05...0x0b, 0x0b...0x12, 0x12...0x18, 0x18...0x20, 0x20...0x21,
|
51
|
+
0x21...0x26, 0x26...0x26, 0x26...0x2c]
|
52
|
+
ranges.each_with_index do |range, idx|
|
53
|
+
assert_equal range, @index.search_range_for_hash("#{idx.chr}01234567890123456789")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
##
|
58
|
+
# This tests normal offsets. Not big ones.
|
59
|
+
def test_small_offset_for_index
|
60
|
+
expected = [0x001ac4c3, 0x001bcaab, 0x001a82fe, 0x0003518e]
|
61
|
+
0.upto(3) do |idx|
|
62
|
+
assert_equal expected[idx], @index.offset_for_index(idx)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
##
|
67
|
+
# There are some hacked in long-style offsets in this index file. The
|
68
|
+
# index file is valid, but I doubt there is a valid packfile it could
|
69
|
+
# reference.
|
70
|
+
#
|
71
|
+
# All counting below is 0-indexed.
|
72
|
+
# Offset number 8 refers to 64-bit offset #1. This long-offset is 0x0000bbbb00000000.
|
73
|
+
# Offset number 9 refers to 64-bit offset #0. This long-offset is 0x0000ffff00000000.
|
74
|
+
def test_big_offset_for_index
|
75
|
+
expected = 0x0000bbbb00000000
|
76
|
+
assert_equal expected, @index.offset_for_index(8)
|
77
|
+
expected = 0x0000ffff00000000
|
78
|
+
assert_equal expected, @index.offset_for_index(9)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_offset_for_hash
|
82
|
+
pairs = [["0013A4B53EA0A0149A777E924019F80BA6588764", 0x001ac4c3],
|
83
|
+
["00166B16ECFFE5B872EE11824B389748A2B2C997", 0x001bcaab],
|
84
|
+
["004EB28B17D7FC33C7B90D2B37E79566038E29C1", 0x001a82fe],
|
85
|
+
["00D917561EB69F243B326DAAA13F7C09D505DB9C", 0x0003518e]]
|
86
|
+
pairs.each do |hsh, expected|
|
87
|
+
assert_equal expected, @index.offset_for_hash(StringUtils.unhexlify(hsh))
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
##################################################################
|
3
|
+
# Licensing Information #
|
4
|
+
# #
|
5
|
+
# The following code is licensed, as standalone code, under #
|
6
|
+
# the Ruby License, unless otherwise directed within the code. #
|
7
|
+
# #
|
8
|
+
# For information on the license of this code when distributed #
|
9
|
+
# with and used in conjunction with the other modules in the #
|
10
|
+
# Amp project, please see the root-level LICENSE file. #
|
11
|
+
# #
|
12
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
13
|
+
# #
|
14
|
+
##################################################################
|
15
|
+
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
17
|
+
|
18
|
+
class TestPackfileWithIndex < AmpTestCase
|
19
|
+
include Amp::Core::Repositories::Git
|
20
|
+
INDEX_FILE = "hasindex.idx"
|
21
|
+
PACK_FILE = "hasindex.pack"
|
22
|
+
|
23
|
+
def setup
|
24
|
+
@opener = Amp::Core::Support::RootedOpener.new(File.expand_path(File.dirname(__FILE__)))
|
25
|
+
@opener.default = :open_file # for testing purposes!
|
26
|
+
@packfile = PackFile.new(PACK_FILE, @opener)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_load_packfile
|
30
|
+
assert_not_nil @packfile
|
31
|
+
end
|
32
|
+
|
33
|
+
headers = [[[0b0001_1101], [1, 13]],
|
34
|
+
[[0b1010_1001, 0b0010_1011], [2, 697]],
|
35
|
+
[[0b1001_0000, 0b0000_0000], [1, 0]],
|
36
|
+
[[0b1111_1111, 0b1010_1001, 0b0000_1011], [7, 23199]]]
|
37
|
+
|
38
|
+
headers.each_with_index do |(input, output), idx|
|
39
|
+
class_eval <<-EOF
|
40
|
+
def test_header_#{idx}
|
41
|
+
input = StringIO.new(#{input.map {|x| x.chr}.join.inspect})
|
42
|
+
type, size = Amp::Core::Repositories::Git::PackFile::PackFileEntry.read_header(input)
|
43
|
+
assert_equal #{output[0]}, type
|
44
|
+
assert_equal #{output[1]}, size
|
45
|
+
end
|
46
|
+
EOF
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_commit_lookup
|
50
|
+
some_commit_obj = @packfile.object_for_hash(StringUtils.unhexlify("862a669a8ddf39a4c60be6bd40c97dc242b6128e"))
|
51
|
+
assert_not_nil some_commit_obj
|
52
|
+
assert_kind_of CommitObject, some_commit_obj
|
53
|
+
assert_equal "2ac9f8fa1628a094cced3534b63084d5f480d10a", hexlify(some_commit_obj.tree_ref)
|
54
|
+
assert_equal ["840c43e100120cd282cf9b334b08aa5fbe2634a0"], some_commit_obj.parent_refs.map {|x| hexlify(x)}
|
55
|
+
assert_equal "Michael Edgar <michael.j.edgar@dartmouth.edu>", some_commit_obj.author
|
56
|
+
assert_equal "Michael Edgar <michael.j.edgar@dartmouth.edu>", some_commit_obj.committer
|
57
|
+
assert_equal Time.at(1273260273), some_commit_obj.date
|
58
|
+
assert_equal "Regenerated gemspec for version 1.1.0", some_commit_obj.message
|
59
|
+
end
|
60
|
+
|
61
|
+
# The previous test gets the first commit. no searching going on. This gets a further one.
|
62
|
+
def test_further_lookup
|
63
|
+
some_commit_obj = @packfile.object_for_hash(StringUtils.unhexlify("958cd2af1c2676e9e90c7ea45bfe384acdcf42e0"))
|
64
|
+
assert_not_nil some_commit_obj
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_tree_lookup
|
68
|
+
some_tree_obj = @packfile.object_for_hash(StringUtils.unhexlify("2ac9f8fa1628a094cced3534b63084d5f480d10a"))
|
69
|
+
assert_not_nil some_tree_obj
|
70
|
+
entry_names = %w(.document .gitignore LICENSE README.md Rakefile VERSION lib spec yard-struct.gemspec).sort
|
71
|
+
assert_equal entry_names, some_tree_obj.entry_names.sort
|
72
|
+
lookedup_entry = TreeObject::TreeEntry.new("Rakefile", 0100644, StringUtils.unhexlify("53bbb0b38868a1bd2059a1174f54de63764013af"))
|
73
|
+
assert_equal lookedup_entry, some_tree_obj.tree_lookup("Rakefile")
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
16
|
+
|
17
|
+
class TestGitCommitObject < AmpTestCase
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@content = "tree ecb7b4460825bed7c0bc6d17004816d15ae32c5e\n"+
|
21
|
+
"parent 8c27219d73786aa2e91d5ae964624ef36696c307\nauthor Michael "+
|
22
|
+
"Edgar <michael.j.edgar@dartmouth.edu> 1273865360 -0400\ncommitter "+
|
23
|
+
"Michael Edgar <michael.j.edgar@dartmouth.edu> 1273865360 -0400\n\n"+
|
24
|
+
"Removed the gemspec from the repo\n"
|
25
|
+
@commit_obj = Amp::Core::Repositories::Git::CommitObject.new(
|
26
|
+
Amp::Core::Support::StringUtils.sha1(@content), nil, @content)
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_correct_type
|
30
|
+
assert_equal 'commit', @commit_obj.type
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_correct_content
|
34
|
+
assert_equal @content, @commit_obj.content
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_tree_ref
|
38
|
+
assert_equal unhexlify("ecb7b4460825bed7c0bc6d17004816d15ae32c5e"), @commit_obj.tree_ref
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_parent_refs
|
42
|
+
assert_equal [unhexlify("8c27219d73786aa2e91d5ae964624ef36696c307")], @commit_obj.parent_refs
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_author
|
46
|
+
assert_equal "Michael Edgar <michael.j.edgar@dartmouth.edu>", @commit_obj.author
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_committer
|
50
|
+
assert_equal "Michael Edgar <michael.j.edgar@dartmouth.edu>", @commit_obj.author
|
51
|
+
end
|
52
|
+
|
53
|
+
def test_date
|
54
|
+
assert_equal Time.at(1273865360), @commit_obj.date
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_messages
|
58
|
+
assert_equal "Removed the gemspec from the repo", @commit_obj.message
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# -*- coding: us-ascii -*-
|
2
|
+
##################################################################
|
3
|
+
# Licensing Information #
|
4
|
+
# #
|
5
|
+
# The following code is licensed, as standalone code, under #
|
6
|
+
# the Ruby License, unless otherwise directed within the code. #
|
7
|
+
# #
|
8
|
+
# For information on the license of this code when distributed #
|
9
|
+
# with and used in conjunction with the other modules in the #
|
10
|
+
# Amp project, please see the root-level LICENSE file. #
|
11
|
+
# #
|
12
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
13
|
+
# #
|
14
|
+
##################################################################
|
15
|
+
|
16
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
17
|
+
require 'amp-git/encoding/binary_delta'
|
18
|
+
|
19
|
+
class TestPackfileWithIndex < AmpTestCase
|
20
|
+
include Amp::Core::Repositories::Git::Encoding
|
21
|
+
|
22
|
+
def test_parse_numbers
|
23
|
+
delta_str = "\x10\x20"
|
24
|
+
input = BinaryDelta.new(delta_str)
|
25
|
+
assert_equal 0x10, input.base_length
|
26
|
+
assert_equal 0x20, input.result_length
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_parse_longer_numbers
|
30
|
+
delta_str = "\xA0\x73\xB0\x6F"
|
31
|
+
input = BinaryDelta.new(delta_str)
|
32
|
+
base = 0b11100110100000
|
33
|
+
result = 0b11011110110000
|
34
|
+
assert_equal base, input.base_length
|
35
|
+
assert_equal result, input.result_length
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_simple_duplicating_patch
|
39
|
+
delta_str = "\x04\x08\x91\x00\x04\x91\x00\x04"
|
40
|
+
input = "abcd"
|
41
|
+
expected = "abcdabcd"
|
42
|
+
assert_equal expected, BinaryDelta.new(delta_str).apply(input)
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_patch_with_insert
|
46
|
+
delta_str = "\x04\x14\x10hello, world!lol\x91\x00\x04"
|
47
|
+
input = "abcd"
|
48
|
+
expected = "hello, world!lolabcd"
|
49
|
+
assert_equal expected, BinaryDelta.new(delta_str).apply(input)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_raises_on_mismatched_base_length
|
53
|
+
delta_str = "\x04\x04"
|
54
|
+
input = "abcdef"
|
55
|
+
assert_raises DeltaError do
|
56
|
+
BinaryDelta.new(delta_str).apply(input)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_raises_on_mismatched_result_length
|
61
|
+
delta_str = "\x04\x09\x91\x00\x04\x91\x00\x04"
|
62
|
+
input = "abcd"
|
63
|
+
assert_raises DeltaError do
|
64
|
+
BinaryDelta.new(delta_str).apply(input)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
2
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
3
|
+
require 'rubygems'
|
4
|
+
require 'amp-front'
|
5
|
+
require 'amp-core'
|
6
|
+
require 'amp-git'
|
7
|
+
require 'test/unit'
|
8
|
+
require 'minitest/unit'
|
9
|
+
require 'tmpdir'
|
10
|
+
|
11
|
+
Amp::Plugins::Core.new.load!
|
12
|
+
Amp::Plugins::Git.new.load!
|
13
|
+
class AmpTestCase < MiniTest::Unit::TestCase
|
14
|
+
def setup
|
15
|
+
super
|
16
|
+
tmpdir = nil
|
17
|
+
Dir.chdir Dir.tmpdir do tmpdir = Dir.pwd end # HACK OSX /private/tmp
|
18
|
+
@tempdir = File.join tmpdir, "test_amp_#{$$}"
|
19
|
+
@tempdir.untaint
|
20
|
+
end
|
21
|
+
|
22
|
+
def tempdir
|
23
|
+
@tempdir
|
24
|
+
end
|
25
|
+
|
26
|
+
def teardown
|
27
|
+
FileUtils.rm_rf @tempdir if defined?(@tempdir) && @tempdir && File.exist?(@tempdir)
|
28
|
+
end
|
29
|
+
|
30
|
+
def hexlify(input)
|
31
|
+
Amp::Core::Support::StringUtils.hexlify(input)
|
32
|
+
end
|
33
|
+
|
34
|
+
def unhexlify(input)
|
35
|
+
Amp::Core::Support::StringUtils.unhexlify(input)
|
36
|
+
end
|
37
|
+
|
38
|
+
# taken from rubygems
|
39
|
+
def write_file(path)
|
40
|
+
path = File.join(@tempdir, path)
|
41
|
+
dir = File.dirname path
|
42
|
+
FileUtils.mkdir_p dir
|
43
|
+
|
44
|
+
open path, 'wb' do |io|
|
45
|
+
yield io
|
46
|
+
end
|
47
|
+
|
48
|
+
path
|
49
|
+
end
|
50
|
+
|
51
|
+
def assert_regexp_equal(areg, breg)
|
52
|
+
# because regexes, inspected, seems to be killing assert_equal
|
53
|
+
assert areg.inspect == breg.inspect, "#{areg.inspect} is not equal to #{breg.inspect}"
|
54
|
+
end
|
55
|
+
|
56
|
+
def assert_false(val)
|
57
|
+
assert_equal(false, !!val)
|
58
|
+
end
|
59
|
+
|
60
|
+
def assert_not_nil(val)
|
61
|
+
refute_equal(nil, val)
|
62
|
+
end
|
63
|
+
|
64
|
+
def assert_file_contents(file, contents)
|
65
|
+
File.open(file,"r") do |f|
|
66
|
+
assert_equal f.read, contents
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
MiniTest::Unit.autorun
|
@@ -0,0 +1,51 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
16
|
+
|
17
|
+
class TestGitLooseObject < AmpTestCase
|
18
|
+
def setup
|
19
|
+
super
|
20
|
+
self.write_file "objects/ab/looseobject1" do |io|
|
21
|
+
io << "blob 10\0abcdefghij"
|
22
|
+
end
|
23
|
+
self.write_file "objects/ab/looseobject2" do |io|
|
24
|
+
io << "blob 4\0mikeedgarisacoolguy"
|
25
|
+
end
|
26
|
+
self.write_file "objects/ab/looseobject3" do |io|
|
27
|
+
io << "blob 0\0hellogarbage"
|
28
|
+
end
|
29
|
+
@opener = Amp::Core::Support::RootedOpener.new(tempdir)
|
30
|
+
@opener.default = :open_file
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_simple_file
|
34
|
+
obj = Amp::Core::Repositories::Git::LooseObject.lookup("ablooseobject1", @opener)
|
35
|
+
assert_equal "blob", obj.type
|
36
|
+
assert_equal "abcdefghij", obj.content
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_trailing_garbage_file
|
40
|
+
obj = Amp::Core::Repositories::Git::LooseObject.lookup("ablooseobject2", @opener)
|
41
|
+
assert_equal "blob", obj.type
|
42
|
+
assert_equal "mike", obj.content
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_empty_file
|
46
|
+
obj = Amp::Core::Repositories::Git::LooseObject.lookup("ablooseobject3", @opener)
|
47
|
+
assert_equal "blob", obj.type
|
48
|
+
assert_equal "", obj.content
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
16
|
+
|
17
|
+
class TestGitTagObject < AmpTestCase
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@content = <<-EOF
|
21
|
+
object 437b1b20df4b356c9342dac8d38849f24ef44f27
|
22
|
+
type commit
|
23
|
+
tag v1.5.0
|
24
|
+
tagger Junio C Hamano <junkio@cox.net> 1171411200 +0000
|
25
|
+
|
26
|
+
GIT 1.5.0
|
27
|
+
-----BEGIN PGP SIGNATURE-----
|
28
|
+
Version: GnuPG v1.4.6 (GNU/Linux)
|
29
|
+
|
30
|
+
iD8DBQBF0lGqwMbZpPMRm5oRAuRiAJ9ohBLd7s2kqjkKlq1qqC57SbnmzQCdG4ui
|
31
|
+
nLE/L9aUXdWeTFPron96DLA=
|
32
|
+
=2E+0
|
33
|
+
-----END PGP SIGNATURE-----
|
34
|
+
EOF
|
35
|
+
@tag_obj = Amp::Core::Repositories::Git::TagObject.new(
|
36
|
+
Amp::Core::Support::StringUtils.sha1(@content), nil, @content)
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_correct_type
|
40
|
+
assert_equal 'tag', @tag_obj.type
|
41
|
+
end
|
42
|
+
|
43
|
+
def test_correct_content
|
44
|
+
assert_equal @content, @tag_obj.content
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_object
|
48
|
+
assert_equal unhexlify("437b1b20df4b356c9342dac8d38849f24ef44f27"), @tag_obj.object_ref
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_reffed_type
|
52
|
+
assert_equal "commit", @tag_obj.reffed_type
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_tagger
|
56
|
+
assert_equal "Junio C Hamano <junkio@cox.net>", @tag_obj.tagger
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_date
|
60
|
+
assert_equal Time.at(1171411200), @tag_obj.date
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_tag
|
64
|
+
assert_equal "v1.5.0", @tag_obj.tag
|
65
|
+
end
|
66
|
+
|
67
|
+
def test_message
|
68
|
+
assert_equal "GIT 1.5.0\n-----BEGIN PGP SIGNATURE-----\nVersion: GnuPG v1.4.6 (GNU/Linux)\n\n"+
|
69
|
+
"iD8DBQBF0lGqwMbZpPMRm5oRAuRiAJ9ohBLd7s2kqjkKlq1qqC57SbnmzQCdG4ui\nnLE/L9aUXdWeT"+
|
70
|
+
"FPron96DLA=\n=2E+0\n-----END PGP SIGNATURE-----", @tag_obj.message
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
##################################################################
|
2
|
+
# Licensing Information #
|
3
|
+
# #
|
4
|
+
# The following code is licensed, as standalone code, under #
|
5
|
+
# the Ruby License, unless otherwise directed within the code. #
|
6
|
+
# #
|
7
|
+
# For information on the license of this code when distributed #
|
8
|
+
# with and used in conjunction with the other modules in the #
|
9
|
+
# Amp project, please see the root-level LICENSE file. #
|
10
|
+
# #
|
11
|
+
# © Michael J. Edgar and Ari Brown, 2009-2010 #
|
12
|
+
# #
|
13
|
+
##################################################################
|
14
|
+
|
15
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'test_helper'))
|
16
|
+
|
17
|
+
class TestGitTreeObject < AmpTestCase
|
18
|
+
|
19
|
+
def setup
|
20
|
+
@content = "100644 example_helper.rb\x00\xD3\xD5\xED\x9DA4_"+
|
21
|
+
"\xE3\xC3\nK\xCD<!\xEA-_\x9E\xDC=40000 examples\x00"+
|
22
|
+
"\xAE\xCB\xE9d!|\xB9\xA6\x96\x024],U\xEE\x99\xA2\xEE\xD4\x92"
|
23
|
+
@tree_obj = Amp::Core::Repositories::Git::TreeObject.new(
|
24
|
+
Amp::Core::Support::StringUtils.sha1(@content), nil,@content)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_correct_type
|
28
|
+
assert_equal 'tree', @tree_obj.type
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_correct_content
|
32
|
+
assert_equal @content, @tree_obj.content
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_correct_num_pairs
|
36
|
+
assert_equal 2, @tree_obj.size
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_parses_filenames
|
40
|
+
assert_not_nil @tree_obj.tree_lookup("example_helper.rb")
|
41
|
+
assert_not_nil @tree_obj.tree_lookup("examples")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_parses_mode_correct
|
45
|
+
assert_equal 0100644, @tree_obj.tree_lookup("example_helper.rb").mode
|
46
|
+
assert_equal 040000, @tree_obj.tree_lookup("examples").mode
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_parses_refs
|
50
|
+
expected_first = "\xD3\xD5\xED\x9DA4_\xE3\xC3\nK\xCD<!\xEA-_\x9E\xDC="
|
51
|
+
expected_second = "\xAE\xCB\xE9d!|\xB9\xA6\x96\x024],U\xEE\x99\xA2\xEE\xD4\x92"
|
52
|
+
assert_equal expected_first, @tree_obj.tree_lookup("example_helper.rb").ref
|
53
|
+
assert_equal expected_second, @tree_obj.tree_lookup("examples").ref
|
54
|
+
end
|
55
|
+
end
|