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

Commit

Permalink
Merge pull request #1243 from carolynvs/gopkgin-v0-panic
Browse files Browse the repository at this point in the history
gps: fix panic for gopkgin's implicit v0
  • Loading branch information
sdboyer committed Nov 20, 2017
2 parents 9d269a6 + 770a444 commit 13df556
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BUG FIXES:
* Suppress git password prompts in more places (#1357).
* Fix `-no-vendor` flag for `ensure -update` (#1361).
* Validate `git ls-remote` output and ignore all malformed lines (#1379)
* Support [gopkg.in version zero](http://labix.org/gopkg.in#VersionZero) (#1243).

IMPROVEMENTS:

Expand Down
23 changes: 20 additions & 3 deletions gps/vcs_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,23 +410,34 @@ func (s *gopkginSource) listVersions(ctx context.Context) ([]PairedVersion, erro
k := 0
var dbranch int // index of branch to be marked default
var bsv semver.Version
var defaultBranch PairedVersion
tryDefaultAsV0 := s.major == 0
for _, v := range ovlist {
// all git versions will always be paired
pv := v.(versionPair)
switch tv := pv.v.(type) {
case semVersion:
tryDefaultAsV0 = false
if tv.sv.Major() == s.major && !s.unstable {
vlist[k] = v
k++
}
case branchVersion:
if tv.isDefault && defaultBranch == nil {
defaultBranch = pv
}

// The semver lib isn't exactly the same as gopkg.in's logic, but
// it's close enough that it's probably fine to use. We can be more
// exact if real problems crop up.
sv, err := semver.NewVersion(tv.name)
if err != nil || sv.Major() != s.major {
// not a semver-shaped branch name at all, or not the same major
// version as specified in the import path constraint
if err != nil {
continue
}
tryDefaultAsV0 = false

if sv.Major() != s.major {
// not the same major version as specified in the import path constraint
continue
}

Expand Down Expand Up @@ -461,6 +472,12 @@ func (s *gopkginSource) listVersions(ctx context.Context) ([]PairedVersion, erro
}.Pair(dbv.r)
}

// Treat the default branch as v0 only when no other semver branches/tags exist
// See http://labix.org/gopkg.in#VersionZero
if tryDefaultAsV0 && defaultBranch != nil {
vlist = append(vlist, defaultBranch)
}

return vlist, nil
}

Expand Down
25 changes: 21 additions & 4 deletions gps/vcs_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,11 +214,11 @@ func testGopkginSourceInteractions(t *testing.T) {

vlist := hidePair(pvlist)
if len(vlist) != len(evl) {
t.Errorf("gopkgin test repo should've produced %v versions, got %v", len(evl), len(vlist))
t.Errorf("gopkgin test repo (%s) should've produced %v versions, got %v.\n%v", un, len(evl), len(vlist), vlist)
} else {
SortForUpgrade(vlist)
if !reflect.DeepEqual(vlist, evl) {
t.Errorf("Version list was not what we expected:\n\t(GOT): %s\n\t(WNT): %s", vlist, evl)
t.Errorf("Version list for %s was not what we expected:\n\t(GOT): %#v\n\t(WNT): %#v", un, vlist, evl)
}
}

Expand All @@ -234,7 +234,7 @@ func testGopkginSourceInteractions(t *testing.T) {
} else {
SortForUpgrade(vlist)
if !reflect.DeepEqual(vlist, evl) {
t.Errorf("Version list was not what we expected:\n\t(GOT): %s\n\t(WNT): %s", vlist, evl)
t.Errorf("Version list for %s was not what we expected:\n\t(GOT): %#v\n\t(WNT): %#v", un, vlist, evl)
}
}

Expand All @@ -249,7 +249,24 @@ func testGopkginSourceInteractions(t *testing.T) {

// simultaneously run for v1, v2, and v3 filters of the target repo
wg := &sync.WaitGroup{}
wg.Add(4)
wg.Add(6)

go func() {
// Treat master as v0 when no other branches/tags exist that match gopkg.in's rules
tfunc("gopkg.in/carolynvs/deptest-gopkgin-implicit-v0.v0", "github.com/carolynvs/deptest-gopkgin-implicit-v0", 0, []Version{
newDefaultBranch("notmaster").Pair(Revision("94ee631b9833cd805d15f50a52e0533124ec0292")),
})
wg.Done()
}()

go func() {
// Use the existing v0 branch for v0, not master
tfunc("gopkg.in/carolynvs/deptest-gopkgin-explicit-v0.v0", "github.com/carolynvs/deptest-gopkgin-explicit-v0", 0, []Version{
newDefaultBranch("v0").Pair(Revision("ec73e84554fb28f08dba630e48dbec868e77f734")),
})
wg.Done()
}()

go func() {
tfunc("gopkg.in/sdboyer/gpkt.v1", "github.com/sdboyer/gpkt", 1, []Version{
NewVersion("v1.1.0").Pair(Revision("b2cb48dda625f6640b34d9ffb664533359ac8b91")),
Expand Down

0 comments on commit 13df556

Please sign in to comment.