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

Commit 1cfc27f

Browse files
committed
import alternate repo url from gb/gvt manifest
1 parent 956f34d commit 1cfc27f

File tree

7 files changed

+76
-9
lines changed

7 files changed

+76
-9
lines changed

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

+8-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
11

2+
[[constraint]]
3+
name = "github.com/sdboyer/deptest"
4+
source = "https://github.com/carolynvs/deptest"
5+
26
[[constraint]]
37
name = "github.com/sdboyer/deptestdos"
8+
9+
[[constraint]]
10+
branch = "v2"
11+
name = "gopkg.in/yaml.v2"

cmd/dep/testdata/harness_tests/init/gvt/case1/initial/main.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,14 @@ package main
77
import (
88
"fmt"
99

10+
"github.com/sdboyer/deptest"
1011
"github.com/sdboyer/deptestdos"
12+
"gopkg.in/yaml.v2"
1113
)
1214

1315
func main() {
14-
var x deptestdos.Bar
15-
fmt.Println(x)
16+
var a deptestdos.Bar
17+
var b yaml.MapItem
18+
var c deptest.Foo
19+
fmt.Println(a, b, c)
1620
}

cmd/dep/testdata/harness_tests/init/gvt/case1/initial/vendor/manifest

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"dependencies": [
44
{
55
"importpath": "github.com/sdboyer/deptest",
6-
"repository": "https://github.com/sdboyer/deptest",
6+
"repository": "https://github.com/carolynvs/deptest",
77
"revision": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f",
88
"branch": "HEAD"
99
},
@@ -12,6 +12,12 @@
1212
"repository": "https://github.com/sdboyer/deptestdos",
1313
"revision": "5c607206be5decd28e6263ffffdcee067266015eXXX",
1414
"branch": "master"
15+
},
16+
{
17+
"importpath": "gopkg.in/yaml.v2",
18+
"repository": "https://gopkg.in/yaml.v2",
19+
"revision": "f7716cbe52baa25d2e9b0d0da546fcf909fc16b4",
20+
"branch": "v2"
1521
}
1622
]
1723
}

internal/importers/base/importer.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -180,10 +180,18 @@ func (i *Importer) ImportPackages(packages []ImportedPackage, defaultConstraintF
180180
}
181181

182182
for _, prj := range projects {
183+
source := prj.Source
184+
if len(source) > 0 {
185+
isDefault, err := i.isDefaultSource(prj.Root, source)
186+
if err == nil && isDefault {
187+
source = ""
188+
}
189+
}
190+
183191
pc := gps.ProjectConstraint{
184192
Ident: gps.ProjectIdentifier{
185193
ProjectRoot: prj.Root,
186-
Source: prj.Source,
194+
Source: source,
187195
},
188196
}
189197

@@ -291,3 +299,20 @@ func (i *Importer) convertToConstraint(v gps.Version) gps.Constraint {
291299
}
292300
return v
293301
}
302+
303+
func (i *Importer) isDefaultSource(projectRoot gps.ProjectRoot, sourceURL string) (bool, error) {
304+
if sourceURL == "https://"+string(projectRoot) {
305+
return true, nil
306+
}
307+
308+
sourceURLs, err := i.sm.SourceURLsForPath(string(projectRoot))
309+
if err != nil {
310+
return false, err
311+
}
312+
// The first url in the slice will be the default one (usually https://...)
313+
if len(sourceURLs) > 0 && sourceURL == sourceURLs[0].String() {
314+
return true, nil
315+
}
316+
317+
return false, nil
318+
}

internal/importers/gvt/importer.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (g *Importer) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error)
103103
var contstraintHint = ""
104104
if pkg.Branch == "HEAD" {
105105
// gb-vendor sets "branch" to "HEAD", if the package was feteched via -tag or -revision,
106-
// we we pass the revision as the constraint hint
106+
// we pass the revision as the constraint hint
107107
contstraintHint = pkg.Revision
108108
} else if pkg.Branch != "master" {
109109
// both gvt & gb-vendor set "branch" to "master" unless a different branch was requested.
@@ -112,9 +112,8 @@ func (g *Importer) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error)
112112
}
113113

114114
ip := base.ImportedPackage{
115-
Name: pkg.ImportPath,
116-
//TODO: temporarly ignore .Repository. see https://github.com/golang/dep/pull/1166
117-
// Source: pkg.Repository,
115+
Name: pkg.ImportPath,
116+
Source: pkg.Repository,
118117
LockHint: pkg.Revision,
119118
ConstraintHint: contstraintHint,
120119
}

internal/importers/gvt/importer_test.go

+18
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,24 @@ func TestGvtConfig_Convert(t *testing.T) {
7070
},
7171
},
7272
},
73+
"package with alternate repository": {
74+
importertest.TestCase{
75+
WantConstraint: importertest.V1Constraint,
76+
WantRevision: importertest.V1Rev,
77+
WantVersion: importertest.V1Tag,
78+
WantSourceRepo: importertest.ProjectSrc,
79+
},
80+
gvtManifest{
81+
Deps: []gvtPkg{
82+
{
83+
ImportPath: importertest.Project,
84+
Repository: importertest.ProjectSrc,
85+
Revision: importertest.V1Rev,
86+
Branch: "master",
87+
},
88+
},
89+
},
90+
},
7391
"missing package name": {
7492
importertest.TestCase{
7593
WantConvertErr: true,

0 commit comments

Comments
 (0)