/
reference_test.rb
113 lines (93 loc) · 3.85 KB
/
reference_test.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
require File.expand_path "../test_helper", __FILE__
context "Rugged::Reference stuff" do
setup do
@path = File.dirname(__FILE__) + '/fixtures/testrepo.git'
@repo = Rugged::Repository.new(@path)
end
teardown do
FileUtils.remove_entry_secure(@path + '/refs/heads/unit_test', true)
end
test "can list references" do
refs = @repo.refs.map { |r| r.name.gsub("refs/", '') }.sort.join(':')
assert_equal "heads/master:heads/packed:tags/v0.9:tags/v1.0", refs
end
test "can list filtered references from regex" do
refs = @repo.refs(/tags/).map { |r| r.name.gsub("refs/", '') }.sort.join(':')
assert_equal "tags/v0.9:tags/v1.0", refs
end
test "can list filtered references from string" do
refs = @repo.refs('0.9').map { |r| r.name.gsub("refs/", '') }.sort.join(':')
assert_equal "tags/v0.9", refs
end
test "can open reference" do
ref = Rugged::Reference.lookup(@repo, "refs/heads/master")
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/master", ref.name
end
test "will return nil for an invalid reference" do
ref = Rugged::Reference.lookup(@repo, "lol/wut")
assert_equal nil, ref
end
test "can get a reflog" do
ref = Rugged::Reference.lookup(@repo, "refs/heads/master")
log = ref.log
e = log[1]
assert_equal e[:oid_old], "8496071c1b46c854b31185ea97743be6a8774479"
assert_equal e[:oid_new], "5b5b025afb0b4c913b4c338a42934a3863bf3644"
assert_equal e[:message], "commit: another commit"
assert_equal e[:committer][:email], "schacon@gmail.com"
end
test "can check for the existence of a reference" do
exists = Rugged::Reference.exist?(@repo, "refs/heads/master")
assert exists
exists = Rugged::Reference.exist?(@repo, "lol/wut")
assert !exists
end
test "can open packed reference" do
ref = Rugged::Reference.lookup(@repo, "refs/heads/packed")
assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/packed", ref.name
end
test "can create reference from symbolic reference" do
ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "refs/heads/master")
assert_equal "refs/heads/master", ref.target
assert_equal :symbolic, ref.type
assert_equal "refs/heads/unit_test", ref.name
ref.delete!
end
test "can create reference from oid" do
ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "36060c58702ed4c2a40832c51758d5344201d89a")
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/unit_test", ref.name
ref.delete!
end
test "can rename ref" do
ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "36060c58702ed4c2a40832c51758d5344201d89a")
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/unit_test", ref.name
ref.rename "refs/heads/rug_new_name"
assert_equal "refs/heads/rug_new_name", ref.name
ref.delete!
end
test "can set target on reference" do
ref = Rugged::Reference.create(@repo, "refs/heads/unit_test", "36060c58702ed4c2a40832c51758d5344201d89a")
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", ref.target
assert_equal :direct, ref.type
assert_equal "refs/heads/unit_test", ref.name
ref.target = "5b5b025afb0b4c913b4c338a42934a3863bf3644"
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", ref.target
ref.delete!
end
test "can resolve head" do
ref = Rugged::Reference.lookup(@repo, "HEAD")
assert_equal "refs/heads/master", ref.target
assert_equal :symbolic, ref.type
head = ref.resolve
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", head.target
assert_equal :direct, head.type
end
end