Go에서 분기 된 패키지 가져 오기 사용
에 저장소가 github.com/someone/repo
있고 github.com/you/repo
. 메인 저장소 대신 포크를 사용하고 싶으므로
go get github.com/you/repo
이제이 저장소의 모든 가져 오기 경로가 "끊어집니다". 즉, 절대 URL을 통해 서로를 참조하는 저장소에 여러 패키지가있는 경우 포크가 아닌 소스를 참조합니다.
올바른 경로로 수동으로 복제하는 더 좋은 방법이 있습니까?
git clone git@github.com:you/repo.git $GOPATH/src/github.com/someone/repo
pull 요청을 처리하려면
- 저장소
github.com/someone/repo
를 포크 하다github.com/you/repo
- 원본 코드 다운로드 :
go get github.com/someone/repo
- 거기 :
cd "$(go env GOPATH)/src"/github.com/someone/repo
- 포크에 업로드 활성화 :
git remote add myfork https://github.com/you/repo.git
- 변경 사항을 저장소에 업로드하십시오.
git push myfork
http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html
프로젝트에서 패키지를 사용하려면
https://github.com/golang/go/wiki/PackageManagementTools
이를 해결하는 한 가지 방법은 Ivan Rave와 http://blog.campoy.cat/2014/03/github-and-go-forking-pull-requests-and.html ( 포킹 방법 )이 제안한 것입니다.
또 다른 방법은 golang 동작 을 해결하는 것 입니다. 당신이 go get
, golang 은 저장소 URI와 같은 이름으로 디렉토리를 배치하고 여기서 문제가 시작됩니다.
대신 고유 한을 발급 git clone
하는 경우 원본 저장소의 이름을 딴 경로에서 파일 시스템에 저장소를 복제 할 수 있습니다.
원래 저장소가에 github.com/awsome-org/tool
있고이를에 포크 한다고 가정하면 github.com/awesome-you/tool
다음을 수행 할 수 있습니다.
cd $GOPATH
mkdir -p {src,bin,pkg}
mkdir -p src/github.com/awesome-org/
cd src/github.com/awesome-org/
git clone git@github.com:awesome-you/tool.git # OR: git clone https://github.com/awesome-you/tool.git
cd tool/
go get ./...
golang 은이 리포지토리를 계속 사용하게되어 기쁩니다. 실제로 awesome-org
git remote가 awesome-you
. 에 대한 모든 가져 오기 awesome-org
는 방금 만든 디렉터리 인 로컬 작업 집합을 통해 다시 요청됩니다.
자세한 내용은 내 블로그 게시물 : GitHub에서 Golang 리포지토리 포크 및 가져 오기 경로 관리 를 참조하세요.
편집 : 고정 디렉토리 경로
포크가 일시적인 경우 (예 : 병합하려는 경우) 현장에서 개발을 수행하십시오 (예 : $GOPATH/src/launchpad.net/goamz
.
그런 다음 버전 제어 시스템의 기능 (예 :) git remote
을 사용하여 업스트림 저장소를 원래 저장소가 아닌 저장소로 만듭니다.
다른 사람들이 저장소를 사용하기 어렵게 go get
하지만 업스트림에 통합하기가 훨씬 쉽습니다.
사실 저는 lp:~nick-craig-wood/goamz/goamz
정확히 그런 방식으로 개발하는 goamz 저장소를 가지고 있습니다 . 아마도 저자는 언젠가 그것을 병합 할 것입니다!
go 모듈을 사용하는 경우 . replace
지시문을 사용할 수 있습니다.
이
replace
지시문을 사용하면 VCS (GitHub 또는 다른 곳)에있는 다른 모듈이거나 상대 또는 절대 파일 경로가있는 로컬 파일 시스템에있는 다른 가져 오기 경로를 제공 할 수 있습니다.replace
지시문 의 새 가져 오기 경로 는 실제 소스 코드에서 가져 오기 경로를 업데이트 할 필요없이 사용됩니다.
그래서 당신은 아래에서 할 수 있습니다
module github.com/yogeshlonkar/openapi-to-postman
go 1.12
require (
github.com/someone/repo v1.20.0
)
replace github.com/someone/repo => github.com/you/repo master
모든 사람에게 적합한 방법은 다음과 같습니다.
github를 사용하여 "my / repo"로 포크합니다 (예제) :
go get github.com/my/repo
cd ~/go/src/github.com/my/repo
git branch enhancement
rm -rf .
go get github.com/golang/tools/cmd/gomvpkg/…
gomvpkg <<oldrepo>> ~/go/src/github.com/my/repo
git commit
Repeat each time when you make the code better:
git commit
git checkout enhancement
git cherry-pick <<commit_id>>
git checkout master
Why? This lets you have your repo that any go get
works with. It also lets you maintain & enhance a branch that's good for a pull request. It doesn't bloat git with "vendor", it preserves history, and build tools can make sense of it.
The answer to this is that if you fork a repo with multiple packages you will need to rename all the relevant import paths. This is largely a good thing since you've forked all of those packages and the import paths should reflect this.
Use vendoring and submodules together
- Fork the lib on github (go-mssqldb in this case)
- Add a submodule which clones your fork into your vendor folder but has the path of the upstream repo
- Update your
import
statements in your source code to point to the vendor folder, (not including thevendor/
prefix). E.g.vendor/bob/lib
=>import "bob/lib"
E.g.
cd ~/go/src/github.com/myproj
mygithubuser=timabell
upstreamgithubuser=denisenkom
librepo=go-mssqldb
git submodule add "git@github.com:$mygithubuser/$librepo" "vendor/$upstreamgithubuser/$librepo"
Why
This solves all the problems I've heard about and come across while trying to figure this out myself.
- Internal package refs in the lib now work because the path is unchanged from upstream
- A fresh checkout of your project works because the submodule system gets it from your fork at the right commit but in the upstream folder path
- You don't have to know to manually hack the paths or mess with the go tooling.
More info
- https://git-scm.com/book/en/v2/Git-Tools-Submodules
- How do I fix the error message "use of an internal package not allowed" when go getting a golang package?
- https://github.com/denisenkom/go-mssqldb/issues/406
- https://github.com/golang/go/wiki/PackageManagementTools#go15vendorexperiment
To automate this process, I wrote a small script. You can find more details on my blog to add a command like "gofork" to your bash.
function gofork() {
if [ $# -ne 2 ] || [ -z "$1" ] || [ -z "$2" ]; then
echo 'Usage: gofork yourFork originalModule'
echo 'Example: gofork github.com/YourName/go-contrib github.com/heirko/go-contrib'
return
fi
echo "Go get fork $1 and replace $2 in GOPATH: $GOPATH"
go get $1
go get $2
currentDir=$PWD
cd $GOPATH/src/$1
remote1=$(git config --get remote.origin.url)
cd $GOPATH/src/$2
remote2=$(git config --get remote.origin.url)
cd $currentDir
rm -rf $GOPATH/src/$2
mv $GOPATH/src/$1 $GOPATH/src/$2
cd $GOPATH/src/$2
git remote add their $remote2
echo Now in $GOPATH/src/$2 origin remote is $remote1
echo And in $GOPATH/src/$2 their remote is $remote2
cd $currentDir
}
export -f gofork
in your Gopkg.toml
file add these block below
[[constraint]]
name = "github.com/globalsign/mgo"
branch = "master"
source = "github.com/myfork/project2"
So it will use the forked project2
in place of github.com/globalsign/mgo
참고URL : https://stackoverflow.com/questions/14323872/using-forked-package-import-in-go
'developer tip' 카테고리의 다른 글
PostgreSQL : CREATE TABLE 정의에서 인덱스를 생성 할 수 있습니까? (0) | 2020.09.10 |
---|---|
팬더 적용 함수에서 행의 인덱스 가져 오기 (0) | 2020.09.10 |
겹치는 직사각형을 간격을 두는 알고리즘? (0) | 2020.09.10 |
Python에서 numpy.random과 random.random의 차이점 (0) | 2020.09.10 |
Node.js + Express : 경로 대 컨트롤러 (0) | 2020.09.10 |