diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2017-05-11 00:18:40 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2017-05-13 17:23:34 +0200 |
commit | 9f98d3e2e4af009e1a5bad7e40969b241d45468b (patch) | |
tree | ae63ff2745a9c7b8c9ac46a3a39c4d35ddff39e1 | |
parent | 09d96f8d46a31e23fbe5a7b5d8114ae9aaba5056 (diff) | |
download | jgit-9f98d3e2e4af009e1a5bad7e40969b241d45468b.tar.gz jgit-9f98d3e2e4af009e1a5bad7e40969b241d45468b.zip |
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>
-rw-r--r-- | org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java | 4 |
1 files changed, 4 insertions, 0 deletions
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 63ca4289a0..a6ea66bc03 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<CloneCommand, Git> { } 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<CloneCommand, Git> { } cleanup(); throw e; + } finally { + Runtime.getRuntime().removeShutdownHook(cleanupHook); } if (!noCheckout) { try { |