Skip to content

Conversation

@mdelapenya
Copy link

@mdelapenya mdelapenya commented Oct 27, 2025

This change makes the config loader respect the environment variables GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM (if set) for Global and System scopes respectively. It also adds unit tests verifying the env-var behavior and precedence:

  • Tests for GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM in config/config_test.go.
  • A precedence test covering GIT_CONFIG_GLOBAL > XDG_CONFIG_HOME > HOME/.gitconfig.
  • A repository-level precedence test for local > global > system via Repository.ConfigScoped(SystemScope).

This mirrors git's behavior as documented in the git-config manual (ENVIRONMENT section): https://git-scm.com/docs/git-config#ENVIRONMENT

The env vars are preferred (placed before defaults) and existing fallback behavior is preserved.

Closes #1701

Copilot AI review requested due to automatic review settings October 27, 2025 13:50
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for the GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM environment variables to mirror git's native behavior, allowing users and tests to redirect config file locations. The changes modify the config loader to check these environment variables before falling back to default paths.

Key changes:

  • Modified Paths() function to check and honor GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM environment variables
  • Added comprehensive unit tests verifying environment variable behavior and config precedence rules
  • Tests validate the precedence order: GIT_CONFIG_GLOBAL > XDG_CONFIG_HOME > HOME/.gitconfig for global scope, and local > global > system for repository-scoped configs

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
config/config.go Added environment variable checks in Paths() for GIT_CONFIG_GLOBAL and GIT_CONFIG_SYSTEM
config/config_test.go Added three test cases verifying env var behavior and precedence rules for global and system scopes
repository_test.go Added integration test verifying repository-level config precedence across system, global, and local scopes

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Manuel de la Peña <social.mdelapenya@gmail.com>
@mdelapenya mdelapenya requested a review from Copilot October 27, 2025 13:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

config/config.go:208

  • The closing brace on line 302 closes the entire switch statement, but it should only close the SystemScope case. The switch statement is missing its closing brace. This would cause a compilation error.
	}
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

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.

GIT_CONFIG_SYSTEM and GIT_CONFIG_GLOBAL are not supported

1 participant