Skip to content

Commit

Permalink
Properly close resources in CloneOp
Browse files Browse the repository at this point in the history
The CloneCommand in JGit returns a reosurce that must be
closed in order to release a lock on the files in the repo.
This prevents someone from deleting a repo, even though they
close the Grgit instance.

Closing the resource has fixed #132.
  • Loading branch information
ajoberstar committed Dec 16, 2016
1 parent 84b827d commit 9b1af80
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class CloneOp implements Callable<Grgit> {
if (refToCheckout) { cmd.branch = refToCheckout }

try {
cmd.call()
cmd.call().close()
return Grgit.open(dir: dir, creds: credentials)
} catch (GitAPIException e) {
throw new GrgitException('Problem cloning repository.', e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,13 @@ class CloneOpSpec extends MultiGitOpSpec {
GitTestUtil.tags(grgit).collect(lastName) == ['tag1']
GitTestUtil.remotes(grgit) == ['origin']
}

def 'cloned repo can be deleted'() {
given:
def grgit = Grgit.clone(dir: repoDir, uri: remoteUri, refToCheckout: 'refs/heads/branch2')
when:
grgit.close()
then:
assert repoDir.deleteDir()
}
}

0 comments on commit 9b1af80

Please sign in to comment.