From bc10fa1fadccd64a8d5b89e76af08172cfbe8e65 Mon Sep 17 00:00:00 2001 From: DIERCKXK Date: Wed, 10 Aug 2022 12:19:38 +0200 Subject: [PATCH 1/3] Only remove safe_directory, if it exists --- lib/puppet/provider/vcsrepo/git.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index 08c4651b..ef12cad4 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -42,7 +42,7 @@ def create end def destroy - remove_safe_directory if safe_directories.include?(@resource.value(:path)) + remove_safe_directory FileUtils.rm_rf(@resource.value(:path)) end @@ -167,7 +167,7 @@ def update_remote_url(remote_name, remote_url) git_with_identity('remote', 'add', remote_name, remote_url) true - # If remote exists, but URL doesn't match, update URL + # If remote exists, but URL doesn't match, update URL elsif !current.include? "remote.#{remote_name}.url=#{remote_url}" git_with_identity('remote', 'set-url', remote_name, remote_url) true @@ -642,9 +642,11 @@ def add_safe_directory # @!visibility private def remove_safe_directory - notice("Removing '#{@resource.value(:path)}' from safe directory list") - args = ['config', '--global', '--unset', 'safe.directory', @resource.value(:path)] - git_with_identity(*args) + if safe_directories.include?(@resource.value(:path)) + notice("Removing '#{@resource.value(:path)}' from safe directory list") + args = ['config', '--global', '--unset', 'safe.directory', @resource.value(:path)] + git_with_identity(*args) + end end # @!visibility private From ba2cddab4f7deecb4250b4e4fd107037204cf827 Mon Sep 17 00:00:00 2001 From: DIERCKXK Date: Thu, 11 Aug 2022 07:25:44 +0200 Subject: [PATCH 2/3] use a guard clause --- lib/puppet/provider/vcsrepo/git.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index ef12cad4..cd2aa11b 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -642,11 +642,11 @@ def add_safe_directory # @!visibility private def remove_safe_directory - if safe_directories.include?(@resource.value(:path)) - notice("Removing '#{@resource.value(:path)}' from safe directory list") - args = ['config', '--global', '--unset', 'safe.directory', @resource.value(:path)] - git_with_identity(*args) - end + return if safe_directories.include?(@resource.value(:path)) + + notice("Removing '#{@resource.value(:path)}' from safe directory list") + args = ['config', '--global', '--unset', 'safe.directory', @resource.value(:path)] + git_with_identity(*args) end # @!visibility private From c380b02a20f41c9f0b0ea676c3cec8905f4480bb Mon Sep 17 00:00:00 2001 From: DIERCKXK Date: Wed, 17 Aug 2022 10:20:47 +0200 Subject: [PATCH 3/3] fixed the guard clause --- lib/puppet/provider/vcsrepo/git.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/puppet/provider/vcsrepo/git.rb b/lib/puppet/provider/vcsrepo/git.rb index cd2aa11b..d1b3f186 100644 --- a/lib/puppet/provider/vcsrepo/git.rb +++ b/lib/puppet/provider/vcsrepo/git.rb @@ -642,7 +642,7 @@ def add_safe_directory # @!visibility private def remove_safe_directory - return if safe_directories.include?(@resource.value(:path)) + return unless safe_directories.include?(@resource.value(:path)) notice("Removing '#{@resource.value(:path)}' from safe directory list") args = ['config', '--global', '--unset', 'safe.directory', @resource.value(:path)]