Open bummoblizard opened 3 years ago
WASM does not have support for sockets or networking, for now. This will make porting git to WASM difficult. Although I could add socket support to WASM, the way I did add local file support.
In the next version (currently being uploaded) I am including a version of git based on Dulwich (a pure python package): https://www.dulwich.io It's not as complete as git, but I think it will be better than nothing.
The best candidate for a port of git is libgit2: https://libgit2.org , combined with objective-C bindings: https://github.com/libgit2/objective-git
I gave it another try. git seems like it could compile to wasm, except it needs gethostbyname()
, which is not part of the WASI SDK (for good reasons: there's no way to emulate that using JS).
I've gotten git commit
, git add
, and git rm
working using Dulwich.
I'm using this wrapper around Dulwich's CLI:
After I get it to work better (e.g. fix git reset
and add the -u
argument to git add
, have git commit
support --amend
, open Vim when no message is specified, etc.), I intend to submit a pull request.
Thank you very much for this hard work!
Please see also issue #170: if we include git
as a command, other commands, like vim
, will call it, and it may break things down. It seems the difficult git plugin was vim-gitgutter
, which you can use a test suite.
It looks like a WASM version of git already exists (uses libgit2 compiled to WASM): https://github.com/petersalomonsen/wasm-git
Thanks for the link. It is based on Emscripten WebAssembly, and so far a-Shell only works with WASI WebAssembly (which does not mean it won't work, but it is not tested yet). Supporting Emscripten is a whole new project (it assumes node is present, and I'm not certain about how it loads extra files).
It is easy to compile libgit2 to native iOS (or probably WebAssembly, but native iOS is easier), the problem is with the clients. There are very few git clients (that I know of) that are both based on libgit2 and have all the command line options of the standard git command line tool.
It looks like wasm-git does expose (at least some) of the git command-line options:
I don't see where this is defined in their source repository though... Edit: See next comment. The client is defined in libgit2
's example directory.
I think it's a part of libgit2: https://github.com/libgit2/libgit2/blob/main/examples/general.c See below. main(argc, argv)
is in lg2.c
, not general.c
.
I think libgit2/examples/*
implement a simple git client... and this is what I think wasm-git
is using.
Edit 1: This could be better than a Dulwich-based client -- Dulwich seems to start a background daemon that sometimes gives "Too many python interpreters running" errors (though this may have also been due to gitgutter
's usage of the git
command). Additionally, I've been having trouble getting some of Dulwich's commands (e.g. stash push/pop
) to work.
Edit 2: main
is in lg2.c!
I think it would be useful to have both commands in a-Shell (your script above dulwich and lg2). Neither is going to work as a drop-in replacement for git, but each of them can be good enough for some uses. You can even call lg2 from Python for some difficult cases.
Do any of these work with LFS files?
As seen from #10, #24, #56, Git is a well requested feature. But one major problem is Git's GPL license, making it incompatible with App Store.
I wonder if there is any attempt to compile Git to WASM, enabling the ability to side load Git from user's side. This could bypass the regulatory issue.