Reputation: 1187
I want to create a little Git GUI and my idea is to make a program that calls the normal git software (using exec
or something similar), but my problem is that I don't know what to do with the stdout
(output) of git. It prints everything as a string.
Is there a way to make it print some kind of data that can be easily parsed, such as a JSON or something?
How are GUIs like git-gui for Windows or Gitkraken getting the output?
If you know another program that works like that, then please tell me the approach I can use.
Upvotes: 1
Views: 1780
Reputation: 31227
You've got 2 possibilities with their own advantages and trade offs.
Pro:
Cons:
But some commands could output something easier to parse. See for example parameters --porcelain
or --output
in the command help:
https://git-scm.com/docs/git-status
You could try to use a pure implementation in your language of choice or use a wrapper around the well maintained library 'libgit2' https://libgit2.github.com/
Pro:
Cons:
Ps: which language and which system do you target? Why not improve an existing GUI? Because that's a lot of hard work...
Upvotes: 2
Reputation: 386342
There are libraries for working with git in many languages. For example, you can use python's gitpython or ruby's ruby-git, etc.
For example:
from git import Repo
repo = Repo("/path/to/a/repo")
for file in repo.untracked_files:
print("untracked file:", file)
Upvotes: 3