1

Is it possible to use an automatic script as git's proxy?

I'm using http://xxx/yyy as my IE proxy, where xxx is a host and yyy is a javascript file which returns a proxy or "DIRECT" depends on different situations.
The script is rather complicated (more than 300 lines and maintained by the corporate IT deparmentt).

Edit:
My real problem: is if I am in corporate network I use a proxy for external sites, and "DIRECT" for corporate sites. Otherwise I'd use "DIRECT".

Leon
  • 3,124
  • 31
  • 36

1 Answers1

0

Don't forget that you set a proxy per Git repo url

That means if your script criteria for attributing a proxy url is only: "if github.com then use this proxy", you don't need the script at all:

git config --global http."https://github.com".proxy http://mydomain\\myusername:mypassword@myproxyserver:proxyport

I use a proxy for external sites, and "DIRECT" for corporate sites.

For Git, all you need to do is define the environment variable

NO_PROXY=.mycompany.com,.sock,localhost,127.0.0.1

That is enough for git to not use a proxy when cloning a repo hosted by your company, as opposed to one hosted on the internet.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • The problem is that it's not simple. The js code is more than 300 lines. – Leon Nov 08 '16 at 08:25
  • @LeonZeng do you mean that for github.com (for instance), the script could return different proxy url? – VonC Nov 08 '16 at 08:29
  • Thanks Von. It's still not what I wanted. What I want is something like "No proxy when I am not connected to a VPN". – Leon Nov 08 '16 at 09:24
  • @LeonZeng You can't detect a VPN connection (http://stackoverflow.com/q/33300877/6309), so a simple script to switch proxy settings on demand (ie launched by you) seems easier. – VonC Nov 08 '16 at 09:26
  • Yes that's feasible, but it's tricky to switch it frequently. – Leon Nov 08 '16 at 09:52