Skip to content

Commit 7c3948a

Browse files
committed
Add -ff option to git clean
Git will refuse to modify untracked nested git repositories (directories with a .git subdirectory) unless a second -f is given. This adds the ability to pass "-ff" to git clean to enable removing directories with a .git subdirectory. An example use case is when a gem from a git source is cached in vendor/cache/some_gem Removing this with "git clean" would require "git clean -dff" Signed-off-by: Cameron Walsh <cameron.walsh@gmail.com>
1 parent 58100b0 commit 7c3948a

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

lib/git/base.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,7 @@ def reset_hard(commitish = nil, opts = {})
287287
# options:
288288
# :force
289289
# :d
290+
# :ff
290291
#
291292
def clean(opts = {})
292293
self.lib.clean(opts)

lib/git/lib.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ def reset(commit, opts = {})
682682
def clean(opts = {})
683683
arr_opts = []
684684
arr_opts << '--force' if opts[:force]
685+
arr_opts << '-ff' if opts[:ff]
685686
arr_opts << '-d' if opts[:d]
686687
arr_opts << '-x' if opts[:x]
687688

tests/units/test_index_ops.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ def test_clean
4949
g.add
5050
g.commit("first commit")
5151

52+
FileUtils.mkdir_p("nested")
53+
Dir.chdir('nested') do
54+
Git.init
55+
end
56+
5257
new_file('file-to-clean', 'blablahbla')
5358
FileUtils.mkdir_p("dir_to_clean")
5459

@@ -76,6 +81,11 @@ def test_clean
7681

7782
g.clean(:force => true, :x => true)
7883
assert(!File.exist?('ignored_file'))
84+
85+
assert(File.exist?('nested'))
86+
87+
g.clean(:ff => true, :d => true)
88+
assert(!File.exist?('nested'))
7989
end
8090
end
8191
end

0 commit comments

Comments
 (0)