github.com/keikoproj/manny@v0.0.0-20210726112440-8571e4c99ced/utils/git.go (about)

     1  package utils
     2  
     3  import (
     4  	"path/filepath"
     5  
     6  	"github.com/go-git/go-git/v5"
     7  )
     8  
     9  // GitRepoRemote gets the remote URL of the git repo
    10  func GitRepoRemote(location string) (string, error) {
    11  	path := filepath.Join(location, git.GitDirName)
    12  
    13  	r, err := git.PlainOpenWithOptions(path, &git.PlainOpenOptions{DetectDotGit: true})
    14  	if err != nil {
    15  		return "", err
    16  	}
    17  
    18  	rem, err := r.Remote(git.DefaultRemoteName)
    19  	if err != nil {
    20  		return "", err
    21  	}
    22  
    23  	return rem.Config().URLs[0], nil
    24  }