简体   繁体   English

如何使用由 dep 管理的开发供应商包?

[英]How to work with a development vendor package managed by dep?

How can I use a development copy/clone of a package while using dep and a vendor directory?如何在使用dep和供应商目录时使用包的开发副本/克隆? The vendor directory is included in the main repository.供应商目录包含在主存储库中。

For example, I have forked package and replaced it with my own on github.例如,我已经 fork 包并将其替换为我自己在 github 上的包。 I want to be able to edit the code and not have to git push + dep ensure for each change of the package.我希望能够编辑代码,而不必为包的每次更改都git push + dep ensure

If I clone the package in the vendor directory, it I won't be able to commit that directory into the main repo because it's treated as a separate repository.如果我在 vendor 目录中克隆包,我将无法将该目录提交到主存储库中,因为它被视为单独的存储库。

I tried a trick to .gitignore the .git directory from outside the package.我尝试了一个技巧来从包外部.gitignore .git目录。 This works well until dep ensure is run, where the .git directory is nuked.这运行良好,直到运行dep ensure ,其中.git目录被破坏。

According to the dep docs , there is no inbuilt way of doing this as it stands.根据dep docs ,目前没有内置的方法可以做到这一点。

They also recommend not modifying packages in the vendor directory directly, for the reasons I discovered: it gets nuked when running dep ensure .他们还建议不要直接修改vendor目录中的包,原因我发现:运行dep ensure时它会被破坏。

Their main suggestion is to manually remove the package from the vendor/ directory, modify it in the regular $GOPATH , and running dep ensure -update <pkg> when finished development of it.他们的主要建议是手动从vendor/目录中删除包,在常规$GOPATH修改它,并在完成开发后运行dep ensure -update <pkg>

This is sufficiently better than pushing for each change, but still requires to manually push / dep ensure when completing the development work.这比每次更改都推送要好得多,但仍然需要在完成开发工作时手动push / dep ensure

An alternative to "ignoring .git " is to keep the .git folder elsewhere! “忽略.git ”的替代方法是将.git文件夹保留在别处! (well outside of your Go project) (在你的 Go 项目之外)

Any time you need to execute a git command in the vendored sub-project, you would need to use an alias to the git command, which would be:任何时候您需要在 vendored 子项目中执行 git 命令,您都需要使用 git 命令的别名,即:

alias gg='git --git-dir=/path/to/elsewhere/.git --work-tree=/path/to/vendored/subproject'
# Windows
doskey gg=git --git-dir=C:\path\to\elsewhere\.git --work-tree=C:\path\to\vendored\subproject $*

That way, you can still benefit from version-controled operations within your vendored subproject.这样,您仍然可以从供应商子项目中的版本控制操作中受益。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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