Skip to content

use proxy from git config - #1358

Merged
technoweenie merged 16 commits into
masterfrom
jonmagic-use-proxy-from-git-config
Jul 21, 2016
Merged

technoweenie merged 16 commits into
masterfrom
jonmagic-use-proxy-from-git-config

Conversation

@technoweenie

Copy link
Copy Markdown
Contributor

This updates #1173 with the latest master. Since that PR, a lot of subpackages have been split out, and we've switched assertion libraries.

@jonmagic @LizzHale: I also changed the main ProxyFromGitConfigOrEnvironment() function from #1173 for these reasons:

  1. proxyFromGitConfigOrEnvironment() is coupled to the global Config value. I updated the function to accept only a *config.Configuration argument, and return a func(*http.Request) (*url.URL, error). That cleaned up the test setup for TestProxyFromGitConfig a bit.
  2. It returns a valid url OR error from http.ProxyFromEnvironment now. I didn't want to drop a potential error if users have a bad HTTPS_PROXY value, but a good git http.proxy value.
  3. The end of the function returns nil now, explicitly.

Unfortunately, I couldn't test the environment, because of how http.ProxyFromEnvironment is implemented. It reads from the env the first time that function is called. Calling os.Setenv doesn't affect it.

However, I'm thinking about pulling all that code into Git LFS. There are a few internal functions that would be useful for proxy values specified in the git config, such as NO_PROXY handling.

@jonmagic

Copy link
Copy Markdown
Contributor

@technoweenie awesome! Just getting back from vacation, anything I can do to help on this?

@technoweenie technoweenie mentioned this pull request Jul 13, 2016
8 tasks done
@ttaylorr

Copy link
Copy Markdown
Contributor

👍

Comment thread lfs/proxy_test.go Outdated

assert.Nil(t, proxyURL)
assert.Nil(t, err)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think there should be some tests with NO_PROXY for completeness.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in f0acdb2

@sinbad

sinbad commented Jul 14, 2016

Copy link
Copy Markdown
Contributor

👍 looks good

@technoweenie

Copy link
Copy Markdown
Contributor Author

Hey, funny story time. @ttaylorr asked me why the function is named ProxyFromGitConfigOrEnvironment, when it's reading from the env first, before git config. Turns out it's named that way because the original implementation read from the git config first. Then, I chimed in:

My main question is whether this should prefer the git config or the environment first? I'd lean towards using the git config as a last resort. A couple use cases:

  • Someone has a global http_proxy set in their bashrc because of their local network setup.
  • Someone runs http_proxy=.... git clone ...

I'd like to see how git handles this.

I never looked into it until just now though, while looking for any other proxy related git config values. The docs say:

Override the HTTP proxy, normally configured using the http_proxy, https_proxy, and all_proxy environment variables

Looks like @jonmagic and @LizzHale are right :) I wonder if a git http.proxy value should override a HTTPS_PROXY env var for https requests though?

@sinbad

sinbad commented Jul 15, 2016

Copy link
Copy Markdown
Contributor

This is a great point - I even checked the precedence and agreed with it, but now you raise it again I think this does need to be the other way around in this case.

Usually environment variables should override gitconfig, but in this case the environment variables are general ones, not git specific ones. Thinking about it, it makes sense that the overall order of precedence should be:

  1. Git specific environment variables
  2. git config
  3. General environment variables

.. because otherwise you have no way of persistently overriding generic environment settings specifically for git. The confusion I've had is that we've only really had 1 & 2 most of the time.

@technoweenie

Copy link
Copy Markdown
Contributor Author

I updated the code to check the git config first 👍

@ttaylorr

Copy link
Copy Markdown
Contributor

Looks good! ✨

@technoweenie
technoweenie merged commit e489002 into master Jul 21, 2016
@technoweenie
technoweenie deleted the jonmagic-use-proxy-from-git-config branch July 21, 2016 17:34
@LizzHale

Copy link
Copy Markdown
Contributor

✨

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants