Skip to content

Commit 64586c3

Browse files
committed
(GH-585/CONT-998) Update safe directory to be set at the system level
Safe directory is now set at a system wide level rather than at a global user level in order to ensure it is as effective as possible.
1 parent 04d5e68 commit 64586c3

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-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: 3 additions & 3 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')
@@ -617,7 +617,7 @@ def update_safe_directory
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

spec/acceptance/clone_repo_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@
239239
it { is_expected.to be_owned_by 'vagrant' }
240240
end
241241

242-
describe file('~/.gitconfig') do
242+
describe file('/etc/gitconfig') do
243243
subject { super().content }
244244

245245
it { is_expected.to match %r{directory = /tmp/vcsrepo/testrepo_owner} }

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)