From 9f98d3e2e4af009e1a5bad7e40969b241d45468b Mon Sep 17 00:00:00 2001 From: Matthias Sohn Date: Thu, 11 May 2017 00:18:40 +0200 Subject: [PATCH] Add shutdown hook to cleanup unfinished clone when JVM is killed Bug: 516303 Change-Id: I5181b0e8096af3537296848ac7dd74dff0b6d279 Signed-off-by: Matthias Sohn --- org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java | 4 ++++ 1 file changed, 4 insertions(+) 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 Git call() throws GitAPIException, InvalidRemoteException, } 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 Git call() throws GitAPIException, InvalidRemoteException, } cleanup(); throw e; + } finally { + Runtime.getRuntime().removeShutdownHook(cleanupHook); } if (!noCheckout) { try {