skip to Main Content

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:wrepoNamerepoName[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.

2

Answers


  1. Chosen as BEST ANSWER

    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.


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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search