gitlab get tar of a specific branch via command li

2019-02-04 23:55发布

问题:

I'm using gitlab. When I go into the interface, on each branch I can download the source code as a zip, tar or whatsoever.

I am making rpm spec files for which I would need the possibility to download the tar ball using command line. since I added my rsa key i can do git clone without problems:

git clone http://gitlab/group/project.git
Cloning into 'project'...
remote: Counting objects: 1885, done.
remote: Compressing objects: 100% (826/826), done.
remote: Total 1885 (delta 1194), reused 1496 (delta 954)
Receiving objects: 100% (1885/1885), 1.30 MiB | 0 bytes/s, done.
Resolving deltas: 100% (1194/1194), done.
Checking connectivity... done

However doing

wget http://gitlab/group/project/repository/archive.zip

gets me these errors:

Resolving gitlab (gitlab)... 10.1.253.75
Connecting to gitlab (gitlab)|10.1.253.75|:80... connected.
HTTP request sent, awaiting response... 401 Unauthorized
Authorization failed.

回答1:

Since GitLab 6.2 and issue 5253, it should be:

GET /projects/:id/repository/archive

But that seems for internal use only, since you cannot know the id of a project as a user (only its name).

Don't forget, as shown in ability.rb, that downloading an archive is linked to a permission. Make sure you have that "download_code" permission set for your project.

Here, it must be a permission issue, because, for instance:

wget http://demo.gitlab.com/gitlab/gitlab-recipes/repository/archive.zip

That works just fine, and get the content of that project without any issue.


However, as the OP Chris Maes comments and mentions in issue 6645, as as illustrated by app/models/ability.rb:

 if project && project.public?

... that "dowload_code" feature is only for public projects.



回答2:

For me the private_token and the sha or ref parameters does not worked together. So, I changed the way, and I tell my private token via a header parameter to the Gitlab API, like this:

wget http://{{your_host}}/api/v3/projects/{{project_id}}/repository/archive?sha={{commit_sha}} --header='PRIVATE-TOKEN: {{private_token}}'


回答3:

try this

curl http://$yourhost:$port/$yourgroup/$yourrepo/repository/archive.zip\?ref\=$yourbranch\&\private_token\=$yourtoken -o newpackage.zip