From 021280c53cd30c3350e18d7b1bfe4806b70ab9ff Mon Sep 17 00:00:00 2001 From: pablone Date: Fri, 5 Apr 2024 14:14:10 +0200 Subject: [PATCH] fix commit code --- .husky/addReferenceTag.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/.husky/addReferenceTag.js b/.husky/addReferenceTag.js index 2eab2b8c5..b50a0342b 100644 --- a/.husky/addReferenceTag.js +++ b/.husky/addReferenceTag.js @@ -3,17 +3,14 @@ const fs = require('fs'); const path = require('path'); -async function getCurrentBranchName(p = process.cwd()) { - while (p !== path.parse(p).root) { - const gitHeadPath = path.join(p, '.git', 'HEAD'); - try { - const headContent = await fs.readFile(gitHeadPath, 'utf-8'); - return headContent.trim().split('/')[2]; - } catch (err) { - p = path.resolve(p, '..'); - } - } - return false; +function getCurrentBranchName(p = process.cwd()) { + const gitHeadPath = `${p}/.git/HEAD`; + + return fs.existsSync(p) ? + fs.existsSync(gitHeadPath) ? + fs.readFileSync(gitHeadPath, 'utf-8').trim().split('/')[2] : + getCurrentBranchName(path.resolve(p, '..')) : + false } const branchName = getCurrentBranchName(); if (branchName) { @@ -29,6 +26,7 @@ if (branchName) { if (splitedMsg.length > 1) { const finalMsg = splitedMsg[0] + splitedMsg.slice(1).join(':'); + console.log('finalMsg: ', finalMsg); fs.writeFileSync(msgPath, finalMsg); } }