1

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.

1
  • You could use git <command> --porcelain to get more machine-readable output. For example, If you ran git status on a repo with no changes, you would get some unnecessary info, like a prompt to push for example. But if you ran git status --porcelain, there would be zero output Commented Jun 12, 2021 at 8:35

2 Answers 2

3

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)
Sign up to request clarification or add additional context in comments.

Comments

2

You've got 2 possibilities with their own advantages and trade offs.

  1. Use the git exe

Pro:

  • Up to date
  • do not behave differently than the official client, contrary to a library (major advantage)

Cons:

  • painful to use and parse output
  • need to support different versions

But some commands could output something easier to parse. See for example parameters --porcelain or --outputin the command help: https://git-scm.com/docs/git-status

  1. Use a library in your language of choice.

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:

  • Really easier to use
  • performance could be better (no need to read git files at every command)

Cons:

  • use could be a little different or features limited (especially for language pure implementations)

Ps: which language and which system do you target? Why not improve an existing GUI? Because that's a lot of hard work...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.