Skip to content

Commit

Permalink
Add -ff option to git clean (#529)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cwalsh committed Dec 17, 2021
1 parent 984ff7f commit 3884314
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/git/base.rb
Expand Up @@ -290,6 +290,7 @@ def reset_hard(commitish = nil, opts = {})
# options:
# :force
# :d
# :ff
#
def clean(opts = {})
self.lib.clean(opts)
Expand Down
1 change: 1 addition & 0 deletions lib/git/lib.rb
Expand Up @@ -684,6 +684,7 @@ def reset(commit, opts = {})
def clean(opts = {})
arr_opts = []
arr_opts << '--force' if opts[:force]
arr_opts << '-ff' if opts[:ff]
arr_opts << '-d' if opts[:d]
arr_opts << '-x' if opts[:x]

Expand Down
10 changes: 10 additions & 0 deletions tests/units/test_index_ops.rb
Expand Up @@ -49,6 +49,11 @@ def test_clean
g.add
g.commit("first commit")

FileUtils.mkdir_p("nested")
Dir.chdir('nested') do
Git.init
end

new_file('file-to-clean', 'blablahbla')
FileUtils.mkdir_p("dir_to_clean")

Expand Down Expand Up @@ -76,6 +81,11 @@ def test_clean

g.clean(:force => true, :x => true)
assert(!File.exist?('ignored_file'))

assert(File.exist?('nested'))

g.clean(:ff => true, :d => true)
assert(!File.exist?('nested'))
end
end
end
Expand Down

0 comments on commit 3884314

Please sign in to comment.