diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java index 63ca4289a..a6ea66bc0 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java @@ -183,6 +183,8 @@ public class CloneCommand extends TransportCommand { } Repository repository = null; FetchResult fetchResult = null; + Thread cleanupHook = new Thread(() -> cleanup()); + Runtime.getRuntime().addShutdownHook(cleanupHook); try { repository = init(); fetchResult = fetch(repository, u); @@ -205,6 +207,8 @@ public class CloneCommand extends TransportCommand { } cleanup(); throw e; + } finally { + Runtime.getRuntime().removeShutdownHook(cleanupHook); } if (!noCheckout) { try {