How to implement Git in pure Javascript to create a GUI?

試著忘記壹切 提交于 2020-06-25 06:47:08

问题


after searching quite a lot without findind nothing about it I'm here to ask you if there is a way to implement Git in a pure Javascript web application. I already know about Git.js but it implements just some basic things and I also wanted to build my own library to learn more in depth about Git.

What I'm not looking for is an API or a lib that could help me.

What I'm looking for is something like:

var command = {{git commit -m "Hello world"}} // Also pure git implementation
gitExecute(command);

I'm still a junior developer and maybe this could be impossible...thanks for the reply :)


回答1:


What you are asking for may be difficult to do in a browser (because you will need access to the file system to run git commands). What you may need to do is create a NodeJS server which exposes REST endpoints which can be accessed by code in the browser which provides the GUI. The NodeJS server code can run commands as needed and respond to the REST HTTP requests which can be then used by your code in the browser to show/update the GUI.

The disadvantage with this method is that you will need to run your NodeJS server on the computer which has the repository and will not work if the repo is not local to the server.

Another alternative is to use the REST APIs exposed by popular GIT providers like GitHub.

EDIT:

Come to think of it, your usecase may be a good fit for an Electron App. That will allow you to build a desktop app (with access to the filesystem and privileges to execute commands) using Javascript.




回答2:


For this purpose, NodeJS is mandatory.

You could install git on your server machine, and thene execute your cmds through nodejs' child processes (DOCs)



来源:https://stackoverflow.com/questions/50269118/how-to-implement-git-in-pure-javascript-to-create-a-gui

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!