获取分叉仓库的工作流程

huangapple go评论89阅读模式
英文:

Go get workflow for forked repo

问题

我正在使用apex,并使用go get github.com/apex/apex/cmd/apex进行安装。我有$GOPATH/bin/apex,它工作得很好。我想对apex做一些贡献,所以我fork了它,并运行了go get github.com/ajcrites/apex/cmd/apex。到目前为止一切都好。

问题出现在我想要测试本地对项目的更改时。我看到有三个问题:

  1. 在本地运行go build不起作用,因为main.go文件直接从$GOPATH/src/github.com/apex导入。我需要它从$GOPATH/src/github.com/ajcrites导入以进行测试。
  2. 手动更改main.go以从ajcrites导入是不稳定的,因为我不能/不应该提交这些更改。而且,即使它使用我的文件构建——我可以通过它们的代码质量判断——生成的二进制文件根本无法工作。
  3. $GOPATH/src/github.com/ajcrites更改为/apex并以这种方式构建是可行的,但存在两个问题:
  • 文件系统目录与实际仓库名称不匹配,这很奇怪。
  • 我仍然希望能够使用/apex中的实际二进制文件,而不仅仅是为了测试本地更改而覆盖它。

有没有推荐的方法来克隆fork的go仓库并在本地构建/测试?

英文:

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?

答案1

得分: 1

如果您不想更改代码中的导入路径,或者将源代码放入项目中,那么不要更改代码所在的GOPATH目录。如果您想更改导入路径,您需要在所有源代码中进行重写,否则会导入多个版本的包。

进入$GOPATH/src/github.com/apex/apex目录,并将origin远程更改为您分叉的存储库。按照惯例,我还会将原始存储库添加为upstream远程,这样我就可以方便地从那里获取和合并更改。

自从go1.6以来,默认启用了供应商支持,您可以将源代码放在您控制的vendor/目录下,并在那里进行修改。使用git子模块也可以让您将其与项目分开进行版本控制,但仍然与项目关联。

英文:

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.

答案2

得分: 0

以下是我为您翻译的内容:

这是我推荐并在GitHub上使用的管理Gorilla组织的流程:

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

# 或者,您可以删除git远程origin并重新添加为SSH
$ git remote add elithrar git@github.com:elithrar/csrf.git

$ git checkout -b new-feature-X
$ <在此进行一些工作>

# 安装这些更改。
$ go install ./...

就是这样。不需要更改任何现有程序中的导入路径。如果您正在使用vendoring来管理依赖项,您只需在vendored副本中进行更改即可。

英文:

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
$ &lt;do some work on it&gt;

# 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.

huangapple
  • 本文由 发表于 2016年3月3日 02:17:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/35755073.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定