Skip to content

Conversation

@anmarchenko
Copy link
Member

@anmarchenko anmarchenko commented Jan 13, 2026

Summary

  • Replaced proactive global git config modification with per-command -c safe.directory=<path> flag
  • Added getSafeDirectoryConfig() function that caches the repository root path (via sync.Once)
  • Updated execGit() and execGitStringWithInput() to automatically include the safe.directory config
  • Removed the code in getLocalGitData() that was adding entries to global git config

Why

The previous approach modified the global git config by running:

git config --global --add safe.directory <path>

This caused several problems:

  1. Config pollution: Using --add creates duplicate entries on repeated runs
  2. Security: Modifying global config affects all repositories, not just the current one
  3. Persistence: Changes remain after the tool finishes running

Solution

Instead of modifying global config, we now pass safe.directory as a command-line config override:

git -c safe.directory=/path/to/repo <command>

Benefits:

  • No modification to any config files (global, local, or system)
  • Only affects the single command execution
  • Cannot cause config pollution
  • More secure (isolated to single invocation)
  • Repository root is cached via sync.Once for performance

Test plan

  • All existing tests pass (make test)
  • Smoke testing with local git repository
  • Manual testing in CI environment with different file ownership (e.g., Docker container)

@anmarchenko anmarchenko requested a review from a team as a code owner January 13, 2026 09:18
@anmarchenko anmarchenko changed the title Use -c flag for git safe.directory instead of modifying global config [SDTEST-3223] Use -c flag for git safe.directory instead of modifying global config Jan 13, 2026
Copy link
Member

@tonyredondo tonyredondo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👨🏻‍🍳 :shipit:

@anmarchenko anmarchenko merged commit c59e6f5 into main Jan 13, 2026
3 checks passed
@anmarchenko anmarchenko deleted the anmarchenko/fix_safe_directory_issue branch January 13, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants