github.com/git-lfs/git-lfs@v2.5.2+incompatible/config/netrc.go (about)

     1  package config
     2  
     3  import (
     4  	"os"
     5  	"path/filepath"
     6  
     7  	"github.com/git-lfs/go-netrc/netrc"
     8  )
     9  
    10  type netrcfinder interface {
    11  	FindMachine(string) *netrc.Machine
    12  }
    13  
    14  type noNetrc struct{}
    15  
    16  func (n *noNetrc) FindMachine(host string) *netrc.Machine {
    17  	return nil
    18  }
    19  
    20  func (c *Configuration) parseNetrc() (netrcfinder, error) {
    21  	home, _ := c.Os.Get("HOME")
    22  	if len(home) == 0 {
    23  		return &noNetrc{}, nil
    24  	}
    25  
    26  	nrcfilename := filepath.Join(home, netrcBasename)
    27  	if _, err := os.Stat(nrcfilename); err != nil {
    28  		return &noNetrc{}, nil
    29  	}
    30  
    31  	return netrc.ParseFile(nrcfilename)
    32  }