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

Commit b17acda

Browse files
committed
Improve ignore glob handling and add tests
Improves handling of ignored local packages. Adds tests for ignoring local packages. - ensure/empty/case4 for ignoring local packages with glob - ensure/empty/case5 for ignoring a single local package, but not subpackages
1 parent 91deb74 commit b17acda

File tree

17 files changed

+153
-8
lines changed

17 files changed

+153
-8
lines changed

cmd/dep/testdata/harness_tests/ensure/empty/case4/final/Gopkg.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignored = ["./samples/..."]
2+
3+
[[constraint]]
4+
branch = "master"
5+
name = "github.com/sdboyer/deptest"

cmd/dep/testdata/harness_tests/ensure/empty/case4/initial/Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignored = ["./samples/..."]
2+
3+
[[constraint]]
4+
branch = "master"
5+
name = "github.com/sdboyer/deptest"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "github.com/sdboyer/deptest"
9+
)
10+
11+
func main() {
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package samples
6+
7+
import _ "github.com/sdboyer/deptestdos"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package samples
6+
7+
import _ "github.com/sdboyer/dep-test"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"commands": [
3+
["ensure"]
4+
],
5+
"error-expected": "",
6+
"vendor-final": [
7+
"github.com/sdboyer/deptest"
8+
]
9+
}

cmd/dep/testdata/harness_tests/ensure/empty/case5/final/Gopkg.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignored = ["./samples", "github.com/Sirupsen/logrus"]
2+
3+
[[constraint]]
4+
branch = "master"
5+
name = "github.com/sdboyer/deptest"

cmd/dep/testdata/harness_tests/ensure/empty/case5/initial/Gopkg.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ignored = ["./samples", "github.com/Sirupsen/logrus"]
2+
3+
[[constraint]]
4+
branch = "master"
5+
name = "github.com/sdboyer/deptest"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
_ "github.com/sdboyer/deptest"
9+
)
10+
11+
func main() {
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package samples
6+
7+
import _ "github.com/sdboyer/deptestdos"
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package samples
6+
7+
import _ "github.com/sdboyer/dep-test"
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"commands": [
3+
["ensure"]
4+
],
5+
"error-expected": "",
6+
"vendor-final": [
7+
"github.com/sdboyer/dep-test",
8+
"github.com/sdboyer/deptest"
9+
]
10+
}

manifest.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,32 @@ func (m *Manifest) IgnoredPackages(solveParam gps.SolveParameters) map[string]bo
292292

293293
mp := make(map[string]bool, len(m.Ignored))
294294
for _, i := range m.Ignored {
295-
// Check if the path has glob syntax (/...)
296-
dir, base := filepath.Split(i)
297-
if base == "..." {
298-
pkgT, _ := pkgtree.ListPackages(filepath.Join(solveParam.RootDir, dir), dir)
299-
300-
// Ignored root packages found in package tree of ignored package
301-
for p := range pkgT.Packages {
295+
// Check if it's a local package path
296+
if strings.HasPrefix(i, "./") {
297+
// Clean ./ from path
298+
i = filepath.Clean(i)
299+
rootPkgT := solveParam.RootPackageTree
300+
301+
// Check if the path has glob syntax (/...)
302+
if strings.HasSuffix(i, "/...") {
303+
dir := filepath.Dir(i)
304+
pkgT, _ := pkgtree.ListPackages(filepath.Join(solveParam.RootDir, dir), dir)
305+
306+
// Ignore root packages found in package tree of ignored package
307+
for p := range pkgT.Packages {
308+
for rp := range solveParam.RootPackageTree.Packages {
309+
if strings.HasSuffix(rp, filepath.Join(rootPkgT.ImportRoot, p)) {
310+
mp[rp] = true
311+
break
312+
}
313+
}
314+
}
315+
} else {
316+
// Ignore root package found in local ignored package
302317
for rp := range solveParam.RootPackageTree.Packages {
303-
if strings.HasSuffix(rp, p) {
318+
if strings.HasSuffix(rp, filepath.Join(rootPkgT.ImportRoot, i)) {
304319
mp[rp] = true
320+
break
305321
}
306322
}
307323
}

0 commit comments

Comments
 (0)