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

Commit

Permalink
import alternate repo url from gb/gvt manifest
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-go committed Sep 20, 2017
1 parent 956f34d commit 1cfc27f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 9 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@

[[constraint]]
name = "github.com/sdboyer/deptest"
source = "https://github.com/carolynvs/deptest"

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

[[constraint]]
branch = "v2"
name = "gopkg.in/yaml.v2"
8 changes: 6 additions & 2 deletions cmd/dep/testdata/harness_tests/init/gvt/case1/initial/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ package main
import (
"fmt"

"github.com/sdboyer/deptest"
"github.com/sdboyer/deptestdos"
"gopkg.in/yaml.v2"
)

func main() {
var x deptestdos.Bar
fmt.Println(x)
var a deptestdos.Bar
var b yaml.MapItem
var c deptest.Foo
fmt.Println(a, b, c)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"dependencies": [
{
"importpath": "github.com/sdboyer/deptest",
"repository": "https://github.com/sdboyer/deptest",
"repository": "https://github.com/carolynvs/deptest",
"revision": "3f4c3bea144e112a69bbe5d8d01c1b09a544253f",
"branch": "HEAD"
},
Expand All @@ -12,6 +12,12 @@
"repository": "https://github.com/sdboyer/deptestdos",
"revision": "5c607206be5decd28e6263ffffdcee067266015eXXX",
"branch": "master"
},
{
"importpath": "gopkg.in/yaml.v2",
"repository": "https://gopkg.in/yaml.v2",
"revision": "f7716cbe52baa25d2e9b0d0da546fcf909fc16b4",
"branch": "v2"
}
]
}
27 changes: 26 additions & 1 deletion internal/importers/base/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,18 @@ func (i *Importer) ImportPackages(packages []ImportedPackage, defaultConstraintF
}

for _, prj := range projects {
source := prj.Source
if len(source) > 0 {
isDefault, err := i.isDefaultSource(prj.Root, source)
if err == nil && isDefault {
source = ""
}
}

pc := gps.ProjectConstraint{
Ident: gps.ProjectIdentifier{
ProjectRoot: prj.Root,
Source: prj.Source,
Source: source,
},
}

Expand Down Expand Up @@ -291,3 +299,20 @@ func (i *Importer) convertToConstraint(v gps.Version) gps.Constraint {
}
return v
}

func (i *Importer) isDefaultSource(projectRoot gps.ProjectRoot, sourceURL string) (bool, error) {
if sourceURL == "https://"+string(projectRoot) {
return true, nil
}

sourceURLs, err := i.sm.SourceURLsForPath(string(projectRoot))
if err != nil {
return false, err
}
// The first url in the slice will be the default one (usually https://...)
if len(sourceURLs) > 0 && sourceURL == sourceURLs[0].String() {
return true, nil
}

return false, nil
}
7 changes: 3 additions & 4 deletions internal/importers/gvt/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (g *Importer) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error)
var contstraintHint = ""
if pkg.Branch == "HEAD" {
// gb-vendor sets "branch" to "HEAD", if the package was feteched via -tag or -revision,
// we we pass the revision as the constraint hint
// we pass the revision as the constraint hint
contstraintHint = pkg.Revision
} else if pkg.Branch != "master" {
// both gvt & gb-vendor set "branch" to "master" unless a different branch was requested.
Expand All @@ -112,9 +112,8 @@ func (g *Importer) convert(pr gps.ProjectRoot) (*dep.Manifest, *dep.Lock, error)
}

ip := base.ImportedPackage{
Name: pkg.ImportPath,
//TODO: temporarly ignore .Repository. see https://github.com/golang/dep/pull/1166
// Source: pkg.Repository,
Name: pkg.ImportPath,
Source: pkg.Repository,
LockHint: pkg.Revision,
ConstraintHint: contstraintHint,
}
Expand Down
18 changes: 18 additions & 0 deletions internal/importers/gvt/importer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,24 @@ func TestGvtConfig_Convert(t *testing.T) {
},
},
},
"package with alternate repository": {
importertest.TestCase{
WantConstraint: importertest.V1Constraint,
WantRevision: importertest.V1Rev,
WantVersion: importertest.V1Tag,
WantSourceRepo: importertest.ProjectSrc,
},
gvtManifest{
Deps: []gvtPkg{
{
ImportPath: importertest.Project,
Repository: importertest.ProjectSrc,
Revision: importertest.V1Rev,
Branch: "master",
},
},
},
},
"missing package name": {
importertest.TestCase{
WantConvertErr: true,
Expand Down

0 comments on commit 1cfc27f

Please sign in to comment.