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: allow go mod edit a go.mod from stdin #28118

Closed
keegancsmith opened this issue Oct 10, 2018 · 6 comments
Closed

cmd/go: allow go mod edit a go.mod from stdin #28118

keegancsmith opened this issue Oct 10, 2018 · 6 comments

Comments

@keegancsmith
Copy link
Contributor

@keegancsmith keegancsmith commented Oct 10, 2018

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

go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes

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

GOARCH="amd64"
GOBIN="/Users/keegan/go/bin"
GOCACHE="/Users/keegan/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/keegan/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/l7/htgnc72s5bz3lfw9882n_5yw0000gn/T/go-build766629131=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

No way to pass in a go.mod file via stdin to go mod edit -print. We want to run a git filter which removes a replace, to prevent devs accidentally committing it. We tried to work around it via bash tricks of redirecting stdin to a file. What ended up working was quite verbose

# bash
$ GOMOD=<(/dev/stdin) go mod edit -print -dropreplace=github.com/my/example
go: cannot find main module; see 'go help modules'
# also tried GOMOD=-
# this works, but isn't ideal
cp /dev/stdin $TMPDIR/go.mod; cd $TMPDIR; GO111MODULE=on go mod edit -print -dropreplace=github.com/my/example

What did you expect to see?

An option for doing edits on a file via stdin, given you can output via stdout.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Oct 10, 2018

I think I'm missing somethnig. go mod edit -dropreplace should be a no-op if there is no such replacement. Why do you need to process it from stdin for that?

@bcmills bcmills added this to the Unplanned milestone Oct 10, 2018
@bcmills bcmills changed the title Allow go mod edit a go.mod from stdin cmd/go: allow go mod edit a go.mod from stdin Oct 10, 2018
@keegancsmith

This comment has been minimized.

Copy link
Contributor Author

@keegancsmith keegancsmith commented Oct 10, 2018

We want to run a git filter which removes a replace, to prevent devs accidentally committing it.

See filter section on https://git-scm.com/docs/gitattributes. You specify a command which takes the file via stdin and output the contents to actually commit over stdout. We often use replace to a relative directory since we have two closely coupled repos. We are wanting to try out a git filter to avoid accidental commits of the replace one uses in local development.

Additionally, I expected go mod edit would not need to read anything but the go.mod file, so wouldn't need the context of the rest of the modules files, etc. An example where this would be needed outside of our specific use case is editor integration and running go mod edit -fmt on an unsaved file.

@bcmills

This comment has been minimized.

Copy link
Member

@bcmills bcmills commented Oct 10, 2018

I'm curious: why a filter attribute rather than a pre-commit hook?

@keegancsmith

This comment has been minimized.

Copy link
Contributor Author

@keegancsmith keegancsmith commented Oct 10, 2018

heh, good question. I'm not actually sure, I didn't ask that was just trying to help a co-worker acheive that. cc @felixfbecker

@myitcv

This comment has been minimized.

Copy link
Member

@myitcv myitcv commented Nov 14, 2018

@keegancsmith @felixbecker - any update here?

@keegancsmith

This comment has been minimized.

Copy link
Contributor Author

@keegancsmith keegancsmith commented Nov 14, 2018

We no longer are needing to do this. This still seems like a useful feature to have w.r.t. other tooling, but not important. So I'm happy to just close out this issue. Re-open if you think its useful to track.

@golang golang locked and limited conversation to collaborators Nov 14, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
4 participants
You can’t perform that action at this time.