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

Commit 13df556

Browse files
authored
Merge pull request #1243 from carolynvs/gopkgin-v0-panic
gps: fix panic for gopkgin's implicit v0
2 parents 9d269a6 + 770a444 commit 13df556

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ BUG FIXES:
77
* Suppress git password prompts in more places (#1357).
88
* Fix `-no-vendor` flag for `ensure -update` (#1361).
99
* Validate `git ls-remote` output and ignore all malformed lines (#1379)
10+
* Support [gopkg.in version zero](http://labix.org/gopkg.in#VersionZero) (#1243).
1011

1112
IMPROVEMENTS:
1213

gps/vcs_source.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -410,23 +410,34 @@ func (s *gopkginSource) listVersions(ctx context.Context) ([]PairedVersion, erro
410410
k := 0
411411
var dbranch int // index of branch to be marked default
412412
var bsv semver.Version
413+
var defaultBranch PairedVersion
414+
tryDefaultAsV0 := s.major == 0
413415
for _, v := range ovlist {
414416
// all git versions will always be paired
415417
pv := v.(versionPair)
416418
switch tv := pv.v.(type) {
417419
case semVersion:
420+
tryDefaultAsV0 = false
418421
if tv.sv.Major() == s.major && !s.unstable {
419422
vlist[k] = v
420423
k++
421424
}
422425
case branchVersion:
426+
if tv.isDefault && defaultBranch == nil {
427+
defaultBranch = pv
428+
}
429+
423430
// The semver lib isn't exactly the same as gopkg.in's logic, but
424431
// it's close enough that it's probably fine to use. We can be more
425432
// exact if real problems crop up.
426433
sv, err := semver.NewVersion(tv.name)
427-
if err != nil || sv.Major() != s.major {
428-
// not a semver-shaped branch name at all, or not the same major
429-
// version as specified in the import path constraint
434+
if err != nil {
435+
continue
436+
}
437+
tryDefaultAsV0 = false
438+
439+
if sv.Major() != s.major {
440+
// not the same major version as specified in the import path constraint
430441
continue
431442
}
432443

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

475+
// Treat the default branch as v0 only when no other semver branches/tags exist
476+
// See http://labix.org/gopkg.in#VersionZero
477+
if tryDefaultAsV0 && defaultBranch != nil {
478+
vlist = append(vlist, defaultBranch)
479+
}
480+
464481
return vlist, nil
465482
}
466483

gps/vcs_source_test.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -214,11 +214,11 @@ func testGopkginSourceInteractions(t *testing.T) {
214214

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

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

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

250250
// simultaneously run for v1, v2, and v3 filters of the target repo
251251
wg := &sync.WaitGroup{}
252-
wg.Add(4)
252+
wg.Add(6)
253+
254+
go func() {
255+
// Treat master as v0 when no other branches/tags exist that match gopkg.in's rules
256+
tfunc("gopkg.in/carolynvs/deptest-gopkgin-implicit-v0.v0", "github.com/carolynvs/deptest-gopkgin-implicit-v0", 0, []Version{
257+
newDefaultBranch("notmaster").Pair(Revision("94ee631b9833cd805d15f50a52e0533124ec0292")),
258+
})
259+
wg.Done()
260+
}()
261+
262+
go func() {
263+
// Use the existing v0 branch for v0, not master
264+
tfunc("gopkg.in/carolynvs/deptest-gopkgin-explicit-v0.v0", "github.com/carolynvs/deptest-gopkgin-explicit-v0", 0, []Version{
265+
newDefaultBranch("v0").Pair(Revision("ec73e84554fb28f08dba630e48dbec868e77f734")),
266+
})
267+
wg.Done()
268+
}()
269+
253270
go func() {
254271
tfunc("gopkg.in/sdboyer/gpkt.v1", "github.com/sdboyer/gpkt", 1, []Version{
255272
NewVersion("v1.1.0").Pair(Revision("b2cb48dda625f6640b34d9ffb664533359ac8b91")),

0 commit comments

Comments
 (0)