diff options
| author | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 22:15:17 +0200 |
|---|---|---|
| committer | Stefan Majewsky <majewsky@gmx.net> | 2017-05-05 22:15:17 +0200 |
| commit | a54004fbd960e4851f1f249ce0d030cf56b20f1b (patch) | |
| tree | 62189d3fb0ad5205cc5a160a008057a3e21d31d0 /pkg/rtree/repo.go | |
| parent | 22d80eda906d1958dfde5072717a12995ee6df2d (diff) | |
| download | gofu-a54004fbd960e4851f1f249ce0d030cf56b20f1b.tar.gz | |
propagate errors upwards properly
Diffstat (limited to 'pkg/rtree/repo.go')
| -rw-r--r-- | pkg/rtree/repo.go | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/pkg/rtree/repo.go b/pkg/rtree/repo.go index 12f087f..12afee0 100644 --- a/pkg/rtree/repo.go +++ b/pkg/rtree/repo.go @@ -27,8 +27,6 @@ import ( "path/filepath" "regexp" "strings" - - "github.com/majewsky/gofu/pkg/util" ) //RootPath is the directory below which all repositories are located. Its value @@ -38,7 +36,7 @@ var RootPath string func init() { gopath := os.Getenv("GOPATH") if gopath == "" { - util.FatalIfError(errors.New("$GOPATH is not set (rtree needs the GOPATH variable to know where to look for and place repos)")) + panic(errors.New("$GOPATH is not set (rtree needs the GOPATH variable to know where to look for and place repos)")) } RootPath = filepath.Join(gopath, "src") } @@ -97,16 +95,17 @@ func NewRepoFromAbsolutePath(path string) (repo Repo, err error) { //NewRepoFromRemoteURL initializes a Repo instance for checking out a remote //for the first time. The checkout does not happen until Checkout() is called. -func NewRepoFromRemoteURL(remoteURL string) Repo { +func NewRepoFromRemoteURL(remoteURL string) (Repo, error) { + checkoutPath, err := CheckoutPathForRemoteURL(ExpandRemoteURL(remoteURL)) return Repo{ - CheckoutPath: CheckoutPathForRemoteURL(ExpandRemoteURL(remoteURL)), + CheckoutPath: checkoutPath, Remotes: []Remote{ { Name: "origin", URL: remoteURL, }, }, - } + }, err } var remoteConfigRx = regexp.MustCompile(`remote\.([^=]+)\.url=(.+)`) @@ -141,22 +140,6 @@ func ForeachPhysicalRepo(action func(repo Repo) error) error { }) } -//ExistsOnDisk returns true if the top directory of this repo exists. -func (r Repo) ExistsOnDisk() bool { - path := r.AbsolutePath() - fi, err := os.Stat(path) - if err == nil { - if !fi.IsDir() { - util.FatalIfError(fmt.Errorf("expected %s to be a directory, but it is not", path)) - } - return true - } - if !os.IsNotExist(err) { - util.FatalIfError(err) - } - return false -} - //Checkout creates the repo in the given path with the given remotes. The //working copy will only be initialized if there is an "origin" remote. func (r Repo) Checkout() error { |
