git-lfs/config/config_netrc.go
Steve Streeting c4bbd3724e Major refactor to pull things into config, httputil, tools
Mainly required to avoid cyclical dependencies when separating other things
2016-05-13 17:38:06 +01:00

33 lines
598 B
Go

package config
import (
"os"
"path/filepath"
"github.com/github/git-lfs/vendor/_nuts/github.com/bgentry/go-netrc/netrc"
)
type netrcfinder interface {
FindMachine(string) *netrc.Machine
}
type noNetrc struct{}
func (n *noNetrc) FindMachine(host string) *netrc.Machine {
return nil
}
func (c *Configuration) parseNetrc() (netrcfinder, error) {
home := c.Getenv("HOME")
if len(home) == 0 {
return &noNetrc{}, nil
}
nrcfilename := filepath.Join(home, netrcBasename)
if _, err := os.Stat(nrcfilename); err != nil {
return &noNetrc{}, nil
}
return netrc.ParseFile(nrcfilename)
}