Skip to content

Commit f9c9ce7

Browse files
Merge branch 'git-clean' of git://github.com/fasttracktool-dev/ruby-git into fasttracktool-dev-git-clean
2 parents dac73b7 + 3ec51b6 commit f9c9ce7

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

lib/git/base.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,12 @@ def reset_hard(commitish = nil, opts = {})
280280
self.lib.reset(commitish, opts)
281281
end
282282

283+
284+
# cleans the working directory, removing directories, too.
285+
def clean(opts = {})
286+
self.lib.clean(opts)
287+
end
288+
283289
# commits all pending changes in the index file to the git repository
284290
#
285291
# options:

lib/git/lib.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,13 @@ def reset(commit, opts = {})
420420
arr_opts << commit if commit
421421
command('reset', arr_opts)
422422
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+
424430
def apply(patch_file)
425431
arr_opts = []
426432
arr_opts << '--' << patch_file if patch_file

tests/units/test_index_ops.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,31 @@ def test_add
3737
end
3838
end
3939
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+
4165
def test_add_array
4266
in_temp_dir do |path|
4367
g = Git.clone(@wbare, 'new')

0 commit comments

Comments
 (0)