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://[email protected]: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)
3
  • Check if this path exists and is writeable Commented Dec 14, 2018 at 9:06
  • Please post the full stack trace so that others can see where exactly the exception stems from. Commented Dec 14, 2018 at 9:24
  • @Jens yes the path exists Commented Dec 14, 2018 at 9:29

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

4 Comments

I changed it to H:/ drive path but still getting same error
did you check the properties of the folder
change it to not read only. i have tried the peice of code and it works when it is not read only localPath.delete() tries to delete it and it returns false when its read only
can you just send me your piece of code which worked for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.