使用Flutter/Dart克隆Git仓库



我想在flutter/dart中做一个Process.start('cmd', ['/c', 'git', 'clone', repoLink, selectedDirectory])。我的目标目录不是空的,因为当我执行普通的git克隆时,它会在其中创建一个包含repo和clone名称的新文件夹。但是当我将目标文件夹传递给git clone命令时,它会引发一个错误:

fatal: destination path 'd:w' already exists and is not an empty directory.

当我得到repo名称并创建目录并将其添加到selectedDirectory时,它会在其中创建另一个具有完全相同名称的文件夹。如:D:wrepoNamerepoName[repo files]

所以,我怎么能正确克隆一个git仓库使用进程在扑?

更多信息:

我的目标目录如下:

D:w
project1
project2
...

在正常的克隆情况下,您可以简单地cd到目标目录D:w并执行git clone <repo link>,而目标目录不能为空。

但是当你想克隆这个repo而我在另一个路径时,git给出致命错误:

// git clone <repo-link> <target_folder>
C:> git clone https://github.com/uesr/repo.git d:w
fatal: destination path 'd:w' already exists and is not an empty directory.

我已经尝试获得repo的名称,并创建一个目录,并将其添加到selectedDirectory,但这样做,git克隆将创建另一个文件夹与repo的名称。我想克隆到d:/w/repoName/[repo files]

我想使用Process来完成这个操作,并使用安装在机器上的实际git软件。

我可以这样做:

Process.start('cmd', ['/c', 'cd', selectedDirectory, '&', 'git', 'clone', repoLink])

我不能在彼此之后添加多行来执行,但是你可以使用&对于单行命令,

您也可以使用rw_git,它提供了对clone和其他命令的支持。你可以这样写:

import 'package:rw_git/rw_git.dart';
...
RwGit rwGit = RwGit();
String localDirectoryToCloneInto = _createCheckoutDirectory(localDirectoryName);
bool clonedSuccessfully = rwGit.clone(localDirectoryToCloneInto, repositoryToClone);

它还提供了各种其他命令,您可能会觉得有用。

最新更新