Skip to content

Commit

Permalink
metanorma/metanorma#202 respect HTTP[S]|SOCKS_PROXY env vars during c…
Browse files Browse the repository at this point in the history
…lone
  • Loading branch information
CAMOBAP committed Jul 15, 2021
1 parent 5cdaabb commit e26e179
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions lib/metanorma/cli/git_template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,17 @@ def remove_template
end

def clone_git_template(repo)
clone = Git.clone(repo, name, path: templates_path)
template_path unless clone.nil?
http_proxy = ENV["SOCKS_PROXY"] || ENV["HTTP_PROXY"]
https_proxy = ENV["SOCKS_PROXY"] || ENV["HTTPS_PROXY"]

if http_proxy || https_proxy
clone_with_proxy(http_proxy, https_proxy)
else
clone = Git.clone(repo, name, path: templates_path)
template_path unless clone.nil?
end

template_path
end

def git_repos
Expand All @@ -102,6 +111,16 @@ def build_templates_path
def template_path
@template_path ||= templates_path.join(name.to_s.downcase)
end

def clone_with_proxy(http_proxy, https_proxy)
repo_path = templates_path / name
git = Git.init(repo_path.to_s)
git.config("http.proxy", http_proxy) if http_proxy
git.config("https.proxy", https_proxy) if https_proxy
git.add_remote("origin", repo)
git.fetch
git.checkout("master") # FIXME after https://github.com/ruby-git/ruby-git/pull/532
end
end
end
end

0 comments on commit e26e179

Please sign in to comment.