/
test_merge.rb
162 lines (132 loc) · 4.62 KB
/
test_merge.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
#!/usr/bin/env ruby
require File.dirname(__FILE__) + '/../test_helper'
class TestMerge < Test::Unit::TestCase
def setup
set_file_paths
end
def test_branch_and_merge
in_temp_dir do |path|
g = Git.clone(@wbare, 'branch_merge_test')
Dir.chdir('branch_merge_test') do
g.branch('new_branch').in_branch('test') do
assert_equal('new_branch', g.current_branch)
new_file('new_file_1', 'hello')
new_file('new_file_2', 'hello')
g.add
true
end
assert_equal('master', g.current_branch)
new_file('new_file_3', 'hello')
g.add
assert(!g.status['new_file_1']) # file is not there
assert(g.branch('new_branch').merge)
assert(g.status['new_file_1']) # file has been merged in
end
end
end
def test_branch_and_merge_two
in_temp_dir do |path|
g = Git.clone(@wbare, 'branch_merge_test')
Dir.chdir('branch_merge_test') do
g.branch('new_branch').in_branch('test') do
assert_equal('new_branch', g.current_branch)
new_file('new_file_1', 'hello')
new_file('new_file_2', 'hello')
g.add
true
end
g.branch('new_branch2').in_branch('test') do
assert_equal('new_branch2', g.current_branch)
new_file('new_file_3', 'hello')
new_file('new_file_4', 'hello')
g.add
true
end
g.branch('new_branch').merge('new_branch2')
assert(!g.status['new_file_3']) # still in master branch
g.branch('new_branch').checkout
assert(g.status['new_file_3']) # file has been merged in
g.branch('master').checkout
g.merge(g.branch('new_branch'))
assert(g.status['new_file_3']) # file has been merged in
end
end
end
def test_branch_and_merge_multiple
in_temp_dir do |path|
g = Git.clone(@wbare, 'branch_merge_test')
Dir.chdir('branch_merge_test') do
g.branch('new_branch').in_branch('test') do
assert_equal('new_branch', g.current_branch)
new_file('new_file_1', 'hello')
new_file('new_file_2', 'hello')
g.add
true
end
g.branch('new_branch2').in_branch('test') do
assert_equal('new_branch2', g.current_branch)
new_file('new_file_3', 'hello')
new_file('new_file_4', 'hello')
g.add
true
end
assert(!g.status['new_file_1']) # still in master branch
assert(!g.status['new_file_3']) # still in master branch
g.merge(['new_branch', 'new_branch2'])
assert(g.status['new_file_1']) # file has been merged in
assert(g.status['new_file_3']) # file has been merged in
end
end
end
def test_no_ff_merge
in_temp_dir do |path|
g = Git.clone(@wbare, 'branch_merge_test')
Dir.chdir('branch_merge_test') do
g.branch('new_branch').in_branch('first commit message') do
new_file('new_file_1', 'hello')
g.add
true
end
g.branch('new_branch2').checkout
g.merge('new_branch', 'merge commit message') # ff merge
assert(g.status['new_file_1']) # file has been merged in
assert_equal('first commit message', g.log.first.message) # merge commit message was ignored
g.branch('new_branch').in_branch('second commit message') do
new_file('new_file_2', 'hello')
g.add
true
end
assert_equal('new_branch2', g.current_branch) # still in new_branch2 branch
g.merge('new_branch', 'merge commit message', no_ff: true) # no-ff merge
assert(g.status['new_file_2']) # file has been merged in
assert_equal('merge commit message', g.log.first.message)
end
end
end
def test_merge_no_commit
in_temp_dir do |path|
g = Git.clone(@wbare, 'branch_merge_test')
g.chdir do
g.branch('new_branch_1').in_branch('first commit message') do
new_file('new_file_1', 'foo')
g.add
true
end
g.branch('new_branch_2').in_branch('first commit message') do
new_file('new_file_2', 'bar')
g.add
true
end
g.checkout('new_branch_2')
before_merge = g.show
g.merge('new_branch_1', nil, no_commit: true)
# HEAD is the same as before.
assert_equal(before_merge, g.show)
# File has not been merged in.
status = g.status['new_file_1']
assert_equal('new_file_1', status.path)
assert_equal('A', status.type)
end
end
end
end