From 73193705c5753a845f589db03ac5a0022b43a693 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 30 Jul 2026 11:25:08 +1000 Subject: [PATCH 1/2] Sandbox the global git config in git-lfs specs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `git lfs install` and `git lfs uninstall` default to the global scope, so these two examples were writing to — and then deleting — the `[filter "lfs"]` section of the developer's real `~/.gitconfig` on every run of the suite. Passing `--local` would not have been enough: `has_git_lfs?` reads every config scope, so the negative example would start failing on any machine that legitimately has global git-lfs filters configured. Pointing `GIT_CONFIG_GLOBAL` at a throwaway file keeps both examples exercising the same code path while confining the writes. --- Generated with the help of Claude Code, https://claude.ai/code Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 2 +- spec/git_helper_spec.rb | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a44445e4..a84c1250f 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. ## 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 .` From 744a4e0203f1eecce6a940ba153c0b2c7cb22314 Mon Sep 17 00:00:00 2001 From: Gio Lodi Date: Thu, 30 Jul 2026 11:25:48 +1000 Subject: [PATCH 2/2] Reference the PR in the CHANGELOG entry --- Generated with the help of Claude Code, https://claude.ai/code Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a84c1250f..73dd661a1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -18,7 +18,7 @@ _None_ ### Internal Changes -- 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. +- 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