Skip to content

Commit f962d15

Browse files
authored
Merge pull request #605 from david22swan/GH-585--CONT-998/main/unsafe_directoryfix
(GH-585/CONT-998) Fix for safe_directory logic
2 parents 9bcaa6b + 64586c3 commit f962d15

File tree

4 files changed

+19
-5
lines changed

4 files changed

+19
-5
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,8 @@ For example, setting the `owner` parameter on a resource would cause Puppet runs
864864
Impacted users are now advised to use the new `safe_directory` parameter on Git resources.
865865
Explicitily setting the value to `true` will add the current path specified on the resource to the `safe.directory` git configuration for the current user (global scope) allowing the Puppet run to continue without error.
866866

867+
Safe directory configuration will be stored within the system wide configuration file `/etc/gitconfig`.
868+
867869
<a id="development"></a>
868870
## Development
869871

lib/puppet/provider/vcsrepo/git.rb

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ def git_version
591591

592592
# @!visibility private
593593
def safe_directories
594-
args = ['config', '--global', '--get-all', 'safe.directory']
594+
args = ['config', '--system', '--get-all', 'safe.directory']
595595
begin
596596
d = git_with_identity(*args) || ''
597597
d.split('\n')
@@ -609,15 +609,15 @@ def update_safe_directory
609609

610610
if should_add_safe_directory?
611611
add_safe_directory
612-
else
612+
elsif should_remove_safe_directory?
613613
remove_safe_directory
614614
end
615615
end
616616

617617
# @!visibility private
618618
def add_safe_directory
619619
notice("Adding '#{@resource.value(:path)}' to safe directory list")
620-
args = ['config', '--global', '--add', 'safe.directory', @resource.value(:path)]
620+
args = ['config', '--system', '--add', 'safe.directory', @resource.value(:path)]
621621
git_with_identity(*args)
622622
end
623623

@@ -626,7 +626,7 @@ def remove_safe_directory
626626
return unless safe_directories.include?(@resource.value(:path))
627627

628628
notice("Removing '#{@resource.value(:path)}' from safe directory list")
629-
args = ['config', '--global', '--unset', 'safe.directory', @resource.value(:path)]
629+
args = ['config', '--system', '--unset', 'safe.directory', @resource.value(:path)]
630630
git_with_identity(*args)
631631
end
632632

@@ -637,6 +637,12 @@ def should_add_safe_directory?
637637
!safe_directories.include?(@resource.value(:path)) # directory should not already be in the list
638638
end
639639

640+
# @!visibility private
641+
def should_remove_safe_directory?
642+
!@resource.value(:safe_directory) && # safe_directory should be false
643+
safe_directories.include?(@resource.value(:path)) # directory should be in the list
644+
end
645+
640646
# @!visibility private
641647
def git_remote_action(*args)
642648
proxy = @resource.value(:http_proxy)

spec/acceptance/clone_repo_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,12 @@
238238
it { is_expected.to be_directory }
239239
it { is_expected.to be_owned_by 'vagrant' }
240240
end
241+
242+
describe file('/etc/gitconfig') do
243+
subject { super().content }
244+
245+
it { is_expected.to match %r{directory = /tmp/vcsrepo/testrepo_owner} }
246+
end
241247
end
242248

243249
context 'with with a group' do

spec/unit/puppet/provider/vcsrepo/git_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ def branch_a_list(include_branch = nil?)
253253
expect(provider).to receive(:path_exists?).and_return(true)
254254
expect(provider).to receive(:path_empty?).and_return(false)
255255
provider.destroy
256-
expect(provider).to receive(:exec_git).with('config', '--global', '--get-all', 'safe.directory')
256+
expect(provider).to receive(:exec_git).with('config', '--system', '--get-all', 'safe.directory')
257257
expect(provider).to receive(:exec_git).with('clone', resource.value(:source), resource.value(:path))
258258
expect(provider).to receive(:update_submodules)
259259
expect(provider).to receive(:update_remote_url).with('origin', resource.value(:source)).and_return false

0 commit comments

Comments
 (0)