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

Fix how dep status print revision constraints #1421

Merged
merged 3 commits into from
Dec 13, 2017
Merged

Fix how dep status print revision constraints #1421

merged 3 commits into from
Dec 13, 2017

Conversation

otoolec
Copy link
Contributor

@otoolec otoolec commented Dec 1, 2017

What does this do / why do we need it?

Before this fix revision constraints would be printed as an
Any constraint ("*") instead of as the revision itself.

For example, if my Gopkg.toml contains the following:

[[constraint]]
  name = "github.com/codahale/sss"
  revision = "ddeb6f5d27091ff291b16232e99076a64fb375b8"

Then running dep status will print a * for the CONSTRAINT column.

PROJECT                                           CONSTRAINT     VERSION        REVISION  LATEST   PKGS USED
github.com/codahale/sss                           *                             ddeb6f5            1  

But what I would have expected is that it list the constraint in my Gopkg.toml file.

PROJECT                                           CONSTRAINT     VERSION        REVISION  LATEST   PKGS USED
github.com/codahale/sss                           ddeb6f5                       ddeb6f5            1  

What should your reviewer look out for in this PR?

Please make sure that the fix I provided is in the right place and that there wasn't some good reason that dep status wasn't listing the constraint the way I was expecting it to.

Do you need help or clarification on anything?

Should the following loop be run after my new code as well, or only after setting gps.Any()?

for _, c := range cm[bs.ProjectRoot] {

Which issue(s) does this PR fix?

None that I know of.

Before this fix revision constraints would be printed as an
Any constraint ("*") instead of as the revision itself.
bs.Constraint = gps.Any()
for _, c := range cm[bs.ProjectRoot] {
bs.Constraint = c.Constraint.Intersect(bs.Constraint)
if pp, has := p.Manifest.Constraints[proj.Ident().ProjectRoot]; has && pp.Constraint != nil {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess I could collapse this into an else if

if Override {
    // ...
} else if Constraint {
    // ...
} else {
   // Any
}

Copy link
Collaborator

@darkowlzz darkowlzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for finding and fixing it. Looks good to me 👍
An integration test and an entry about this in CHANGELOG.md, and we would be good to have this.

@@ -486,6 +486,8 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
if pp, has := p.Manifest.Ovr[proj.Ident().ProjectRoot]; has && pp.Constraint != nil {
bs.hasOverride = true
bs.Constraint = pp.Constraint
} else if pp, has := p.Manifest.Constraints[proj.Ident().ProjectRoot]; has && pp.Constraint != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment above this block talks about checking in Override. Since with this we check Constraints separately, let's add a comment about that too.

Constraint: gps.Revision("ddeb6f5d27091ff291b16232e99076a64fb375b8"),
},
wantConstraint: "ddeb6f5",
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this. But we need an integration test to test the actual change in result from this PR, because the runStatusAll() is not run by any of the unit tests. You can refer https://github.com/golang/dep/blob/master/cmd/dep/testdata/harness_tests/README.md to learn how to write and run the integration tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good. I'll work on the integration test

@otoolec
Copy link
Contributor Author

otoolec commented Dec 12, 2017

@darkowlzz I've made the requested changes and verified that the new integration test will fail if my code change is removed.

It looks like the code climate tool doesn't like the unit test I added earlier, but believe the test is unique enough to keep and that there isn't any valuable refactoring that could be done to prevent the test from triggering the similar code block check. That said, let me know if you want me to remove the unit test since it isn't really testing the change I'm making in this PR.

@darkowlzz
Copy link
Collaborator

@otoolec I've been seeing these codeclimate issues a lot recently and nothing has changed on our end. And from this tweet, it looks like something has changed in codeclimate and they are working on a fix. So, it's fine for now. I ran their cli tool locally to analyze the code and it showed uncountable number of results related to duplication. If it's actually an issue, we can fix them separately. Not related to this issue.

Also, I overlooked your question about the loop,

Should the following loop be run after my new code as well, or only after setting gps.Any()?

Yes, we need that to set BasicStatus Constraint for projects that are not in the manifest but exist in the project.

Test looks great. Thank you for fixing this.

@darkowlzz darkowlzz merged commit f31d439 into golang:master Dec 13, 2017
@otoolec otoolec deleted the status-revision-constraint branch January 8, 2018 15:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants