From e46c5c5c032fa1b30d023f300f3e1f0aace9cfcb Mon Sep 17 00:00:00 2001 From: Cameron Walsh Date: Mon, 12 Jul 2021 12:00:13 +1000 Subject: [PATCH] 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 --- lib/git/base.rb | 1 + lib/git/lib.rb | 1 + tests/units/test_index_ops.rb | 10 ++++++++++ 3 files changed, 12 insertions(+) diff --git a/lib/git/base.rb b/lib/git/base.rb index 6e7c7a10..75822530 100644 --- a/lib/git/base.rb +++ b/lib/git/base.rb @@ -287,6 +287,7 @@ def reset_hard(commitish = nil, opts = {}) # options: # :force # :d + # :ff # def clean(opts = {}) self.lib.clean(opts) diff --git a/lib/git/lib.rb b/lib/git/lib.rb index 57220f07..adfdf9d7 100644 --- a/lib/git/lib.rb +++ b/lib/git/lib.rb @@ -682,6 +682,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] diff --git a/tests/units/test_index_ops.rb b/tests/units/test_index_ops.rb index fd47e609..c033735b 100644 --- a/tests/units/test_index_ops.rb +++ b/tests/units/test_index_ops.rb @@ -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") @@ -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