Skip to content

Commit

Permalink
metanorma/metanorma#202 respect HTTP[S]|SOCKS_PROXY env vars during g…
Browse files Browse the repository at this point in the history
…it clone
  • Loading branch information
CAMOBAP committed Jul 15, 2021
1 parent e49bc5c commit 0913c7d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/fontist/repo.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "git"
require "fontist/utils/git"

module Fontist
class Repo
Expand Down Expand Up @@ -48,7 +49,7 @@ def fetch_repo(name, url)
if Dir.exist?(path)
Git.open(path).pull
else
Git.clone(url, path, depth: 1)
Utils::Git.clone(url, path, depth: 1)
end
end

Expand Down
6 changes: 3 additions & 3 deletions lib/fontist/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ def update_main_repo
if Dir.exist?(Fontist.formulas_repo_path)
Git.open(Fontist.formulas_repo_path).pull
else
Git.clone(Fontist.formulas_repo_url,
Fontist.formulas_repo_path,
depth: 1)
Utils::Git.clone(Fontist.formulas_repo_url,
Fontist.formulas_repo_path,
depth: 1)
end
end

Expand Down
23 changes: 23 additions & 0 deletions lib/fontist/utils/git.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "git"

module Fontist
module Utils
class Git
def self.clone(url, path, opts)
http_proxy = ENV["SOCKS_PROXY"] || ENV["HTTP_PROXY"]
https_proxy = ENV["SOCKS_PROXY"] || ENV["HTTPS_PROXY"]

if http_proxy || https_proxy
git = Git.init(path.to_s)
git.config('http.proxy', http_proxy) if http_proxy # NOTE what if user move out of proxy
git.config('https.proxy', https_proxy) if https_proxy
git.add_remote('origin', url)
git.fetch
git.checkout("master") # FIXME after https://github.com/ruby-git/ruby-git/pull/532
else
Git.clone(url, path, opts)
end
end
end
end
end

0 comments on commit 0913c7d

Please sign in to comment.