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

replace versionInworkspace() stub #27

Merged
merged 8 commits into from
Dec 6, 2016
Merged

replace versionInworkspace() stub #27

merged 8 commits into from
Dec 6, 2016

Conversation

jessfraz
Copy link
Contributor

@jessfraz jessfraz commented Dec 3, 2016

fix #21

@sdboyer
Copy link
Member

sdboyer commented Dec 3, 2016

aaawesome, glad to see this move.

a few things to consider here:

  • remote/canonical does not have local data (unpushed tags). dvcs only
  • local data is modified vs remote/canonical (unpushed commits on a branch). dvcs only
  • dirty working tree. that might mean uncommitted changes, or entirely untracked files

maybe we just ignore these entirely. maybe we put in a general disclaimer note to the user that such things will trip up the init importer.

@jessfraz
Copy link
Contributor Author

jessfraz commented Dec 5, 2016

added some initial tests

@jessfraz
Copy link
Contributor Author

jessfraz commented Dec 5, 2016

so this is big because i added tests


func newContext() *ctx {
// this way we get the default GOPATH that was added in 1.8
buildContext := build.Default
Copy link
Member

Choose a reason for hiding this comment

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

Why the additional assignment?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

OK, but build.Default is the value returned from that function call, not itself a function, so this seems unnecessary?

Or is this a way of guarding against an out-of-order initialization problem, since both of these assignments end up being made as a result of function calls on package var init?

Copy link
Contributor Author

@jessfraz jessfraz Dec 6, 2016

Choose a reason for hiding this comment

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

I was more trying to protect us, if we wanted other things from buildContext, from re-calling that function

Copy link
Member

Choose a reason for hiding this comment

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

OK, nbd anyway, it's really just a nit. The thing actually worth discussing is the gopath/splitlist stuff, i think

case "github.com/termie/go-shutil":
return gps.NewBranch("master").Is("4239b77079c7b5d1243b7b4736304ce8ddb6f0f2"), nil
func (c *ctx) versionInWorkspace(root gps.ProjectRoot) (gps.Version, error) {
pr, err := c.absoluteProjectRoot(string(root))
Copy link
Member

Choose a reason for hiding this comment

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

So, I realize you're just doing a a 1:1 change from before, but by moving these methods onto the ctx object, it seems like we need to do away with the loop over all the possible GOPATH workspaces. Instead, we should do it in newContext(), and pick exactly one GOPATH to use then and there, based on the current working directory.

That way these method calls will always and only search the one workspace, which I think is our desired behavior for all the methods on there.

Copy link
Member

Choose a reason for hiding this comment

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

That'd also let us do away with the second return param from determineProjectRoot, as that state would be carried in the ctx object itself.

return nil, errors.Wrapf(err, "determine project root for %s", root)
}

repo, err := vcs.NewRepo("", string(pr))
Copy link
Member

Choose a reason for hiding this comment

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

Hah...I'm glad an empty first param works. I don't think they'd ever anticipated it, but if it does...awesome.


func TestIsStdLib(t *testing.T) {
tests := map[string]bool{
"github.com/sirupsen/logrus": false,
Copy link
Member

Choose a reason for hiding this comment

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

supernit: s/sirupsen/Sirupsen/

(i think he actually switched his own nick to be uncapitalized recently, but we should be consistent in how we refer to it in the tests)

gopath := os.Getenv("GOPATH")
for _, gp := range filepath.SplitList(gopath) {
posspath := filepath.Join(gp, "src", path)
f, err := os.Stat(posspath)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd make an isDir function for this

return nil, errors.Wrapf(err, "finding current branch/version for root: %s", pr)
}

sha, err := repo.Version()
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe 'rev' ?


func TestInit(t *testing.T) {
// test must also have external network
if _, err := exec.LookPath("git"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we need a needsGit method at some point

//
// The second returned string indicates which GOPATH value was used.
// TODO: rename this appropriately
func (c *ctx) determineProjectRoot(path string) (string, string, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

These should be colocated with the ctx type declaration.

func getSourceManager() (*gps.SourceMgr, error) {
gopath := os.Getenv("GOPATH")
if gopath == "" {
func (c *ctx) getSourceManager() (*gps.SourceMgr, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

rename 'sourceManager'

tg.setenv("GOPATH", tg.path("."))
depCtx := &ctx{GOPATH: tg.path(".")}

importPaths := map[string]bool{
Copy link
Contributor

Choose a reason for hiding this comment

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

should also have a case for a file where a dir is expected, or something. if that's possible

@@ -70,6 +72,39 @@ func TestIsStdLib(t *testing.T) {
}
}

func TestVersionInWorkspace(t *testing.T) {
// test must also have external network
if _, err := exec.LookPath("git"); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

another usage for that helper

Signed-off-by: Jess Frazelle <[email protected]>
Signed-off-by: Jess Frazelle <[email protected]>
Moved all functions that use ctx to context.go

Created a test helper for `needsGit` and `needsExternalNetwork`

Added a test case for `absoluteProjectPath` to make sure a file will error out

Renamed `getSourceManager` to `sourceManager`

Signed-off-by: Jess Frazelle <[email protected]>
@jessfraz
Copy link
Contributor Author

jessfraz commented Dec 6, 2016

Addressed all comments except this one: #27 (comment) which I'm hoping in pairing with Sam tomorrow I can get an idea of what he's thinking :)

@sdboyer
Copy link
Member

sdboyer commented Dec 6, 2016

IMO we can merge and fix in pairing tomorrow - no need to bloat this PR more :)

@jessfraz
Copy link
Contributor Author

jessfraz commented Dec 6, 2016

sweet yeah thats what I was hoping for figured we could just do it together real fast

@jessfraz jessfraz merged commit 35349ab into golang:master Dec 6, 2016
@jessfraz jessfraz deleted the replace-versionInWorkspace-stub branch December 6, 2016 02:17
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace versionInWorkspace() stub
3 participants