Making custom Git client

I am writing a program in PHP that needs to interface with GIT repositories.
(i know, the language sucks. I'm only using it because I have to)

I was wondering if anyone knew, or had documentation for, the network commands to interact with a GIT server.
The script will need to grab the commit log and keep the local repository up to date with the remote one.

Does anyone have any ideas?

Thanks in advance!

I'm not sure about PHP, but there is the official C library libgit2 which will allow you to interact with Git directly, thus allowing you to interact with remote repositories as well.

EDIT: yep, there is a PHP binding for the library.

(i know, the language sucks. I'm only using it because I have to)

PHP is one of the better languages out there. It receives a lot of undeserved hate, probably because there is a lot of terrible PHP code (and programmers) out there. Also the language was pretty bad pre 5.3. If there is something specific about the language that you don't like then please explain.

Compared to other languages, I find that it has one of the better/best package management and lazy-loading systems which makes code-reuse a breeze. There's great documentation and free IDEs that fully support it like Netbeans. This is one of the biggest gripes I have against Javascript (lack of IDE support). Yes PHP is not as fast as Java or C++, but 7.0 will apparently be faster than most of the other scripting languages you know of, including Ruby, Python and Perl.

For something specific I am at a loss. It just feels... sloppy...
(relevant XKCD post: https://xkcd.com/1537/)

That is likely just carried over from using it years ago when it was really bad, but it kills me how slow it is. If they made threading or async tasks easier that would be fantastic.

I agree though, I am looking forward to PHP7. Hopefully it can make up for the bad name it has gotten in the past!

That is all fine and good, but is there any documentation on the network requests and protocols themselves?
I dont mind using a third party library, but im trying to build this to be modular and not everyone who would be interested might have that library installed.

There is this: http://stackoverflow.com/questions/18798762/git-transfer-protocol-specifications

1 Like

If there is something specific about the language that you don't like then please explain.

I don't like having to use the global keyword all the time, that it essentially forces you to use classes, the way || and && works, the performance, the obligatory dollar sign, unicode, isset vs all the other ones, array_map et al, etc. Granted, there were some nice additions done to it like traits, but to me it still feels like its lagging behind the other languages just like Java.

There's great documentation and free IDEs that fully support it like Netbeans. This is one of the biggest gripes I have against Javascript (lack of IDE support).

Documentation on the Mozilla Developer Network is pretty good IMO (they even provide polyfills in some cases). If you want to get really specific you can always check the W3C website. For IDES, theres Webstorm and some really bleeding edge stuff like Light Table (check it, its amazing). I also recommend looking at the auto-complete engine Tern (theres a plugin for vim, sublime, emacs, etc).

Back to the subject though, if you're looking for the easiest route to get your Git interface, I think you should seriously consider using libgit2. It will be more maintainable, more performant (since its a binding to a C library), and less buggy.

@aghost7 is right to recommend libgit2, I used libgit2sharp in a project and it was mostly great, unfortunately I discovered that git-prune wasn't supported for my git server setup (TFS), ended up finding a work around for my specific use case but do your research before diving in because it's not the most supported product.

Not a fan of PHP either-- the damn thing was built as a small project for a templating language-- it was never meant for it to become what it is now. I don't have many nice things to say about the standard library either.

This bug report's a great example of why I'm staying as far the fuck away from PHP as I can.
https://bugs.php.net/bug.php?id=45647

I don't like having to use the global keyword all the time,

I agree, don't use it. I develop in PHP and never use globals. Use parameters, defines, and constants.

the way || and && works,

It works the same way as many other languages. I don't see the problem.

the performance

I take it you are talking about the applications performance and not the speed at which one can develop? Are you comparing against something like Java or C++?

the obligatory dollar sign

I can understand this one as it is different from other languages, but I've actually come to think the other way now. I love the dollar sign clearly showing me whats a variable and whats not. I wish other languages had it too now.

unicode, isset vs all the other ones, array_map et al, etc

Please clarify what you mean here. You don't like the array_map function? Don't use it then.

there were some nice additions done to it like traits

I actually thought this was a large step backwards. The AWS SDK heavily uses this to avoid creating a truly OO codebase. Use inheritance and dependency injection instead.

it still feels like its lagging behind the other languages just like Java.

I missed the memo where Java is lagging behind? It is still incredibly strong in the programming industry and still being developed. It is one of the few programming languages that makes it easy to create multi-threaded applications and with an OO codebase at that.

For IDES, theres Webstorm and some really bleeding edge stuff like Light Table (check it, its amazing).

I tried webstorm, it suffered from lack of OO support. Try making a class in Javascript (which doesn't have "native" classes, only functions) with a private and public variable and methods, as well as static ones and check that you can't see the private ones when interfacing with an instantiated object, as well as being able to see the public ones. I will have to see if Light table works.

Not a fan of PHP either-- the damn thing was built as a small project for a templating language-- it was never meant for it to become what it is now. I don't have many nice things to say about the standard library either.

The only thing I have against the standard library is the lack of a consistent naming convention. E.g. sometimes _ is used and sometimes it isn't. Also the haystack,needle then needle,haystack ordering in parameters but there was a "good" reason for this that I heard, but I forget.

Do you not like languages evolving to become better? I have no issues with languages with a long history to become refined, it's extremely hard/impossible to just create a language that's great from day1 with features people expect.

This bug report's a great example of why I'm staying as far the fuck away from PHP as I can.
https://bugs.php.net/bug.php?id=456471

I understand both your point there and the guy who responded to the bug report. Technically there is no bug and the guy is right, but he could have spent a lot more effort in explaining exactly why there is no issue there and what would have been a better test. You can't have loose typing and expect strict results. You could always have performed an === operation on two strings representing dates.

This is exactly what I needed. Thanks a ton!

@programster There's some really nice stuff like Laravel, but like I said, I generally dont like PHP compared to other languages like Clojure and Scala. Its not my favourite, thats all.

@judahnator I'd say just recommend to your users to install "Composer" and just use the libgit2 binding for PHP. I never tried it, but if its like npm in NodeJS, it should provide decent support for C/C++ extensions. Reinventing the wheel, as they say, is to be avoided when possible.