class Fontist::Update

Constants

VERSION

Public Class Methods

call() click to toggle source
# File lib/fontist/update.rb, line 5
def self.call
  new(VERSION).call
end
new(branch = "main") click to toggle source
# File lib/fontist/update.rb, line 9
def initialize(branch = "main")
  @branch = branch
end

Public Instance Methods

call() click to toggle source
# File lib/fontist/update.rb, line 13
def call
  update_main_repo
  update_private_repos
ensure
  rebuild_index
end

Private Instance Methods

private_repos() click to toggle source
# File lib/fontist/update.rb, line 64
def private_repos
  Dir.glob(Fontist.private_formulas_path.join("*")).select do |path|
    File.directory?(path)
  end
end
rebuild_index() click to toggle source
# File lib/fontist/update.rb, line 74
def rebuild_index
  Index.rebuild
end
repo_name(path) click to toggle source
# File lib/fontist/update.rb, line 70
def repo_name(path)
  File.basename(path)
end
update_main_repo() click to toggle source
# File lib/fontist/update.rb, line 22
def update_main_repo
  dir = File.dirname(Fontist.formulas_repo_path)
  FileUtils.mkdir_p(dir) unless File.exist?(dir)

  unless Dir.exist?(Fontist.formulas_repo_path)
    return Git.clone(Fontist.formulas_repo_url,
                     Fontist.formulas_repo_path,
                     branch: @branch,
                     depth: 1)
  end

  git = Git.open(Fontist.formulas_repo_path)
  return git.pull("origin", @branch) if git.current_branch == @branch

  git.config("remote.origin.fetch",
             "+refs/heads/#{@branch}:refs/remotes/origin/#{@branch}")
  git.fetch
  git.checkout(@branch)
  git.pull("origin", @branch)
end
update_private_repos() click to toggle source
# File lib/fontist/update.rb, line 43
def update_private_repos
  private_repos.each do |path|
    update_repo(path)
  end
end
update_repo(path) click to toggle source
# File lib/fontist/update.rb, line 49
    def update_repo(path)
      Git.open(path).pull
    rescue Git::GitExecuteError => e
      name = repo_name(path)
      raise Errors::RepoCouldNotBeUpdatedError.new(<<~MSG.chomp)
        Formulas repo '#{name}' could not be updated.
        Please consider reinitializing it with:
          fontist remove #{name}
          fontist setup #{name} REPO_URL

        Git error:
        #{e.message}
      MSG
    end