Answer a question

I know it is possible to fetch then use checkout with the path/to/file to download that specific file.

My issue is that I have a 1 MB data cap per day and git fetch will download all the data anyway even if it does not save them to disc until I use git checkout. I still used my data

Is my understanding of how git fetch/checkout correct? is there a way to download a specific file only to see if there is a new version before proceeding with the download.

Answers

Gitlab has a rest API for that.

You can GET a file from repository with curl:

curl https://gitlab.com/api/v4/projects/:id/repository/files/:filename\?ref\=:ref

For example:

curl https://gitlab.com/api/v4/projects/12949323/repository/files/.gitignore\?ref\=master

If your repository isn't public you also need to provide an access token by adding --header 'Private-Token: <your_access_token>'.


Links:

You can check how to find repository api id here.

Api documentation

More on tokens

There is also a python library that uses this api.

Note that this is GitLab specific solution and won't work for other hostings.

Logo

Python社区为您提供最前沿的新闻资讯和知识内容

更多推荐