如何使用用户名和密码从私有GitLab仓库下载单个原始文件

10

以下命令可以使用用户名和密码克隆私有仓库

git clone https://some-git-lab-token:someHash@git.xxx.com/foo/bar.git

我想知道是否可能使用相同的凭证 some-git-lab-token:someHash,通过 curlwget 从同一仓库中获取单个原始文件。
以下是一个样例 gitlab 原始文件 URL:
https://gitlab.com/athos.oc/lodash-has-plugin/-/raw/master/.eslintrc.json

我尝试使用以下命令curl一个文件,但失败了。
curl https://some-git-lab-token:someHash@git.xxx.com/foo/bar/-/raw/master/testing.js

我获得的结果如下:
<html><body>You are being <a href="https://git.xxx.com/users/sign_in">redirected</a>.</body></html>

这可以通过个人访问令牌来实现。你能利用它吗? - Sameer Atharkar
1个回答

15

要通过curl下载存储库文件,您需要使用存储库文件API端点

以您的示例https://gitlab.com/athos.oc/lodash-has-plugin/-/raw/master/.eslintrc.json为例:

https://gitlab.com/api/v4/projects/30349314/repository/files/%2Eeslintrc%2Ejson/raw?ref=master

然而,API身份验证不包括用户名和密码作为可用的身份验证方法,因此您需要使用令牌(或会话cookie)。

1
感谢您的回答!为了以后的参考,您仍然需要使用/raw来获取内容,因为没有它,您只能获得文件的元数据。所以链接应该是https://gitlab.com/api/v4/projects/30349314/repository/files/%2Eeslintrc%2Ejson/raw?ref=master - Isaac
哦,对不起!我从文档中复制了错误的示例。我已经更新了链接和示例。 - Arty-chan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接