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

拥有回忆 提交于 2020-01-23 03:27:05

问题


How can I use a development copy/clone of a package while using dep and a vendor directory? The vendor directory is included in the main repository.

For example, I have forked package and replaced it with my own on github. I want to be able to edit the code and not have to git push + dep ensure for each change of the package.

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.

I tried a trick to .gitignore the .git directory from outside the package. This works well until dep ensure is run, where the .git directory is nuked.


回答1:


According to the dep docs, there is no inbuilt way of doing this as it stands.

They also recommend not modifying packages in the vendor directory directly, for the reasons I discovered: it gets nuked when running 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.

This is sufficiently better than pushing for each change, but still requires to manually push/dep ensure when completing the development work.




回答2:


An alternative to "ignoring .git" is to keep the .git folder elsewhere! (well outside of your Go project)

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:

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.



来源:https://stackoverflow.com/questions/48031621/how-to-work-with-a-development-vendor-package-managed-by-dep

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!