From dd732ac19130bdf06520decd0c0b3bbc1aec046c Mon Sep 17 00:00:00 2001 From: Feng Yu Date: Fri, 2 Feb 2024 12:05:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20wrong=20COMMIT=5FEDITMSG?= =?UTF-8?q?=20on=20Windows=20in=20Cygwin=20env?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use `path.posix.join()` instead of `path.join()` to solve path compatibility in Cygwin on Windows ✅ Closes: #622 --- lib/cli.js | 4 ++-- lib/util/getGitDir.js | 4 +--- test/__snapshots__/cli.test.js.snap | 9 --------- test/cli.test.js | 9 ++++++++- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/cli.js b/lib/cli.js index c3d7b5d6..627c9c0a 100644 --- a/lib/cli.js +++ b/lib/cli.js @@ -1,6 +1,6 @@ const {spawn, execSync} = require('child_process'); const fs = require('fs'); -const {join} = require('path'); +const path = require('path'); const shellescape = require('any-shell-escape'); const signale = require('signale'); const parseArgs = require('./parseArgs'); @@ -89,7 +89,7 @@ const main = async () => { } } - const commitMsgFile = join(getGitDir(), 'COMMIT_EDITMSG'); + const commitMsgFile = path.posix.join(getGitDir(), 'COMMIT_EDITMSG'); const command = shellescape([ 'git', diff --git a/lib/util/getGitDir.js b/lib/util/getGitDir.js index 3e46573f..bcc3cff5 100644 --- a/lib/util/getGitDir.js +++ b/lib/util/getGitDir.js @@ -1,9 +1,7 @@ const {execSync} = require('child_process'); const getGitDir = () => { - const devNull = process.platform === 'win32' ? ' nul' : '/dev/null'; - const dir = execSync('git rev-parse --absolute-git-dir 2>' + devNull) - .toString() + const dir = execSync('git rev-parse --absolute-git-dir', {encoding: 'utf8'}) .trim(); return dir; diff --git a/test/__snapshots__/cli.test.js.snap b/test/__snapshots__/cli.test.js.snap index 397cac20..e511d343 100644 --- a/test/__snapshots__/cli.test.js.snap +++ b/test/__snapshots__/cli.test.js.snap @@ -24,12 +24,3 @@ exports[`git-cz --help 1`] = ` " `; - -exports[`git-cz --non-interactive 1`] = ` -"Running in dry mode. -Will execute command: -git commit --file '.git/COMMIT_EDITMSG' -Message: -chore: 🤖 automated commit -" -`; diff --git a/test/cli.test.js b/test/cli.test.js index 7877cbc0..eb3d0407 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -20,7 +20,14 @@ test('git-cz --version', async () => { test('git-cz --non-interactive', async () => { const {getResult} = runCLI(['--non-interactive', '--dry-run']); + const quote = process.platform === 'win32' ? '"' : '\''; const result = await getResult(); - expect(result).toMatchSnapshot(); + expect(result).toBe(`\ +Running in dry mode. +Will execute command: +git commit --file ${quote}.git/COMMIT_EDITMSG${quote} +Message: +chore: 🤖 automated commit +`); });