Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/go: clarify documentation for -replace flag #26417

Closed
komuw opened this issue Jul 17, 2018 · 8 comments
Closed

cmd/go: clarify documentation for -replace flag #26417

komuw opened this issue Jul 17, 2018 · 8 comments
Labels
Documentation FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@komuw
Copy link
Contributor

komuw commented Jul 17, 2018

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +b59b42cee8 Tue Jul 17 10:07:18 2018 +0000 darwin/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/go"
GOMOD="
/mystuff/meli/go.mod"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/p5/56z0g6pj6dq0njc1n6wccz4r0000gn/T/go-build722725015=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

try to use a go module replacement to point to a local repository

git clone https://github.com/pkg/errors to a place outside GOPATH
in your application's go.mod file add a replace directive to point to the cloned github.com/pkg/errors
cat go.mod

replace github.com/pkg/errors => ../errors

try to build your application

What did you expect to see?

  • my application to build succefully without problem(using the cloned errors package)

What did you see instead?

go: parsing ../errors/go.mod: open ~/mystuff/errors/go.mod: no such file or directory
go: error loading module requirements

However, if I manually add a go.mod file to the cloned errors package

echo 'module "github.com/pkg/errors"' >> ~/mystuff/errors/go.mod

I'm able to build my application using that local errors package.

@myitcv myitcv added the modules label Jul 17, 2018
@myitcv
Copy link
Member

myitcv commented Jul 17, 2018

I think this is answered by #25739 (comment). Please shout if not.

@myitcv myitcv closed this as completed Jul 17, 2018
@myitcv
Copy link
Member

myitcv commented Jul 17, 2018

Actually, @rsc @bcmills might we want to slightly enhance the go help mod documentation here?

The -replace=old@v=new@w and -dropreplace=old@v flags
add and drop a replacement of the given module path and version pair.
If the @v in old@v is omitted, the replacement applies to all versions
with the old module path. If the @v in new@v is omitted, the
new path should be a directory on the local system, not a module path.
Note that -replace overrides any existing replacements for old@v.

to read:

... the new path should be a directory on the local system that contains
a module, ...

or some such?

@komuw
Copy link
Contributor Author

komuw commented Jul 17, 2018

yeah, that would be helpful.

also the documentation has a typo( I think). it says

The -replace=old@v=new@w ...

and further down it says

If the @v in new@v is omitted,

I believe the latter should read;

If the @w in new@w is omitted

@bcmills
Copy link
Contributor

bcmills commented Jul 17, 2018

It should read If the @v in old@v is omitted.

@bcmills
Copy link
Contributor

bcmills commented Jul 17, 2018

And maybe, the new path should be a source directory for the module on the local system, not a module path?

@bcmills bcmills reopened this Jul 17, 2018
@komuw
Copy link
Contributor Author

komuw commented Jul 17, 2018

@bcmills
I'm talking about this part;

If the @v in new@v is omitted, the new path should be a directory on the local system

shouldn't it read?

If the @w in new@w is omitted, the new path should be a directory on the local system

@bcmills bcmills changed the title cmd/go: replace directive fails for local packages cmd/go: clarify documentation for -replace flag Jul 17, 2018
@bcmills bcmills added Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Jul 17, 2018
@bcmills bcmills added this to the Go1.11 milestone Jul 17, 2018
@mwf
Copy link

mwf commented Jul 25, 2018

$ go mod -replace foo/bar
go mod: -replace=foo/bar: need old@v=new[@v] (missing =)

As we now allow -replace foo/bar=../ without specifying old version - let's fix the error message accordingly.

old@v=new[@v] -> old[@v]=new[@v]

@bcmills bcmills self-assigned this Jul 25, 2018
@gopherbot
Copy link

Change https://golang.org/cl/126155 mentions this issue: cmd/go: allow unversioned paths to -dropreplace flag

jeet-parekh pushed a commit to jeet-parekh/go that referenced this issue Jul 31, 2018
We can add unversioned paths via -replace;
-dropreplace must be able to drop them.

Fixes golang#26417.

Change-Id: Ic05e9ae2ad80c008e11b195695cbb9d0fc8dbc0a
Reviewed-on: https://go-review.googlesource.com/126155
Run-TryBot: Bryan C. Mills <bcmills@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Russ Cox <rsc@golang.org>
@golang golang locked and limited conversation to collaborators Jul 31, 2019
@rsc rsc unassigned bcmills Jun 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants