5
5
class TestTreeOps < Test ::Unit ::TestCase
6
6
7
7
def test_read_tree
8
+ treeish = 'testbranch1'
9
+ expected_command_line = [ 'read-tree' , treeish ]
10
+ git_cmd = :read_tree
11
+ git_cmd_args = [ treeish ]
12
+ assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
13
+ end
14
+
15
+ def test_read_tree_with_prefix
16
+ treeish = 'testbranch1'
17
+ prefix = 'foo'
18
+ expected_command_line = [ 'read-tree' , "--prefix=#{ prefix } " , treeish ]
19
+ git_cmd = :read_tree
20
+ git_cmd_args = [ treeish , prefix : prefix ]
21
+ assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
22
+ end
23
+
24
+ def test_write_tree
25
+ expected_command_line = [ 'write-tree' ]
26
+ git_output = 'aa7349e'
27
+ git_cmd = :write_tree
28
+ git_cmd_args = [ ]
29
+ result = assert_command_line ( expected_command_line , git_cmd , git_cmd_args , git_output )
30
+ # the git output should be returned from Git::Base#write_tree
31
+ assert_equal ( git_output , result )
32
+ end
33
+
34
+ def test_commit_tree_with_default_message
35
+ tree = 'tree-ref'
36
+
37
+ expected_message = 'commit tree tree-ref'
38
+ tempfile_path = 'foo'
39
+ mock_tempfile = mock ( 'tempfile' )
40
+ Tempfile . stubs ( :new ) . returns ( mock_tempfile )
41
+ mock_tempfile . stubs ( :path ) . returns ( tempfile_path )
42
+ mock_tempfile . expects ( :write ) . with ( expected_message )
43
+ mock_tempfile . expects ( :close )
44
+
45
+ redirect_value = windows_platform? ? "< \" #{ tempfile_path } \" " : "< '#{ tempfile_path } '"
46
+
47
+ expected_command_line = [ 'commit-tree' , tree , redirect : redirect_value ]
48
+ git_cmd = :commit_tree
49
+ git_cmd_args = [ tree ]
50
+ assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
51
+ end
52
+
53
+ def test_commit_tree_with_message
54
+ tree = 'tree-ref'
55
+ message = 'this is my message'
56
+
57
+ tempfile_path = 'foo'
58
+ mock_tempfile = mock ( 'tempfile' )
59
+ Tempfile . stubs ( :new ) . returns ( mock_tempfile )
60
+ mock_tempfile . stubs ( :path ) . returns ( tempfile_path )
61
+ mock_tempfile . expects ( :write ) . with ( message )
62
+ mock_tempfile . expects ( :close )
63
+
64
+ redirect_value = windows_platform? ? "< \" #{ tempfile_path } \" " : "< '#{ tempfile_path } '"
65
+
66
+ expected_command_line = [ 'commit-tree' , tree , redirect : redirect_value ]
67
+ git_cmd = :commit_tree
68
+ git_cmd_args = [ tree , message : message ]
69
+ assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
70
+ end
71
+
72
+ def test_commit_tree_with_parent
73
+ tree = 'tree-ref'
74
+ message = 'this is my message'
75
+ parent = 'parent-commit'
76
+
77
+ tempfile_path = 'foo'
78
+ mock_tempfile = mock ( 'tempfile' )
79
+ Tempfile . stubs ( :new ) . returns ( mock_tempfile )
80
+ mock_tempfile . stubs ( :path ) . returns ( tempfile_path )
81
+ mock_tempfile . expects ( :write ) . with ( message )
82
+ mock_tempfile . expects ( :close )
83
+
84
+ redirect_value = windows_platform? ? "< \" #{ tempfile_path } \" " : "< '#{ tempfile_path } '"
85
+
86
+ expected_command_line = [ 'commit-tree' , tree , "-p" , parent , redirect : redirect_value ]
87
+ git_cmd = :commit_tree
88
+ git_cmd_args = [ tree , parent : parent , message : message ]
89
+
90
+ assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
91
+ end
92
+
93
+ def test_commit_tree_with_parents
94
+ tree = 'tree-ref'
95
+ message = 'this is my message'
96
+ parents = 'commit1'
97
+
98
+ tempfile_path = 'foo'
99
+ mock_tempfile = mock ( 'tempfile' )
100
+ Tempfile . stubs ( :new ) . returns ( mock_tempfile )
101
+ mock_tempfile . stubs ( :path ) . returns ( tempfile_path )
102
+ mock_tempfile . expects ( :write ) . with ( message )
103
+ mock_tempfile . expects ( :close )
104
+
105
+ redirect_value = windows_platform? ? "< \" #{ tempfile_path } \" " : "< '#{ tempfile_path } '"
106
+
107
+ expected_command_line = [ 'commit-tree' , tree , '-p' , 'commit1' , redirect : redirect_value ]
108
+ git_cmd = :commit_tree
109
+ git_cmd_args = [ tree , parents : parents , message : message ]
110
+
111
+ assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
112
+ end
113
+
114
+ def test_commit_tree_with_multiple_parents
115
+ tree = 'tree-ref'
116
+ message = 'this is my message'
117
+ parents = [ 'commit1' , 'commit2' ]
118
+
119
+ tempfile_path = 'foo'
120
+ mock_tempfile = mock ( 'tempfile' )
121
+ Tempfile . stubs ( :new ) . returns ( mock_tempfile )
122
+ mock_tempfile . stubs ( :path ) . returns ( tempfile_path )
123
+ mock_tempfile . expects ( :write ) . with ( message )
124
+ mock_tempfile . expects ( :close )
125
+
126
+ redirect_value = windows_platform? ? "< \" #{ tempfile_path } \" " : "< '#{ tempfile_path } '"
127
+
128
+ expected_command_line = [ 'commit-tree' , tree , '-p' , 'commit1' , '-p' , 'commit2' , redirect : redirect_value ]
129
+ git_cmd = :commit_tree
130
+ git_cmd_args = [ tree , parents : parents , message : message ]
131
+
132
+ assert_command_line ( expected_command_line , git_cmd , git_cmd_args )
133
+ end
134
+
135
+ def test_tree_ops
8
136
in_bare_repo_clone do |g |
9
137
g . branch ( 'testbranch1' ) . in_branch ( 'tb commit 1' ) do
10
138
new_file ( 'test-file1' , 'blahblahblah2' )
@@ -79,12 +207,7 @@ def test_read_tree
79
207
assert ( c . commit? )
80
208
assert_equal ( 'b40f7a9072cdec637725700668f8fdebe39e6d38' , c . gtree . sha )
81
209
82
- tmp = Tempfile . new ( 'tesxt' )
83
- tmppath = tmp . path
84
- tmp . close
85
- tmp . unlink
86
-
87
- g . with_index ( tmppath ) do
210
+ g . with_temp_index do
88
211
g . read_tree ( 'testbranch1' , :prefix => 'b1/' )
89
212
g . read_tree ( 'testbranch3' , :prefix => 'b3/' )
90
213
index = g . ls_files
@@ -111,7 +234,6 @@ def test_read_tree
111
234
g . checkout_index ( :all => true )
112
235
assert ( File . directory? ( 'b1' ) )
113
236
end
114
-
115
237
end
116
238
end
117
239
end
0 commit comments