在使用go get时,在Travis CI构建中默认检出Git主分支。

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

Default Git master branch checkout in Travis CI build when using go get

问题

我在尝试使用Travis CI构建时遇到了一些困难。

我正在使用Parse(.com)作为后端,并找到了一个使用Travis进行构建和部署的示例这里。然而,尽管我尽力进行了设置,但我现在遇到了一个Google无法解决的问题。

我从Travis CI构建日志中得到了以下错误信息:

....
$ mkdir -p "$TRAVIS_BUILD_DIR/gosrc"
$ mkdir -p "$TRAVIS_BUILD_DIR/static"
$ curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
$ go get -v github.com/xxxxx/xxxxxxx
github.com/xxxxxx/xxxxxx (download)
cd /home/travis/build/xxxxx/xxxxx/gosrc/src/github.com/xxxxxx/xxxxxx; git checkout master

error: pathspec 'master' did not match any file(s) known to git.

package github.com/xxxxx/xxxxxx: exit status 1

The command "go get -v github.com/xxxxxx/xxxxxx" failed and exited with 1 during .
Your build has been stopped.

这是我的.travis.yml文件中的安装部分:

install:
- mkdir -p "$TRAVIS_BUILD_DIR/gosrc"
- mkdir -p "$TRAVIS_BUILD_DIR/static"
- curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
- go get -v github.com/xxxxxx/xxxxxxx

我的问题是:在执行go get {git repo}时,是否可以指定它应该检出哪个分支?这样它就不会默认检出master分支。如果不能,是否有更好的方法来做到这一点?

注意:我在我的存储库中没有主分支,因为我一段时间前将其删除了,因为我没有使用它。我需要添加一个主分支才能使其工作吗?

如果问题不清楚或缺少必要的信息,请告诉我。

非常感谢任何帮助!

英文:

I'm having some difficulties getting my first attempts at an Travis CI build working.

I'm using Parse(.com) as a backend and have then found an example of using Travis for build and deployment here. However having tried to set it up as best I could I now gotten to a problem which Google can't help with.

I'm getting this error from the Travis CI build log.

....
$ mkdir -p "$TRAVIS_BUILD_DIR/gosrc"
$ mkdir -p "$TRAVIS_BUILD_DIR/static"
$ curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
$ go get -v github.com/xxxxx/xxxxxxx
github.com/xxxxxx/xxxxxx (download)
cd /home/travis/build/xxxxx/xxxxx/gosrc/src/github.com/xxxxxx/xxxxxx; git checkout master

error: pathspec 'master' did not match any file(s) known to git.

package github.com/xxxxx/xxxxxx: exit status 1

The command "go get -v github.com/xxxxxx/xxxxxx" failed and exited with 1 during .
Your build has been stopped.

This is my install section of the .travis.yml file

install:
- mkdir -p "$TRAVIS_BUILD_DIR/gosrc"
- mkdir -p "$TRAVIS_BUILD_DIR/static"
- curl -s https://www.parse.com/downloads/cloud_code/installer.sh | sudo /bin/bash
- go get -v github.com/xxxxxx/xxxxxxx

My question is: Can you, when conducting a go get {git repo}, specify which branch it's supposed to checkout? So it doesn't default to master. If not is there a better way of doing this?

Note: I don't have a master branch in my repository, having removed it some time ago because I didn't use it. Do I need to add one for this to work?

Please let me know if the question is unclear or if it's missing some needed information.

Thankful for any help!

答案1

得分: 1

简短回答是不可以,你不能使用go get指定分支或标签。然而,如果你检查一下go工具的源代码,你会发现在克隆时它实际上也没有指定master。它只是克隆了整个仓库。这可能是一个git/GitHub的问题。

你可以尝试在终端中克隆该仓库到其他位置,看看是否会报错找不到master分支。仓库有一个设置,用于指定默认分支,如果它仍然默认为master,即使你没有该分支,你将会看到错误。我通过创建一个没有master分支的GitHub仓库来复现了这个问题。我通过进入GitHub仓库的设置并指定默认分支来解决了这个问题。

注意:如果你的本地仓库处于分离头状态,go get命令将会指定master分支。从输出来看,我不认为这是发生在这里的情况。

英文:

The short answer is that No, you can't specify a branch or tag with go get. However, if you inspect the source of the go tool you will see that it doesn't really specify master either when it's doing a clone. It just clones the repo. This is probably really a git/GitHub issue.

Can you open a terminal and just clone that repo to some other location? Does it give you a complaint about not having the master branch? Repositories have a setting for which branch should be the default and if it's still defaulting to master even though you don't have one then you'll see the error. I reproduced this by making a GitHub repo without a master branch. I was able to fix it by going into my GitHub repo settings and specifying the default branch.

Note: The go get command will specify the master branch if your local repo is in a detached head state. Looking at the output I don't think that's what's happening here.

huangapple
  • 本文由 发表于 2015年6月5日 17:20:36
  • 转载请务必保留本文链接:https://go.coder-hub.com/30662849.html
匿名

发表评论

匿名网友

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

确定