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

Commit 381d157

Browse files
committed
Import ignores with wildcards
1 parent 32a4622 commit 381d157

File tree

6 files changed

+40
-26
lines changed

6 files changed

+40
-26
lines changed

cmd/dep/testdata/harness_tests/init/govendor/case1/final/Gopkg.lock

Lines changed: 1 addition & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/dep/testdata/harness_tests/init/govendor/case1/final/Gopkg.toml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
ignored = ["github.com/sdboyer/dep-test"]
2-
3-
[[constraint]]
4-
name = "github.com/carolynvs/go-dep-test"
5-
version = "0.2.0"
1+
ignored = ["github.com/golang/notexist/samples*","github.com/sdboyer/dep-test*"]
62

73
[[constraint]]
84
name = "github.com/sdboyer/deptestdos"

cmd/dep/testdata/harness_tests/init/govendor/case1/testcase.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"github.com/sdboyer/deptestdos": "5c607206be5decd28e6263ffffdcee067266015e"
99
},
1010
"vendor-final": [
11-
"github.com/carolynvs/go-dep-test",
1211
"github.com/sdboyer/deptest",
1312
"github.com/sdboyer/deptestdos"
1413
]

internal/importers/govendor/importer.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"io/ioutil"
1010
"log"
1111
"os"
12+
"path"
1213
"path/filepath"
1314
"strings"
1415

@@ -80,11 +81,11 @@ func (g *Importer) load(projectDir string) error {
8081
}
8182
vb, err := ioutil.ReadFile(v)
8283
if err != nil {
83-
return errors.Wrapf(err, "Unable to read %s", v)
84+
return errors.Wrapf(err, "unable to read %s", v)
8485
}
8586
err = json.Unmarshal(vb, &g.file)
8687
if err != nil {
87-
return errors.Wrapf(err, "Unable to parse %s", v)
88+
return errors.Wrapf(err, "unable to parse %s", v)
8889
}
8990
return nil
9091
}
@@ -96,13 +97,13 @@ func (g *Importer) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error)
9697
for _, pkg := range g.file.Package {
9798
// Path must not be empty
9899
if pkg.Path == "" {
99-
err := errors.New("Invalid govendor configuration, Path is required")
100+
err := errors.New("invalid govendor configuration, Path is required")
100101
return nil, nil, err
101102
}
102103

103104
// Revision must not be empty
104105
if pkg.Revision == "" {
105-
err := errors.New("Invalid govendor configuration, Revision is required")
106+
err := errors.New("invalid govendor configuration, Revision is required")
106107
return nil, nil, err
107108
}
108109

@@ -131,12 +132,20 @@ func (g *Importer) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error)
131132
g.Logger.Printf(" Govendor was configured to ignore the %s build tag, but that isn't supported by dep yet, and will be ignored. See https://github.com/golang/dep/issues/291.", i)
132133
continue
133134
}
135+
136+
var ignorePattern string
134137
_, err := g.SourceManager.DeduceProjectRoot(i)
135-
if err == nil {
136-
g.Manifest.Ignored = append(g.Manifest.Ignored, i)
137-
} else {
138-
g.Logger.Printf(" Govendor was configured to ignore the %s package prefix, but that isn't supported by dep yet, and will be ignored.", i)
138+
if err == nil { // external package
139+
ignorePattern = i
140+
} else { // relative package path in the current project
141+
ignorePattern = path.Join(string(pr), i)
139142
}
143+
144+
// Convert to a a wildcard ignore
145+
ignorePattern = strings.TrimRight(ignorePattern, "/")
146+
ignorePattern += "*"
147+
148+
g.Manifest.Ignored = append(g.Manifest.Ignored, ignorePattern)
140149
}
141150
}
142151

internal/importers/govendor/importer_test.go

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestGovendorConfig_Import(t *testing.T) {
6666
}
6767
}
6868

69-
func TestGovendorConfig_Convert_Project(t *testing.T) {
69+
func TestGovendorConfig_Convert(t *testing.T) {
7070
testCases := map[string]struct {
7171
file govendorFile
7272
importertest.TestCase
@@ -88,12 +88,28 @@ func TestGovendorConfig_Convert_Project(t *testing.T) {
8888
WantVersion: importertest.V1Tag,
8989
},
9090
},
91-
"ignored package": {
91+
"skipped build tags": {
9292
govendorFile{
93-
Ignore: "test github.com/sdboyer/deptest linux_amd64 github.com/sdboyer",
93+
Ignore: "test linux_amd64",
9494
},
9595
importertest.TestCase{
96-
WantIgnored: []string{"github.com/sdboyer/deptest"},
96+
WantIgnored: nil,
97+
},
98+
},
99+
"ignored external package": {
100+
govendorFile{
101+
Ignore: "github.com/sdboyer/deptest k8s.io/apimachinery",
102+
},
103+
importertest.TestCase{
104+
WantIgnored: []string{"github.com/sdboyer/deptest*", "k8s.io/apimachinery*"},
105+
},
106+
},
107+
"ignored internal package": {
108+
govendorFile{
109+
Ignore: "samples/ foo/bar",
110+
},
111+
importertest.TestCase{
112+
WantIgnored: []string{importertest.RootProject + "/samples*", importertest.RootProject + "/foo/bar*"},
97113
},
98114
},
99115
"missing package path": {

internal/importers/importertest/testcase.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (tc TestCase) validate(manifest *dep.Manifest, lock *dep.Lock, convertErr e
7979
}
8080

8181
if !equalSlice(manifest.Ignored, tc.WantIgnored) {
82-
return errors.Errorf("unexpected set of ignored projects: \n\t(GOT) %v \n\t(WNT) %v",
82+
return errors.Errorf("unexpected set of ignored projects: \n\t(GOT) %#v \n\t(WNT) %#v",
8383
manifest.Ignored, tc.WantIgnored)
8484
}
8585

0 commit comments

Comments
 (0)