From 6a9f52230decc14c161977d65aa88afed4cb9159 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AD=99=E6=99=AF=E6=98=8C?= <13207121+actri_sjchang@user.noreply.gitee.com> Date: Fri, 28 Jul 2023 08:06:45 +0000 Subject: [PATCH] =?UTF-8?q?`GitUtil`=E7=B1=BB=E7=9A=84=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E6=B7=BB=E5=8A=A0=E4=BA=86=E9=80=82=E5=BD=93?= =?UTF-8?q?=E7=9A=84=E5=BC=82=E5=B8=B8=E5=A4=84=E7=90=86=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E7=A1=AE=E4=BF=9D=E6=8D=95=E8=8E=B7=E5=B9=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 孙景昌 <13207121+actri_sjchang@user.noreply.gitee.com> --- src/net/oschina/git/utils/GitUtil.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/net/oschina/git/utils/GitUtil.java b/src/net/oschina/git/utils/GitUtil.java index 6ae81f0..6b2f9de 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 { -- Gitee