@peccul is peccu

(love peccu '(emacs lisp cat outdoor bicycle mac linux coffee))

git://で始まるリポジトリURLをプロキシ環境下で使う

npmパッケージの依存するパッケージの中にはgit://で始まるURLが指定されていることがあってプロキシ環境下だとクローンできない。 git://github.com/hogehoge/fugafuga.git のような。

git://のみcloneに失敗とか、timeoutのエラー表示ならほぼプロキシを経由できていないからかと思う。

gitがプロキシを超えられるようにする

準備(git://でなくても必要)

環境変数の設定 HTTP_PROXY, http_proxy, HTTPS_PROXY, https_proxyそれぞれに http://proxy.example.com:8080のように設定する

続く手段1と2はどちらでも良い。1が簡単。

手段1

参考:A simple wrapper around socat to use as a git proxy command

gitプロトコルのアクセスをhttpsでのアクセスに読み替える

  • gitの設定ファイルを編集する ~/.gitconfigの内容(抜粋)
[url "https://"]
        insteadOf = git://

手段2

参考:How to use the git protocol through a HTTP CONNECT proxy - Thoughts on Systems socatを利用する

  • パッケージマネージャでsocatをインストールする
  • パスの通っている場所にスクリプトを置く 内容はこれ。ここでは ~/bin/gitproxy-socat という名前で保存したとする (プロキシのドメインとポートは適宜修正する)
#!/bin/sh
# Use socat to proxy git through an HTTP CONNECT firewall.
# Useful if you are trying to clone git:// from inside a company.
# Requires that the proxy allows CONNECT to port 9418.
#
# Save this file as gitproxy somewhere in your path (e.g., ~/bin) and then run
#   chmod +x gitproxy
#   git config --global core.gitproxy gitproxy
#
# More details at http://tinyurl.com/8xvpny

# Configuration. Common proxy ports are 3128, 8123, 8000.
_proxy=proxy.example.com
_proxyport=8080

exec socat STDIO PROXY:$_proxy:$1:$2,proxyport=$_proxyport
  • 実行権限をつける chmod +x ~/bin/gitproxy-socat
  • gitの設定ファイルを編集する ~/.gitconfigの内容(抜粋)
[core]
    gitproxy=gitproxy-socat