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

Commit 30cce2a

Browse files
authored
Merge pull request #529 from ibrasho-forks/handle-init-in-GOPATH/src-issue
Show a clear error message when trying to 'dep init' in $GOPATH/src
2 parents 8b00de0 + f81437d commit 30cce2a

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

context.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func (c *Ctx) resolveProjectRoot(path string) (string, error) {
214214
func (c *Ctx) SplitAbsoluteProjectRoot(path string) (string, error) {
215215
srcprefix := filepath.Join(c.GOPATH, "src") + string(filepath.Separator)
216216
if internal.HasFilepathPrefix(path, srcprefix) {
217+
if len(path) <= len(srcprefix) {
218+
return "", errors.New("dep does not currently support using $GOPATH/src as the project root.")
219+
}
220+
217221
// filepath.ToSlash because we're dealing with an import path now,
218222
// not an fs path
219223
return filepath.ToSlash(path[len(srcprefix):]), nil

context_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,16 @@ func TestSplitAbsoluteProjectRoot(t *testing.T) {
6363
}
6464
}
6565

66-
// test where it should return error
67-
got, err := depCtx.SplitAbsoluteProjectRoot("tra/la/la/la")
66+
// test where it should return an error when directly within $GOPATH/src
67+
got, err := depCtx.SplitAbsoluteProjectRoot(filepath.Join(depCtx.GOPATH, "src"))
68+
if err == nil || !strings.Contains(err.Error(), "$GOPATH/src") {
69+
t.Fatalf("should have gotten an error for use directly in $GOPATH/src, but got %s", got)
70+
}
71+
72+
// test where it should return an error
73+
got, err = depCtx.SplitAbsoluteProjectRoot("tra/la/la/la")
6874
if err == nil {
69-
t.Fatalf("should have gotten error but did not for tra/la/la/la: %s", got)
75+
t.Fatalf("should have gotten an error but did not for tra/la/la/la: %s", got)
7076
}
7177
}
7278

0 commit comments

Comments
 (0)