diff --git a/src/net/oschina/git/utils/GitUtil.java b/src/net/oschina/git/utils/GitUtil.java index 6ae81f0d36d85fcf2fc3050e3e512963e70a92e9..6b2f9deb1ba3e1f366d62670a88ad16fe138686d 100644 --- a/src/net/oschina/git/utils/GitUtil.java +++ b/src/net/oschina/git/utils/GitUtil.java @@ -54,10 +54,17 @@ public class GitUtil { return lsCmd.call().toString(); } - public static Repository getRepository(String path) throws IOException { - Git git = Git.open(new File(path + "/.git")); - return git.getRepository(); - } + public static Repository getRepository(String path) throws IOException { + Git git = null; + try { + git = Git.open(new File(path + "/.git")); + return git.getRepository(); + } finally { + if (git != null) { + git.close(); + } + } + } public static void createRepository(String path, String remotePath) throws IllegalStateException, GitAPIException, IOException {