简体   繁体   中英

Go get workflow for forked repo

I am using apex and have installed it with go get github.com/apex/apex/cmd/apex . I have $GOPATH/bin/apex which works great. I wanted to make some contributions to apex, so I forked it and ran go get github.com/ajcrites/apex/cmd/apex . So far so good.

The problem comes when I want to actually test my local changes to the project. There are three issues I can see:

  1. Running go build locally doesn't work because the main.go file imports directly from $GOPATH/src/github.com/apex . I need it to import from $GOPATH/src/github.com/ajcrites for the purposes of testing
  2. Changing main.go manually to import from ajcrites is wonky since I can't/shouldn't commit these changes. Moreover even though it does build with my files -- I can tell because it lints them -- the binary that is emitted doesn't work at all.
  3. Changing $GOPATH/src/github.com/ajcrites to /apex and building that way does work, but there are two issues:
    • The file system directory doesn't match the actual repo name which is weird
    • I still want to be able to use the actual binary from /apex without clobbering it just for the purposes of testing local changes

Is there a recommended way to clone forked go repositories and build/test locally?

If you don't want to change the import paths in your code, or vendor the source in your project, don't change directory where the code lies in GOPATH. If you want to change the import path, you will need to rewrite that in all the source, or you end up importing multiple versions of the package.

Go into the $GOPATH/src/github.com/apex/apex directory and change the origin remote to your forked repo. By convention, I also add the original repo as an upstream remote, so I can conveniently fetch and merge changes from there as well.

Since vendoring is enabled by default since go1.6, you can put the source in a vendor/ directory under your control, and make your modifications there. Using git submodules can also allow you to keep it under separate version control, but linked to your project.

Here's the flow I recommend and use for managing the Gorilla organization on GitHub:

$ go get github.com/gorilla/csrf
$ cd $GOPATH/src/github.com/gorilla/csrf

# Alternatively, you can git remote remove origin + re-add as SSH
$ git remote add elithrar git@github.com:elithrar/csrf.git

$ git checkout -b new-feature-X
$ <do some work on it>

# Install those changes.
$ go install ./...

That's it. No need to change import paths in any existing programs. If you're vendoring the dependencies, you can just change it in the vendored copy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM