forked from libgit2/rugged
/
branch_test.rb
192 lines (147 loc) · 5.79 KB
/
branch_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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# encoding: UTF-8
require "test_helper"
class BranchTest < Rugged::TestCase
include Rugged::TempRepositoryAccess
def test_list_all_names
assert_equal [
"master",
"origin/HEAD",
"origin/master",
"origin/packed",
], Rugged::Branch.each_name(@repo).sort
end
def test_list_only_local_branches
assert_equal ["master"], Rugged::Branch.each_name(@repo, :local).sort
end
def test_list_only_remote_branches
assert_equal [
"origin/HEAD",
"origin/master",
"origin/packed",
], Rugged::Branch.each_name(@repo, :remote).sort
end
def test_get_latest_commit_in_branch
tip = Rugged::Branch.lookup(@repo, "master").tip
assert_kind_of Rugged::Commit, tip
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", tip.oid
end
def test_lookup_local_branch
branch = Rugged::Branch.lookup(@repo, "master")
refute_nil branch
assert_equal "master", branch.name
assert_equal "refs/heads/master", branch.canonical_name
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", branch.tip.oid
end
def test_lookup_remote_branches
branch = Rugged::Branch.lookup(@repo, "origin/packed", :remote)
refute_nil branch
assert_equal "origin/packed", branch.name
assert_equal "refs/remotes/origin/packed", branch.canonical_name
assert_equal "41bc8c69075bbdb46c5c6f0566cc8cc5b46e8bd9", branch.tip.oid
end
def test_lookup_unicode_branch_name
new_branch = @repo.create_branch("Ångström", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
refute_nil new_branch
retrieved_branch = Rugged::Branch.lookup(@repo, "Ångström")
refute_nil retrieved_branch
assert_equal new_branch, retrieved_branch
end
def test_delete_branch
branch = @repo.create_branch("test_branch")
branch.delete!
assert_nil Rugged::Branch.lookup(@repo, "test_branch")
end
def test_rename_branch
branch = @repo.create_branch("test_branch")
branch.move('other_branch')
assert_nil Rugged::Branch.lookup(@repo, "test_branch")
refute_nil Rugged::Branch.lookup(@repo, "other_branch")
end
def test_create_new_branch
new_branch = @repo.create_branch("test_branch", "5b5b025afb0b4c913b4c338a42934a3863bf3644")
refute_nil new_branch
assert_equal "test_branch", new_branch.name
assert_equal "refs/heads/test_branch", new_branch.canonical_name
refute_nil new_branch.tip
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
refute_nil @repo.branches.find { |p| p.name == "test_branch" }
end
def test_create_unicode_branch
branch_name = "A\314\212ngstro\314\210m"
new_branch = @repo.create_branch(branch_name, "5b5b025afb0b4c913b4c338a42934a3863bf3644")
refute_nil new_branch
assert_equal branch_name, new_branch.name
assert_equal "refs/heads/#{branch_name}", new_branch.canonical_name
refute_nil new_branch.tip
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
refute_nil @repo.branches.find { |p| p.name == branch_name }
end
def test_create_branch_short_sha
new_branch = @repo.create_branch("test_branch", "5b5b025")
refute_nil new_branch
assert_equal "test_branch", new_branch.name
assert_equal "refs/heads/test_branch", new_branch.canonical_name
refute_nil new_branch.tip
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
end
def test_create_branch_from_tag
new_branch = @repo.create_branch("test_branch", "refs/tags/v0.9")
refute_nil new_branch
assert_equal "test_branch", new_branch.name
assert_equal "refs/heads/test_branch", new_branch.canonical_name
refute_nil new_branch.tip
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
end
def test_create_branch_from_head
new_branch = @repo.create_branch("test_branch")
refute_nil new_branch
assert_equal "test_branch", new_branch.name
assert_equal "refs/heads/test_branch", new_branch.canonical_name
refute_nil new_branch.tip
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
end
def test_create_branch_explicit_head
new_branch = @repo.create_branch("test_branch", "HEAD")
refute_nil new_branch
assert_equal "test_branch", new_branch.name
assert_equal "refs/heads/test_branch", new_branch.canonical_name
refute_nil new_branch.tip
assert_equal "36060c58702ed4c2a40832c51758d5344201d89a", new_branch.tip.oid
end
def test_create_branch_from_commit
new_branch = @repo.create_branch("test_branch",
Rugged::Commit.lookup(@repo, "5b5b025afb0b4c913b4c338a42934a3863bf3644"))
refute_nil new_branch
assert_equal "test_branch", new_branch.name
assert_equal "refs/heads/test_branch", new_branch.canonical_name
refute_nil new_branch.tip
assert_equal "5b5b025afb0b4c913b4c338a42934a3863bf3644", new_branch.tip.oid
end
def test_create_branch_from_tree_fails
assert_raises ArgumentError, Rugged::InvalidError do
@repo.create_branch("test_branch",
Rugged::Tree.lookup(@repo, "f60079018b664e4e79329a7ef9559c8d9e0378d1"))
end
end
def test_create_branch_from_blob_fails
assert_raises ArgumentError, Rugged::InvalidError do
@repo.create_branch("test_branch",
Rugged::Blob.lookup(@repo, "1385f264afb75a56a5bec74243be9b367ba4ca08"))
end
end
def test_create_branch_from_unknown_ref_fails
assert_raises Rugged::ReferenceError do
@repo.create_branch("test_branch", "i_do_not_exist")
end
end
def test_create_branch_from_unknown_commit_fails
assert_raises Rugged::ReferenceError do
@repo.create_branch("test_branch", "dd15de908706711b51b7acb24faab726d2b3cb16")
end
end
def test_create_branch_from_non_canonical_fails
assert_raises Rugged::ReferenceError do
@repo.create_branch("test_branch", "packed")
end
end
end