2021-01-12 16:27:25 -05:00
|
|
|
# typed: true
|
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2021-05-12 16:07:47 +01:00
|
|
|
require "utils/popen"
|
2021-04-14 14:21:16 +01:00
|
|
|
|
2021-01-13 11:16:09 -05:00
|
|
|
module Homebrew
|
|
|
|
# Helper functions for reading and writing settings.
|
|
|
|
#
|
|
|
|
# @api private
|
|
|
|
module Settings
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.read(setting, repo: HOMEBREW_REPOSITORY)
|
2021-01-13 11:16:09 -05:00
|
|
|
return unless (repo/".git/config").exist?
|
|
|
|
|
2021-05-12 16:07:47 +01:00
|
|
|
value = Utils.popen_read("git", "-C", repo.to_s, "config", "--get", "homebrew.#{setting}").chomp
|
|
|
|
|
|
|
|
return if value.strip.empty?
|
|
|
|
|
|
|
|
value
|
2021-01-12 16:27:25 -05:00
|
|
|
end
|
|
|
|
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.write(setting, value, repo: HOMEBREW_REPOSITORY)
|
2021-01-13 11:16:09 -05:00
|
|
|
return unless (repo/".git/config").exist?
|
2021-01-12 16:27:25 -05:00
|
|
|
|
2021-04-22 20:46:51 +02:00
|
|
|
value = value.to_s
|
|
|
|
|
|
|
|
return if read(setting, repo: repo) == value
|
|
|
|
|
2021-05-12 16:07:47 +01:00
|
|
|
Kernel.system("git", "-C", repo.to_s, "config", "--replace-all", "homebrew.#{setting}", value, exception: true)
|
2021-01-12 16:27:25 -05:00
|
|
|
end
|
|
|
|
|
2023-04-17 10:37:59 -07:00
|
|
|
def self.delete(setting, repo: HOMEBREW_REPOSITORY)
|
2021-01-13 11:16:09 -05:00
|
|
|
return unless (repo/".git/config").exist?
|
2021-04-22 20:46:51 +02:00
|
|
|
|
2023-09-04 21:48:26 +01:00
|
|
|
return if read(setting, repo: repo).nil?
|
2021-01-12 16:27:25 -05:00
|
|
|
|
2021-05-12 16:07:47 +01:00
|
|
|
Kernel.system("git", "-C", repo.to_s, "config", "--unset-all", "homebrew.#{setting}", exception: true)
|
2021-01-12 16:27:25 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|