Used the following piece of code to clone the repo from ADO.
File file = new File("local_folder_location");
CredentialsProvider cp = new UsernamePasswordCredentialsProvider("user_id", "password");
try {
Git.cloneRepository()
.setURI("repo_path")
.setCredentialsProvider(cp)
.setDirectory(file)
.call();
} catch (GitAPIException e) {
e.printStackTrace();
}
It is working fine if we try to clone the repo only once. On the second time it will throw an error like:
Exception in thread "main" org.eclipse.jgit.api.errors.JGitInternalException: Destination path "path" 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)
Please suggest a solution in which:
- If the repository is not there in local, Clone it like above.
- If it is already existing, pull the latest changes only.
Also if there's any other solution to this in Java (any other API or something), it would work.
Thanks