0

I want to do a Process.start('cmd', ['/c', 'git', 'clone', repoLink, selectedDirectory]) in flutter/dart. My target directory is not empty because when I do a normal git clone, it creates a new folder with the name of the repo an clone inside that. but when I pass the target folder to git clone command, it raise an error:

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

And when i get the repo name and make a directory and add it to selectedDirectory, it would create another folder inside that with the exact same name.like: D:\w\repoName\repoName\[repo files]

So, how can I properly clone a git repo using Process in flutter?

More information:

My target directory is like:

D:\w\
  project1\
  project2\
  ...

In a normal clone case, you can simply cd to the target directory D:\w and do a git clone <repo link> while the target directory can be not empty.

but when you want to clone that repo while I am in a different path, git gives fatal error:

// 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.

I have tried to get the repo name and make a directory and add it to selectedDirectory, but doing that, git clone will create another folder with the repo name. I want to clone into d:/w/repoName/[repo files]

I would like to do this using Process and work with the actual git software that is installed on the machine.

omid3098
  • 1
  • 2
  • Try `git -C selectedDirectory clone repoLink`; see [`git -C`](https://git-scm.com/docs/git#Documentation/git.txt--Cltpathgt). – phd Jan 20 '23 at 19:42
  • Does this answer your question? [How do I clone into a non-empty directory?](https://stackoverflow.com/questions/2411031/how-do-i-clone-into-a-non-empty-directory) – Aissaoui Ahmed Jan 20 '23 at 20:31
  • Thank you @phd . I did not know about git -C – omid3098 Jan 20 '23 at 22:33

2 Answers2

0

I could do it using this process:

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

I could not add multiple lines to execute after each other but you can use & to do so for one line commands.

omid3098
  • 1
  • 2
0

You can also use rw_git which offers support for clone and other commands. You could write something like:

import 'package:rw_git/rw_git.dart';

...

RwGit rwGit = RwGit();
String localDirectoryToCloneInto = _createCheckoutDirectory(localDirectoryName);
bool clonedSuccessfully = rwGit.clone(localDirectoryToCloneInto, repositoryToClone);

It also offers various others commands that you might find useful.