From ab1491010ba4e17dec7ec733c837a431d12cff22 Mon Sep 17 00:00:00 2001 From: linwumingshi Date: Wed, 31 Jan 2024 10:40:34 +0800 Subject: [PATCH] fix: :bug: Git initialization of a project reports a null pointer error when not committed --- src/main/java/com/ly/doc/helper/GitHelper.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/com/ly/doc/helper/GitHelper.java b/src/main/java/com/ly/doc/helper/GitHelper.java index 2b10108d..a82c1f19 100644 --- a/src/main/java/com/ly/doc/helper/GitHelper.java +++ b/src/main/java/com/ly/doc/helper/GitHelper.java @@ -116,6 +116,10 @@ public String getLatestCommitId() { try { ObjectId objectId = repository.resolve("HEAD"); + // if not exist (the repository is init), return empty string + if (null == objectId) { + return ""; + } return objectId.getName(); } catch (IOException e) { throw new RuntimeException(e);