Browse Source

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>
stable-4.8
Matthias Sohn 7 years ago
parent
commit
9f98d3e2e4
  1. 4
      org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

4
org.eclipse.jgit/src/org/eclipse/jgit/api/CloneCommand.java

@ -183,6 +183,8 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
} }
Repository repository = null; Repository repository = null;
FetchResult fetchResult = null; FetchResult fetchResult = null;
Thread cleanupHook = new Thread(() -> cleanup());
Runtime.getRuntime().addShutdownHook(cleanupHook);
try { try {
repository = init(); repository = init();
fetchResult = fetch(repository, u); fetchResult = fetch(repository, u);
@ -205,6 +207,8 @@ public class CloneCommand extends TransportCommand<CloneCommand, Git> {
} }
cleanup(); cleanup();
throw e; throw e;
} finally {
Runtime.getRuntime().removeShutdownHook(cleanupHook);
} }
if (!noCheckout) { if (!noCheckout) {
try { try {

Loading…
Cancel
Save