From 994f3b042222081870f124984da9d14acd7024b7 Mon Sep 17 00:00:00 2001 From: nutlike Date: Sat, 22 Aug 2020 01:18:49 +0200 Subject: [PATCH] fix(cli): determine correct location of `COMMIT_EDITMSG` (#737) If using git working trees, then `.git` is a file and not a directory: This file references its own git directory within the main working tree. `$ git rev-parse --git-dir` will always return the directory where the `COMMIT_EDITMSG` file should be placed. --- src/git/commit.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/git/commit.js b/src/git/commit.js index a193458a..14051b96 100644 --- a/src/git/commit.js +++ b/src/git/commit.js @@ -1,4 +1,4 @@ -import { spawn } from 'child_process'; +import { execSync, spawn } from 'child_process'; import path from 'path'; @@ -50,7 +50,11 @@ function commit (repoPath, message, options, done) { } }); } else { - const commitFilePath = path.join(repoPath, '/.git/COMMIT_EDITMSG'); + const gitDirPath = execSync( + 'git rev-parse --absolute-git-dir', + { cwd: repoPath, encoding: 'utf8' }, + ).trim(); + const commitFilePath = path.join(gitDirPath, 'COMMIT_EDITMSG'); try { const fd = openSync(commitFilePath, 'w'); try {