Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request #529 from ibrasho-forks/handle-init-in-GOPATH/src-…
Browse files Browse the repository at this point in the history
…issue

Show a clear error message when trying to 'dep init' in $GOPATH/src
  • Loading branch information
sdboyer committed May 11, 2017
2 parents 8b00de0 + f81437d commit 30cce2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (c *Ctx) resolveProjectRoot(path string) (string, error) {
func (c *Ctx) SplitAbsoluteProjectRoot(path string) (string, error) {
srcprefix := filepath.Join(c.GOPATH, "src") + string(filepath.Separator)
if internal.HasFilepathPrefix(path, srcprefix) {
if len(path) <= len(srcprefix) {
return "", errors.New("dep does not currently support using $GOPATH/src as the project root.")
}

// filepath.ToSlash because we're dealing with an import path now,
// not an fs path
return filepath.ToSlash(path[len(srcprefix):]), nil
Expand Down
12 changes: 9 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,16 @@ func TestSplitAbsoluteProjectRoot(t *testing.T) {
}
}

// test where it should return error
got, err := depCtx.SplitAbsoluteProjectRoot("tra/la/la/la")
// test where it should return an error when directly within $GOPATH/src
got, err := depCtx.SplitAbsoluteProjectRoot(filepath.Join(depCtx.GOPATH, "src"))
if err == nil || !strings.Contains(err.Error(), "$GOPATH/src") {
t.Fatalf("should have gotten an error for use directly in $GOPATH/src, but got %s", got)
}

// test where it should return an error
got, err = depCtx.SplitAbsoluteProjectRoot("tra/la/la/la")
if err == nil {
t.Fatalf("should have gotten error but did not for tra/la/la/la: %s", got)
t.Fatalf("should have gotten an error but did not for tra/la/la/la: %s", got)
}
}

Expand Down

0 comments on commit 30cce2a

Please sign in to comment.