I need to clone a git repo in java. I am using jGit.
The line of code I am using is :
Git clone = Git.cloneRepository().setURI(URIofRepo).setDirectory(localPath).call();
Where URIofRepo is : the github link to my repo and Where localPath is : the directory I want the clone to happen.
This works perfectly. However, since the use of the project I am doing doesn't require a clone for continued work, I simply want the clone to have the contents of the github repo WITHOUT the .git directory.
I tried also using the following :
File dirToDelete = new File (path + "/.git");
FileUtils.deleteDirectory(dirToDelete);
However I got an IO exception saying I am unable to delete the file as follows :
Exception in thread "main" java.io.IOException: Unable to delete file: C:\testing\testRepo1.git\objects\pack\pack-7ca7f11688adda065d62f3394d0e055346beff22.pack
It is possible that the current eclipse process keep an handle on the pack file, preventing its deletion.
As RĂ¼diger Herrmann suggests in the comments:
Another approach would be to download an archive of the GitHub repo through its archive link.
Or using JGit to create an archive from your current local repo (see
ArchiveTest.java
), and unzip that archive for you to use.