@@ -159,4 +159,49 @@ def test_git_clone_with_no_name
159
159
160
160
assert_equal ( expected_command_line , actual_command_line )
161
161
end
162
+
163
+ test 'clone with negative depth' do
164
+ repository_url = 'https://github.com/ruby-git/ruby-git.git'
165
+ destination = 'ruby-git'
166
+
167
+ actual_command_line = nil
168
+
169
+ in_temp_dir do |path |
170
+ # Give a bare repository with a single commit
171
+ repository_path = File . join ( path , 'repository.git' )
172
+ Git . init ( repository_path , :bare => true )
173
+ worktree_path = File . join ( path , 'repository' )
174
+ worktree = Git . clone ( repository_path , worktree_path )
175
+ File . write ( File . join ( worktree_path , 'test.txt' ) , 'test' )
176
+ worktree . add ( 'test.txt' )
177
+ worktree . commit ( 'Initial commit' )
178
+ worktree . push
179
+ FileUtils . rm_rf ( worktree_path )
180
+
181
+ # When I clone it with a negative depth with
182
+ error = assert_raises ( Git ::FailedError ) do
183
+ Git . clone ( repository_path , worktree , depth : -1 )
184
+ end
185
+
186
+ assert_match ( /depth/ , error . result . stderr )
187
+ end
188
+
189
+ # git = Git.init('.')
190
+
191
+ # # Mock the Git::Lib#command method to capture the actual command line args
192
+ # git.lib.define_singleton_method(:command) do |cmd, *opts, &block|
193
+ # actual_command_line = [cmd, *opts.flatten]
194
+ # end
195
+
196
+ # git.lib.clone(repository_url, destination, depth: -1)
197
+ # end
198
+
199
+ # expected_command_line = [
200
+ # 'clone',
201
+ # '--depth', '-1',
202
+ # '--', repository_url, destination, {timeout: nil}
203
+ # ]
204
+
205
+ # assert_equal(expected_command_line, actual_command_line)
206
+ end
162
207
end
0 commit comments