Use Homebrew's gitconfig for various commands
Git is a transport and storage mechanism for us so we don't want to allow arbitrary customisation of this due to user issues e.g. #3664 and #3561. Fixes #3664.
This commit is contained in:
		
							parent
							
								
									02591bdf34
								
							
						
					
					
						commit
						228cbd81c9
					
				@ -39,6 +39,6 @@ module Homebrew
 | 
			
		||||
    end
 | 
			
		||||
    args = ARGV.options_only
 | 
			
		||||
    args += ["--follow", "--", path] unless path.nil?
 | 
			
		||||
    exec "git", "log", *args
 | 
			
		||||
    Utils.with_homebrew_gitconfig { exec "git", "log", *args }
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -28,6 +28,8 @@ EOS
 | 
			
		||||
    set -x
 | 
			
		||||
  fi
 | 
			
		||||
 | 
			
		||||
  export HOME="$HOMEBREW_LIBRARY/Homebrew/gitconfig"
 | 
			
		||||
 | 
			
		||||
  for DIR in "$HOMEBREW_REPOSITORY" "$HOMEBREW_LIBRARY"/Taps/*/*
 | 
			
		||||
  do
 | 
			
		||||
    [[ -d "$DIR/.git" ]] || continue
 | 
			
		||||
 | 
			
		||||
@ -19,7 +19,11 @@ git() {
 | 
			
		||||
  then
 | 
			
		||||
    GIT_EXECUTABLE="$("$HOMEBREW_LIBRARY/Homebrew/shims/scm/git" --homebrew=print-path)"
 | 
			
		||||
  fi
 | 
			
		||||
  OLDHOME="$HOME"
 | 
			
		||||
  export HOME="$HOMEBREW_LIBRARY/Homebrew/gitconfig"
 | 
			
		||||
  "$GIT_EXECUTABLE" "$@"
 | 
			
		||||
  export HOME="$OLDHOME"
 | 
			
		||||
  unset OLDHOME
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
git_init_if_necessary() {
 | 
			
		||||
 | 
			
		||||
@ -793,15 +793,19 @@ class GitDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
  def update_repo
 | 
			
		||||
    return unless @ref_type == :branch || !ref?
 | 
			
		||||
 | 
			
		||||
    if !shallow_clone? && shallow_dir?
 | 
			
		||||
      quiet_safe_system "git", "fetch", "origin", "--unshallow"
 | 
			
		||||
    else
 | 
			
		||||
      quiet_safe_system "git", "fetch", "origin"
 | 
			
		||||
    Utils.with_homebrew_gitconfig do
 | 
			
		||||
      if !shallow_clone? && shallow_dir?
 | 
			
		||||
        quiet_safe_system "git", "fetch", "origin", "--unshallow"
 | 
			
		||||
      else
 | 
			
		||||
        quiet_safe_system "git", "fetch", "origin"
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def clone_repo
 | 
			
		||||
    safe_system "git", *clone_args
 | 
			
		||||
    Utils.with_homebrew_gitconfig do
 | 
			
		||||
      safe_system "git", *clone_args
 | 
			
		||||
    end
 | 
			
		||||
    cached_location.cd do
 | 
			
		||||
      safe_system "git", "config", "homebrew.cacheversion", cache_version
 | 
			
		||||
      checkout
 | 
			
		||||
@ -811,7 +815,9 @@ class GitDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
 | 
			
		||||
  def checkout
 | 
			
		||||
    ohai "Checking out #{@ref_type} #{@ref}" if @ref_type && @ref
 | 
			
		||||
    quiet_safe_system "git", "checkout", "-f", @ref, "--"
 | 
			
		||||
    Utils.with_homebrew_gitconfig do
 | 
			
		||||
      quiet_safe_system "git", "checkout", "-f", @ref, "--"
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def reset_args
 | 
			
		||||
@ -830,8 +836,10 @@ class GitDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def update_submodules
 | 
			
		||||
    quiet_safe_system "git", "submodule", "foreach", "--recursive", "git submodule sync"
 | 
			
		||||
    quiet_safe_system "git", "submodule", "update", "--init", "--recursive"
 | 
			
		||||
    Utils.with_homebrew_gitconfig do
 | 
			
		||||
      quiet_safe_system "git", "submodule", "foreach", "--recursive", "git submodule sync"
 | 
			
		||||
      quiet_safe_system "git", "submodule", "update", "--init", "--recursive"
 | 
			
		||||
    end
 | 
			
		||||
    fix_absolute_submodule_gitdir_references!
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
							
								
								
									
										14
									
								
								Library/Homebrew/gitconfig/.gitconfig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								Library/Homebrew/gitconfig/.gitconfig
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,14 @@
 | 
			
		||||
[user]
 | 
			
		||||
	# Name used in commit messages.
 | 
			
		||||
	name = Homebrew
 | 
			
		||||
	# Email used in commit messages.
 | 
			
		||||
	email = git@brew.sh
 | 
			
		||||
[fetch]
 | 
			
		||||
	# Always prune when fetching (and pulling).
 | 
			
		||||
	prune = 1
 | 
			
		||||
[core]
 | 
			
		||||
	# Don't prompt for commit messages for merge commits.
 | 
			
		||||
	mergeoptions = --no-edit
 | 
			
		||||
[credential]
 | 
			
		||||
	# Use macOS Keychain to store HTTP passwords.
 | 
			
		||||
	helper = osxkeychain
 | 
			
		||||
@ -230,7 +230,7 @@ class Tap
 | 
			
		||||
      ohai "Unshallowing #{name}" unless quiet
 | 
			
		||||
      args = %w[fetch --unshallow]
 | 
			
		||||
      args << "-q" if quiet
 | 
			
		||||
      path.cd { safe_system "git", *args }
 | 
			
		||||
      Utils.with_homebrew_gitconfig { path.cd { safe_system "git", *args } }
 | 
			
		||||
      return
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -242,7 +242,7 @@ class Tap
 | 
			
		||||
    args << "-q" if quiet
 | 
			
		||||
 | 
			
		||||
    begin
 | 
			
		||||
      safe_system "git", *args
 | 
			
		||||
      Utils.with_homebrew_gitconfig { safe_system "git", *args }
 | 
			
		||||
      unless Readall.valid_tap?(self, aliases: true)
 | 
			
		||||
        unless ARGV.homebrew_developer?
 | 
			
		||||
          raise "Cannot tap #{name}: invalid syntax in tap!"
 | 
			
		||||
 | 
			
		||||
@ -60,6 +60,12 @@ module Utils
 | 
			
		||||
    raise "Git is unavailable" unless git_available?
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def self.with_homebrew_gitconfig
 | 
			
		||||
    with_env(HOME: HOMEBREW_LIBRARY/"Homebrew/gitconfig") do
 | 
			
		||||
      yield if block_given?
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def self.clear_git_available_cache
 | 
			
		||||
    @git = nil
 | 
			
		||||
    @git_path = nil
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user