File tree 3 files changed +38
-2
lines changed 3 files changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -280,6 +280,12 @@ def reset_hard(commitish = nil, opts = {})
280
280
self . lib . reset ( commitish , opts )
281
281
end
282
282
283
+
284
+ # cleans the working directory, removing directories, too.
285
+ def clean ( opts = { } )
286
+ self . lib . clean ( opts )
287
+ end
288
+
283
289
# commits all pending changes in the index file to the git repository
284
290
#
285
291
# options:
Original file line number Diff line number Diff line change @@ -420,7 +420,13 @@ def reset(commit, opts = {})
420
420
arr_opts << commit if commit
421
421
command ( 'reset' , arr_opts )
422
422
end
423
-
423
+
424
+ def clean ( opts = { } )
425
+ arr_opts = [ "--force" ] # Some configurations require a --force
426
+ arr_opts << [ "-d" ] # Remove untracked directories in addition to untracked files.
427
+ command ( 'clean' , arr_opts )
428
+ end
429
+
424
430
def apply ( patch_file )
425
431
arr_opts = [ ]
426
432
arr_opts << '--' << patch_file if patch_file
Original file line number Diff line number Diff line change @@ -37,7 +37,31 @@ def test_add
37
37
end
38
38
end
39
39
end
40
-
40
+
41
+ def test_clean
42
+ in_temp_dir do |path |
43
+ g = Git . clone ( @wbare , 'clean_me' )
44
+ Dir . chdir ( 'clean_me' ) do
45
+ new_file ( 'test-file' , 'blahblahbal' )
46
+ g . add
47
+ g . commit ( "first commit" )
48
+
49
+ new_file ( 'file-to-clean' , 'blablahbla' )
50
+ FileUtils . mkdir_p ( "dir_to_clean" )
51
+
52
+ Dir . chdir ( 'dir_to_clean' ) do
53
+ new_file ( 'clean-me-too' , 'blablahbla' )
54
+ end
55
+
56
+ assert ( File . exists? ( 'file-to-clean' ) )
57
+ assert ( File . exists? ( 'dir_to_clean' ) )
58
+ g . clean
59
+ assert ( !File . exists? ( 'file-to-clean' ) )
60
+ assert ( !File . exists? ( 'dir_to_clean' ) )
61
+ end
62
+ end
63
+ end
64
+
41
65
def test_add_array
42
66
in_temp_dir do |path |
43
67
g = Git . clone ( @wbare , 'new' )
You can’t perform that action at this time.
0 commit comments