Skip to content

Commit

Permalink
fix: πŸ› wrong COMMIT_EDITMSG on Windows in Cygwin env
Browse files Browse the repository at this point in the history
Use `path.posix.join()` instead of `path.join()` to solve path
compatibility in Cygwin on Windows

βœ… Closes: streamich#622
  • Loading branch information
abcfy2 committed Feb 2, 2024
1 parent e2c5cfe commit dd732ac
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
4 changes: 2 additions & 2 deletions lib/cli.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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',
Expand Down
4 changes: 1 addition & 3 deletions lib/util/getGitDir.js
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
9 changes: 0 additions & 9 deletions test/__snapshots__/cli.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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
"
`;
9 changes: 8 additions & 1 deletion test/cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
`);
});

0 comments on commit dd732ac

Please sign in to comment.