0

问题

我想在服务器上创建一个个人微Github,但是如何优雅地与服务器上的git交谈?使用 PHP 向 git-shell 发送命令是否明智exec?我会直接与 git 交谈吗?为了理解这个想法,让我们花几秒钟来讨论它。

它应该如何工作

这个想法是我想创建一个类似于 GitHub 的应用程序,它允许用户管理多个存储库并浏览存储库。需要在服务器上安装 git 才能成为git 服务器。为了实现上述类似 GitHub 的功能,我想我应该将 git 包装在一个 API 层中,该层将用作数据访问层。这样,应用程序可以使用 git 来做 git 的事情,并且应该允许应用程序完成有用的事情:

请注意:语言选择不仅限于 PHP。我只使用 PHP 是因为它的exec()功能有助于突出本案例中的问题。

// Instantiate a git object
$git = new Git();

// Connect to a git server
$result = $git->connect("0.0.0.0","username","password");

// Create a bare repository in the filesystem
$repo = $git->init("name","/home/pwd/user/name.git");

// Clone a repository
$repo->clone("username","host","repository")

// Commit to the repository
$repo->commit($fileset,"message","long message");

问题

问题变成了这样:在对象和抽象之下Git,我将如何与服务器上的 git 对话?我会使用 PHP 向 git-shell 发送命令exec吗?还有另一种方式可以让我优雅地与 git 交谈吗?

4

0 回答 0