Is there a way to emulate git status via the api? I’m looking for a way to enumerate the untracked plus the staged files.
The reason I’m looking for this is so I can push all the new, deleted and modified files using this api: POST /projects/:id/repository/commits (https://docs.gitlab.com/ee/api/commits.html)
I was intrigued and bit confused with your reply until I checked the link you provided and others that I found from additional searching about “bare repository”.
Perhaps, if I outline the workflow that I envision, you might be able to give me pointers on how to better use the GitLab API.
I have several jpg files that I want to version. This collection of files may change from time to time, like adding more files, deleting some and even changing the content of some. I want to commit and push each version of this collection to GitLab every time such changes occur. I then would want to pull any version of the collection from GitLab at any time.
So I have a local folder named “C:\MyFiles” with a number of subdirectories like “C:\MyFiles\One”, “C:\MyFiles\Two”, etc.
And here’s what I think I should do:
Create a new GitLab project using the GitLab web ui (which from what I have read will default to a bare repo).
Push all the files from C:\MyFiles using the api: POST /projects/:id/repository/commits
Tag the last commit using the api: POST /projects/:id/repository/tags
To pull all the files from any desired tag with this api: GET /projects/:id/repository/archive
The reason why I asked about git status was to determine what commit action I will use (that is, create, update or delete) for succeeding calls to “POST /projects/:id/repository/commits”.
Now I understand better. You are actually writing a script which will run on your Windows workstation, and I think your plan is OK. And of course, you are right, you can push using the API.
As to git status, it’s a local command, in which GitLab is not involved, and thus has nothing to do with the API.
Therefore I think you could simply run git status in your script and parse its output. From what I see in the documentation, you should probably use the –porcelain option.
You are right, POST /projects/:id/repository/commits does upload files. However, it does not push a whole commit. It only creates a new commit on the GitLab server, without having the same commit on your computer. As a result, you will create a discrepancy between the repo on your computer and that on the server. The right way to do is first to create a commit on your computer, then push it to the server.
With all seriousness, why do you want to manipulate Git repository using GitLab API, even thou GitLab partially allows that? I’m still baffled about that…
What’s wrong with standard Git approach as alexk mentioned (add, commit, push)? You don’t need connection to that GitLab server to add and commit files to repository and you don’t need to gather status of files.
If you want to manipulate Git repository from C# app, I would suggest using libgit2sharp library. That’s wrapper for libgit2 library, which is more effecient for applications like that instead of calling cmd-line version of Git, but approach is still same: add, commit, tag, push.