Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gitlab get tar of a specific branch via command line

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.
like image 871
Chris Maes Avatar asked Mar 27 '14 14:03

Chris Maes


3 Answers

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.

like image 136
VonC Avatar answered Nov 18 '22 23:11

VonC


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}}'
like image 45
laze Avatar answered Nov 18 '22 23:11

laze


try this

curl http://$yourhost:$port/$yourgroup/$yourrepo/repository/archive.zip\?ref\=$yourbranch\&\private_token\=$yourtoken -o newpackage.zip
like image 4
user2688588 Avatar answered Nov 19 '22 00:11

user2688588