2013-03-28 75 views
34

无法更新git子模块。遇到错误:github子模块访问权限(Travis CI)

$ git submodule init 
Submodule 'build/html' ([email protected]:quadroid/clonejs.git) registered for path 'build/html' 
... 
$ git submodule update 
Cloning into 'build/html'... 
Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts. 
Permission denied (publickey). 
fatal: Could not read from remote repository. 

完整的日志: https://travis-ci.org/quadroid/clonejs/jobs/5855553

但是当我做本地相同的任务,一切都很好。

+0

通过更改子模块的网址,以固定的git://github.com/quadroid/clonejs.git 但现在我不能在本地推动这个模块... – Quadroid 2013-03-28 05:06:34

+0

使用[部署键(HTTPS:/ /help.github.com/categories/30/articles),或让脚本只在travis中更改URL,而不是在本地 – 2013-03-28 11:05:14

回答

20

我建议使用子模块的https方案,因为这可以让你拉上Travis并在本地推送:https://github.com/quadroid/clonejs.git

62

通过在Travis上即时修改.gitmodules文件,以便在初始化子模块之前将SSH URL替换为公用URL,可以(很庆幸地)轻松解决此问题。要做到这一点,添加以下到.travis.yml:

# Handle git submodules yourself 
git: 
    submodules: false 
# Use sed to replace the SSH URL with the public URL, then initialize submodules 
before_install: 
    - sed -i 's/[email protected]:/https:\/\/github.com\//' .gitmodules 
    - git submodule update --init --recursive 

感谢Michael Iedema他gist从中我得出这一解决方案。

如果你的子模块的私人仓库,它应该工作,包括在https网址凭证,我建议在做针对此用途受限权限的GitHub access token

# Replace <user> and <token> with your GitHub username and access token respectively 
- sed -i 's/[email protected]:/https:\/\/<user>:<token>@github.com\//' .gitmodules 
+3

到目前为止,这是迄今为止这个问题的最佳解决方案! – 2014-07-09 07:51:12

+0

@StefanDragnev谢谢,我的目标是取悦;) – aknuds1 2014-07-09 17:23:44

+1

这似乎不适用于私人存储库。所有这些私人存储库都在同一个github帐户下,并开启了travis。任何人都有线索?谢谢。 – inder 2014-07-17 17:59:41

11

特拉维斯现在支持使用ssh访问子模块,其是迄今为止最简单的解决方案。您只需将您的ssh密钥(或专用CI用户的ssh密钥)与您正在构建的Github项目相关联,如documentation for private dependencies中所述。

$ travis sshkey --upload ~/.ssh/id_rsa -r myorg/main

注意,特拉维斯建议创建一个专用的用户,这样你就不必使用自己的SSH密钥。

+1

为了使这个解释更加完整;找到一个可以访问Travis正在构建的仓库和子模块(Travis建议为此创建一个特定的CI用户)的用户,然后运行这个命令*执行构建*的repo。 – thoutbeckers 2014-09-04 16:46:17

+1

它不是在travis.org上可用(只有travis.com,不是免费的) – Toilal 2014-09-24 04:46:57

+0

这并不能真正提高安全性吗?让你的github密钥传播.. – matanster 2015-10-29 13:17:30

5

你得到这个错误是因为你通过ssh-urls指定了子模块。对于travis-ci环境下的ssh访问,您需要configure a key

另外,你可以使用相对的URL为你的git子模块,因为你的项目和你的子模块都在Github上可用。

Git针对ORIGIN解析相关网址。

例子:

使用从.gitmodules第2项:

[submodule "lib/es5-shim"] 
     path = lib/es5-shim 
     url = [email protected]:kriskowal/es5-shim.git 
[submodule "build/html"] 
     path = build/html 
     url = [email protected]:quadroid/clonejs.git 

替换为相对URL:

[submodule "lib/es5-shim"] 
     path = lib/es5-shim 
     url = ../../kriskowal/es5-shim.git 
[submodule "build/html"] 
     path = build/html 
     url = ../clonejs.git 

然后,当克隆 - 说 - 通过HTTPS原点设置像这样:

$ git clone https://github.com/quadroid/clonejs.git 
$ cd clonejs 
$ git remote -v 
origin https://github.com/quadroid/clonejs.git (fetch) 
origin https://github.com/quadroid/clonejs.git (push) 

当通过SSH克隆:

$ git clone [email protected]:quadroid/clonejs.git 
$ cd clonejs 
$ git remote -v         
origin [email protected]:quadroid/clonejs.git (fetch) 
origin [email protected]:quadroid/clonejs.git (push) 

相对URL,通常的子模块顺序独立工作的由来:

$ git submodule init 
$ git submodule update 
+0

在我的情况下,相对URL的工作非常好,这可能是最优雅的公共回购解决方案。感谢您提出这项技术! – matanster 2015-10-24 01:50:22

+0

令人讨厌的是,它似乎打破了github的自动超链接到submodules github页面。 – matanster 2015-10-24 02:02:03

+0

这不适用于私人子模块。 Travis似乎隐藏了它使用私有令牌访问回购的事实,但是在克隆子模块时却没有这样做。 – 2017-10-17 23:51:37

0

用户也可以直接通过直接操纵git您.gitmodules文件。 (受this answer的启发)。

git config --file=.gitmodules submodule.SUBMODULE_PATH.url https://github.com/ORG/REPO.git