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 @@ -264,6 +264,12 @@ def reset_hard(commitish = nil, opts = {})
264
264
self . lib . reset ( commitish , opts )
265
265
end
266
266
267
+
268
+ # cleans the working directory, removing directories, too.
269
+ def clean ( opts = { } )
270
+ self . lib . clean ( opts )
271
+ end
272
+
267
273
# commits all pending changes in the index file to the git repository
268
274
#
269
275
# options:
Original file line number Diff line number Diff line change @@ -429,7 +429,13 @@ def reset(commit, opts = {})
429
429
arr_opts << commit if commit
430
430
command ( 'reset' , arr_opts )
431
431
end
432
-
432
+
433
+ def clean ( opts = { } )
434
+ arr_opts = [ "--force" ] # Some configurations require a --force
435
+ arr_opts << [ "-d" ] # Remove untracked directories in addition to untracked files.
436
+ command ( 'clean' , arr_opts )
437
+ end
438
+
433
439
def apply ( patch_file )
434
440
arr_opts = [ ]
435
441
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