1

I am trying to clone a git repository using JGit.

public static void main(String[] args) throws IOException, InvalidRemoteException, GitAPIException {

    String name = "username";
    String password = "password";

    remotePath = "https://user@stash.gto.intranet.db.com:8081/scm/paragon/paragongit.git";

    CredentialsProvider cp = new UsernamePasswordCredentialsProvider(name, password);

            File localPath = new File("C:/Users/13 dec/");
    if (!localPath.delete()) {
        throw new IOException("Could not delete temporary file" + localPath);
    }

    System.out.println("localPath " + localPath.getAbsolutePath());

    System.out.println("Cloning from" + remotePath + "to" + localPath);

    Git git = Git.init().setDirectory(localPath).call();

    System.out.println("The End");

    Git result = Git.cloneRepository().setURI(remotePath).setDirectory(localPath).setCredentialsProvider(cp).call();

    System.out.println("The end of program");

}

But I am getting JGitInternalException

Error->Exception in thread "main" org.eclipse.jgit.api.errors.JGitInternalException: Destination path "13 dec" already exists and is not an empty directory
    at org.eclipse.jgit.api.CloneCommand.verifyDirectories(CloneCommand.java:253)
    at org.eclipse.jgit.api.CloneCommand.call(CloneCommand.java:189)
    at testInAction.main(testInAction.java:39)
centic
  • 15,565
  • 9
  • 68
  • 125
Rain
  • 41
  • 7

2 Answers2

1

The error message is telling you that you are trying to clone a git repo over the top of an existing non-empty directory.

You can't do that. And you can't do that by running git clone from the command line either; see the comments on https://stackoverflow.com/a/42561781/139985

Basically, git is trying to stop you from shooting yourself in the foot.

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

when we create a directory in C:\Users then it is created a read only and we would need admin privilege to delete it even using normal delete from windows.

vivek g
  • 50
  • 6