Skip to content

Use proxy from git config if available - #1173

Closed
jonmagic wants to merge 3 commits into
git-lfs:masterfrom
jonmagic:use-proxy-from-git-config
Closed

jonmagic wants to merge 3 commits into
git-lfs:masterfrom
jonmagic:use-proxy-from-git-config

Conversation

@jonmagic

Copy link
Copy Markdown
Contributor

This may be a possible solution to #1125 but we are Go and git-lfs newbs so we could use some guidance.

  • Is this approach even close to how y'all would do this?
  • Should we create a new test file for lfs/http.go so that we can test this method specifically or should we add an integration test, or something else entirely?

/cc @LizzHale

jonmagic and others added 2 commits April 22, 2016 13:48
Returns proxy string from Git config first and environment second.
@technoweenie

Copy link
Copy Markdown
Contributor

This looks great :) 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:

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

I'd like to see how git handles this.

A go test for proxyFromGitConfigOrEnvironment() could go in lfs/proxy_test.go. Seems like that'd be enough to test the various use cases.

An integration test would be lovely. It'd require setting up a fake proxy server for testing purposes. I can look into this separately, since it should've existed for the current env proxy support.

@sinbad

sinbad commented Apr 27, 2016

Copy link
Copy Markdown
Contributor

+1 to @technoweenie's comments. Environment vars should always override gitconfig settings, it's how you typically change things temporarily rather than persistently.

Add three go tests and only one works right now
@jonmagic

jonmagic commented Jun 3, 2016

Copy link
Copy Markdown
Contributor Author

@LizzHale and I paired on this again today and we think we've got the logic right but haven't figured out how to correctly test all of them. One of our tests works and two don't, we left them there but commented out with the error. Any *pointers are appreciated 😁

@ttaylorr

ttaylorr commented Jun 4, 2016

Copy link
Copy Markdown
Contributor

Hi @jonmagic and @LizzHale! This looks awesome 👍 I definitely agree with @technoweenie and @sinbad's comment about the environment vs. .gitconfig debate, and your patch looks sweet.

Tests look like they're off to a good start, too. If you post more of the stacktrace, I'd be more than happy to take a look at it with you and try and figure out the cause of the failure 😄

Comment thread lfs/proxy_test.go
// panic: runtime error: invalid memory address or nil pointer dereference [recovered]
// panic: runtime error: invalid memory address or nil pointer dereference
//
// func TestProxyFromEnv(t *testing.T) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Stacktrace:

warning: current Git remote contains credentials
warning: current Git remote contains credentials
--- FAIL: TestProxyFromEnv (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
    panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0xe1a2a]

goroutine 287 [running]:
panic(0x4cef80, 0xc82000a0f0)
    /usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:481 +0x3e6
testing.tRunner.func1(0xc820366000)
    /usr/local/Cellar/go/1.6.2/libexec/src/testing/testing.go:467 +0x192
panic(0x4cef80, 0xc82000a0f0)
    /usr/local/Cellar/go/1.6.2/libexec/src/runtime/panic.go:443 +0x4e9
github.com/github/git-lfs/lfs.TestProxyFromEnv(0xc820366000)
    /Users/jonmagic/gopath/src/github.com/github/git-lfs/lfs/proxy_test.go:29 +0x34a
testing.tRunner(0xc820366000, 0x7d4368)
    /usr/local/Cellar/go/1.6.2/libexec/src/testing/testing.go:473 +0x98
created by testing.RunTests
    /usr/local/Cellar/go/1.6.2/libexec/src/testing/testing.go:582 +0x892
FAIL    github.com/github/git-lfs/lfs   1.285s
ok      github.com/github/git-lfs/git   1.636s

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.

So the relevant bit here is this:

github.com/github/git-lfs/lfs.TestProxyFromEnv(0xc820366000)
    /Users/jonmagic/gopath/src/github.com/github/git-lfs/lfs/proxy_test.go:29 +0x34a

This is telling me that the TestProxyFromEnv() function on proxy_test.go:29 is failing due to a nil pointer reference. Going by the commented test line numbers, that's coming from the middle line here, because proxyURL is nil.

proxyURL, err := proxyFromGitConfigOrEnvironment(req)
assert.Equal(t, "proxy-from-env:8080", proxyURL.Host)
assert.Equal(t, nil, err)

You should check err before the value to avoid issues like this.

This was referenced Jul 7, 2016
@jonmagic

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1358

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants