Add shutdown hook to cleanup unfinished clone when JVM is killed

Bug: 516303
Change-Id: I5181b0e8096af3537296848ac7dd74dff0b6d279
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
This commit is contained in:
Matthias Sohn 2017-05-11 00:18:40 +02:00
parent 09d96f8d46
commit 9f98d3e2e4
1 changed files with 4 additions and 0 deletions

View File

@ -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 {