Merge pull request #1216 from darkowlzz/status-mismatch-ignore

fix(status): skip ignored pkgs in missing pkgs chk
This commit is contained in:
sam boyer 2017-10-04 07:41:44 -04:00 коммит произвёл GitHub
Родитель 67e867833a 7c5da1277f
Коммит 0edac3f3d3
14 изменённых файлов: 114 добавлений и 30 удалений

Просмотреть файл

@ -1,5 +1,10 @@
# v0.3.2 (Unreleased) # v0.3.2 (Unreleased)
BUG FIXES:
* Fix `status` shows incorrect reason for lock mismatch when ignoring packages.
(#1216)
IMPROVEMENTS: IMPROVEMENTS:
* `dep ensure -add` now concurrently fetches the source and adds the projects. * `dep ensure -add` now concurrently fetches the source and adds the projects.

Просмотреть файл

@ -49,9 +49,10 @@ const (
) )
var ( var (
errFailedUpdate = errors.New("failed to fetch updates") errFailedUpdate = errors.New("failed to fetch updates")
errFailedListPkg = errors.New("failed to list packages") errFailedListPkg = errors.New("failed to list packages")
errMultipleFailures = errors.New("multiple sources of failure") errMultipleFailures = errors.New("multiple sources of failure")
errInputDigestMismatch = errors.New("input-digest mismatch")
) )
func (cmd *statusCommand) Name() string { return "status" } func (cmd *statusCommand) Name() string { return "status" }
@ -235,36 +236,35 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
} }
} }
digestMismatch, hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm) hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm)
if err != nil { if err != nil {
// If it's only update errors switch err {
if err == errFailedUpdate { case errFailedUpdate:
// Print the results with unknown data // Print the results with unknown data
ctx.Out.Println(buf.String()) ctx.Out.Println(buf.String())
// Print the help when in non-verbose mode // Print the help when in non-verbose mode
if !ctx.Verbose { if !ctx.Verbose {
ctx.Out.Printf("The status of %d projects are unknown due to errors. Rerun with `-v` flag to see details.\n", errCount) ctx.Out.Printf("The status of %d projects are unknown due to errors. Rerun with `-v` flag to see details.\n", errCount)
} }
} else { case errInputDigestMismatch:
// List package failure or multiple failures // Tell the user why mismatch happened and how to resolve it.
if hasMissingPkgs {
ctx.Err.Printf("Lock inputs-digest mismatch due to the following packages missing from the lock:\n\n")
ctx.Out.Print(buf.String())
ctx.Err.Printf("\nThis happens when a new import is added. Run `dep ensure` to install the missing packages.\n")
} else {
ctx.Err.Printf("Lock inputs-digest mismatch. This happens when Gopkg.toml is modified.\n" +
"Run `dep ensure` to regenerate the inputs-digest.")
}
default:
ctx.Out.Println("Failed to get status. Rerun with `-v` flag to see details.") ctx.Out.Println("Failed to get status. Rerun with `-v` flag to see details.")
} }
return err return err
} }
if digestMismatch { // Print the status output
if hasMissingPkgs { ctx.Out.Print(buf.String())
ctx.Err.Printf("Lock inputs-digest mismatch due to the following packages missing from the lock:\n\n")
ctx.Out.Print(buf.String())
ctx.Err.Printf("\nThis happens when a new import is added. Run `dep ensure` to install the missing packages.\n")
} else {
ctx.Err.Printf("Lock inputs-digest mismatch. This happens when Gopkg.toml is modified.\n" +
"Run `dep ensure` to regenerate the inputs-digest.")
}
} else {
ctx.Out.Print(buf.String())
}
return nil return nil
} }
@ -352,16 +352,16 @@ type MissingStatus struct {
MissingPackages []string MissingPackages []string
} }
func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager) (digestMismatch bool, hasMissingPkgs bool, errCount int, err error) { func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager) (hasMissingPkgs bool, errCount int, err error) {
if p.Lock == nil { if p.Lock == nil {
return false, false, 0, errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file") return false, 0, errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file")
} }
// While the network churns on ListVersions() requests, statically analyze // While the network churns on ListVersions() requests, statically analyze
// code from the current project. // code from the current project.
ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot)) ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot))
if err != nil { if err != nil {
return false, false, 0, errors.Wrapf(err, "analysis of local packages failed") return false, 0, errors.Wrapf(err, "analysis of local packages failed")
} }
// Set up a solver in order to check the InputHash. // Set up a solver in order to check the InputHash.
@ -381,12 +381,12 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
} }
if err := ctx.ValidateParams(sm, params); err != nil { if err := ctx.ValidateParams(sm, params); err != nil {
return false, false, 0, err return false, 0, err
} }
s, err := gps.Prepare(params, sm) s, err := gps.Prepare(params, sm)
if err != nil { if err != nil {
return false, false, 0, errors.Wrapf(err, "could not set up solver for input hashing") return false, 0, errors.Wrapf(err, "could not set up solver for input hashing")
} }
cm := collectConstraints(ptree, p, sm) cm := collectConstraints(ptree, p, sm)
@ -557,7 +557,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
out.BasicFooter() out.BasicFooter()
return false, false, errCount, err return false, errCount, err
} }
// Hash digest mismatch may indicate that some deps are no longer // Hash digest mismatch may indicate that some deps are no longer
@ -566,7 +566,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
// //
// It's possible for digests to not match, but still have a correct // It's possible for digests to not match, but still have a correct
// lock. // lock.
rm, _ := ptree.ToReachMap(true, true, false, nil) rm, _ := ptree.ToReachMap(true, true, false, p.Manifest.IgnoredPackages())
external := rm.FlattenFn(paths.IsStandardImportPath) external := rm.FlattenFn(paths.IsStandardImportPath)
roots := make(map[gps.ProjectRoot][]string, len(external)) roots := make(map[gps.ProjectRoot][]string, len(external))
@ -598,7 +598,7 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
ctx.Err.Printf("\t%s: %s\n", fail.ex, fail.err.Error()) ctx.Err.Printf("\t%s: %s\n", fail.ex, fail.err.Error())
} }
return true, false, 0, errors.New("address issues with undeducible import paths to get more status information") return false, 0, errors.New("address issues with undeducible import paths to get more status information")
} }
out.MissingHeader() out.MissingHeader()
@ -618,7 +618,8 @@ outer:
} }
out.MissingFooter() out.MissingFooter()
return true, hasMissingPkgs, 0, nil // We are here because of an input-digest mismatch. Return error.
return hasMissingPkgs, 0, errInputDigestMismatch
} }
func formatVersion(v gps.Version) string { func formatVersion(v gps.Version) string {

9
cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/final/Gopkg.lock сгенерированный поставляемый Normal file
Просмотреть файл

@ -0,0 +1,9 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
solver-name = "gps-cdcl"
solver-version = 1

Просмотреть файл

@ -0,0 +1,2 @@
ignored = ["github.com/sdboyer/deptestdos"]

9
cmd/dep/testdata/harness_tests/status/ignore_lock_mismatch/initial/Gopkg.lock сгенерированный поставляемый Normal file
Просмотреть файл

@ -0,0 +1,9 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
solver-name = "gps-cdcl"
solver-version = 1

Просмотреть файл

@ -0,0 +1,2 @@
ignored = ["github.com/sdboyer/deptestdos"]

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
_ "github.com/sdboyer/deptestdos"
)
func main() {
}

Просмотреть файл

@ -0,0 +1,7 @@
{
"commands": [
["status"]
],
"error-expected": "This happens when Gopkg.toml is modified",
"vendor-final": []
}

9
cmd/dep/testdata/harness_tests/status/missing_pkgs_lock_mismatch/final/Gopkg.lock сгенерированный поставляемый Normal file
Просмотреть файл

@ -0,0 +1,9 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
solver-name = "gps-cdcl"
solver-version = 1

Просмотреть файл

9
cmd/dep/testdata/harness_tests/status/missing_pkgs_lock_mismatch/initial/Gopkg.lock сгенерированный поставляемый Normal file
Просмотреть файл

@ -0,0 +1,9 @@
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "ab4fef131ee828e96ba67d31a7d690bd5f2f42040c6766b1b12fe856f87e0ff7"
solver-name = "gps-cdcl"
solver-version = 1

Просмотреть файл

Просмотреть файл

@ -0,0 +1,12 @@
// Copyright 2017 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
_ "github.com/sdboyer/deptestdos"
)
func main() {
}

Просмотреть файл

@ -0,0 +1,7 @@
{
"commands": [
["status"]
],
"error-expected": "due to the following packages missing from the lock",
"vendor-final": []
}