diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a44445e4..73dd661a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ _None_ ### Internal Changes -_None_ +- Run the `GitHelper` git-lfs specs against a sandboxed `GIT_CONFIG_GLOBAL` so they no longer remove the `[filter "lfs"]` section from the developer's global git config. [#762] ## 14.11.1 diff --git a/spec/git_helper_spec.rb b/spec/git_helper_spec.rb index 787f5edf1..b1bdcb430 100644 --- a/spec/git_helper_spec.rb +++ b/spec/git_helper_spec.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'tempfile' require 'tmpdir' require_relative 'spec_helper' @@ -57,15 +58,19 @@ it 'can detect a repository with Git-lfs enabled' do init_git_repo - `git lfs install` - expect(described_class.has_git_lfs?).to be true + with_sandboxed_global_git_config do + `git lfs install` + expect(described_class.has_git_lfs?).to be true + end end it 'can detect a repository without Git-lfs enabled' do init_git_repo - `git lfs uninstall &>/dev/null` - expect(described_class.is_git_repo?).to be true - expect(described_class.has_git_lfs?).to be false + with_sandboxed_global_git_config do + `git lfs uninstall &>/dev/null` + expect(described_class.is_git_repo?).to be true + expect(described_class.has_git_lfs?).to be false + end end describe 'commit(message:, files:)' do @@ -262,6 +267,18 @@ def init_git_repo `git init --initial-branch main || git init` end +# `git lfs install` and `git lfs uninstall` write to the global scope unless told +# otherwise, so without this the examples edit the developer's real `~/.gitconfig`. +def with_sandboxed_global_git_config + Tempfile.create('gitconfig') do |file| + original = ENV['GIT_CONFIG_GLOBAL'] + ENV['GIT_CONFIG_GLOBAL'] = file.path + yield + ensure + ENV['GIT_CONFIG_GLOBAL'] = original + end +end + def add_file_and_commit(file:, message:) `touch #{file}` `git add .`