Class: Fontist::Repo

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/repo.rb

Class Method Summary collapse

Class Method Details

.info(name) ⇒ Object



147
148
149
150
151
152
153
154
# File 'lib/fontist/repo.rb', line 147

def info(name)
  path = Pathname.new repo_path(name)
  unless path.exist?
    raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
  end

  Info.new(name, path)
end

.listObject



141
142
143
144
145
# File 'lib/fontist/repo.rb', line 141

def list
  Dir.glob(Fontist.private_formulas_path.join("*"))
    .select { |path| File.directory?(path) }
    .map { |path| File.basename(path) }
end

.remove(name) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/fontist/repo.rb', line 131

def remove(name)
  path = repo_path(name)
  unless Dir.exist?(path)
    raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
  end

  FileUtils.rm_r(path)
  rebuild_index_if_needed
end

.setup(name, url) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/fontist/repo.rb', line 63

def setup(name, url)
  ensure_private_formulas_path_exists
  path = repo_path(name)

  # Check for duplicate URL across all repos
  existing_repo_with_url = find_repo_by_url(url)
  if existing_repo_with_url && existing_repo_with_url != name
    Fontist.ui.error(Paint["Repository URL already in use by '#{existing_repo_with_url}'",
                           :red])
    Fontist.ui.error(Paint["URL: #{url}", :yellow])
    Fontist.ui.error(Paint["Cannot setup duplicate repository.", :red])
    return false
  end

  if Dir.exist?(path)
    Fontist.ui.say(Paint["Repository '#{name}' already exists at #{path}",
                         :yellow])
    # Determine whether to proceed with overwrite:
    # - If auto_overwrite is explicitly set, use that value
    # - If interactive, prompt the user
    # - Otherwise (non-interactive without explicit setting), proceed automatically
    proceed = if !Fontist.auto_overwrite.nil?
                Fontist.auto_overwrite
              elsif Fontist.interactive?
                Fontist.ui.yes?(Paint["Do you want to overwrite it? [y/N]",
                                      :yellow, :bright])
              else
                true
              end
    unless proceed
      Fontist.ui.say(Paint["Setup cancelled.", :red])
      return false
    end
    Fontist.ui.say(Paint["Removing existing repository...", :yellow])
    Fontist::Utils::FileOps.safe_rm_rf(path)
  end

  validate_and_fetch_repo(name, url)
  rebuild_index_if_needed
  true
rescue StandardError => e
  # Catch all git-related errors
  if e.class.name.include?("Git") || e.message.match?(/git|clone|repository/i)
    handle_git_error(name, url, e, :setup)
  else
    raise
  end
end

.update(name) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/fontist/repo.rb', line 112

def update(name)
  path = repo_path(name)
  unless Dir.exist?(path)
    raise(Errors::RepoNotFoundError, "No such repo '#{name}'.")
  end

  git = Git.open(path)
  git.pull("origin", git.current_branch)

  rebuild_index_if_needed
rescue StandardError => e
  # Catch all git-related errors
  if e.class.name.include?("Git") || e.message.match?(/git|pull|repository/i)
    handle_git_error(name, git.config["remote.origin.url"], e, :update)
  else
    raise
  end
end