Do not use cmd line call but an implementation of git in Python instead
Submitted by Gil Forcada
Link to original bug (#686122)
Description
Using cmd line calls and having to parse its output, errors and everything is not much elegant but unavoidable in most cases.
Fortunately there is a Python library[1] that allows you to work with git repositories from python code, nicely integrated :)
It's still not feature complete and there are still things that you can not do, but we should keep an eye on it (and to any other implementation that can pop up at any time) to evaluate a possible library to use for interfacing with git repositories.
As a matter of an example in stats/models.py in Branch._exists the following code:
command = "cd %s && git branch | grep %s" % (self.co_path(), self.name)
status, output, errs = utils.run_shell_command(command)
return output != ""
Can be replaced by this:
from git import Repo
git_repo = Repo(self.co_path())
return len(git_repo.branches() > 0
Which looks easier to grasp and pythonic :)