New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(cli): determine correct location of COMMIT_EDITMSG
#737
Conversation
src/git/commit.js
Outdated
@@ -50,7 +50,8 @@ function commit (repoPath, message, options, done) { | |||
} | |||
}); | |||
} else { | |||
const commitFilePath = path.join(repoPath, '/.git/COMMIT_EDITMSG'); | |||
const gitDirPath = execSync('git rev-parse --absolute-git-dir', { encoding: 'utf8' }).trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be run in the repoPath
, right?
const gitDirPath = execSync('git rev-parse --absolute-git-dir', { encoding: 'utf8' }).trim(); | |
const gitDirPath = execSync('git rev-parse --absolute-git-dir', { encoding: 'utf8', cwd: repoPath }).trim(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it should – Good catch. I will make the change (test needs to be changed, too) and report back. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I applied the suggested change and it made any changes to the tests unnecessary. If I would have been aware that the tests create their own git environment I wouldn't have created the stub in the first place, sorry, my bad. 😄 I (force-)pushed the changes – Thanks again for catching this!
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.
Codecov Report
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat 👍
Hello @LinusU, is there anything we can help to merge this PR? |
🎉 This PR is included in version 4.1.4 🎉 The release is available on: Your semantic-release bot 📦🚀 |
* fix: git-cz commit repoPath * chore(deps): bump minimist from 1.2.0 to 1.2.3 (#721) Bumps [minimist](https://github.com/substack/minimist) from 1.2.0 to 1.2.3. - [Release notes](https://github.com/substack/minimist/releases) - [Commits](https://github.com/substack/minimist/compare/1.2.0...1.2.3) Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * chore(deps): update dependency nyc to v15 (#704) Co-authored-by: Renovate Bot <bot@renovateapp.com> * fix: add babel spread plugin * fix: move to babel.config.js * fix: update azure devops images * docs: add commitiquette (#727) * fix(deps): bump vulnerable packages * feature: remove dependency on ShellJS (#729) * feature: avoid dependning on shelljs * refactor: remove shelljs from tests * refactor: simplify configLoader call * fix: use shell flag when spawning npm init Co-authored-by: hdmr14 <58992133+hdmr14@users.noreply.github.com> * refactor: remove unused function isArray * refactor: remove unused function isString Co-authored-by: hdmr14 <58992133+hdmr14@users.noreply.github.com> * feat: remove dependency on ShellJS (#729) Empty commit to trigger release. * fix(deps): update dependency cz-conventional-changelog to v3.2.0 (#657) Co-authored-by: Renovate Bot <bot@renovateapp.com> * fix: restore commitizen.congifLoader.load to public API (#733) * fix: restore commitizen.congifLoader.load to public API This reverts commit 468e924. * chore: temporarily skip failing test * fix: make cwd argument optional again (#735) * docs: add .czrc support to README (#739) * fix(deps): upgrade lodash to 4.17.20 and update package lock file * docs: add cz-format-extension (#758) * docs: Update `commitlint` adapter link (#751) * docs: Update `commitlint` adapter link * docs: Update link to commitlint adapter * docs: add adapter for jira (#748) We have created an adapter that is purposed for the JIRA workflow when you don't use _smart commits_. We have made sure that the adapter is well documented and easy to use. We think that it is unique and would love for it to be recognized. * chore(deps): update dependency nyc to v15.1.0 (#745) Co-authored-by: Renovate Bot <bot@renovateapp.com> * 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. * chore(deps): update dependency babel-plugin-istanbul to v5.2.0 (#658) Co-authored-by: Renovate Bot <bot@renovateapp.com> * chore(deps): update dependency semver to v6.3.0 (#659) Co-authored-by: Renovate Bot <bot@renovateapp.com> * fix(deps): update dependency inquirer to v6.5.2 (#664) Co-authored-by: Renovate Bot <bot@renovateapp.com> * feat: use cz as binary name (#767) While still support the old git-cz binary name. Also improve the documentation. Closes #761 * fix: git-cz commit repoPath Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Renovate Bot <bot@renovateapp.com> Co-authored-by: jimthedev <jimthedev@gmail.com> Co-authored-by: Martin McWhorter <martin@mcwhorter.org> Co-authored-by: Linus Unnebäck <linus@folkdatorn.se> Co-authored-by: hdmr14 <58992133+hdmr14@users.noreply.github.com> Co-authored-by: Fernando Maia <fsmaia@gmail.com> Co-authored-by: Jimmy Andrade <jimmy.andrade@thoughtworks.com> Co-authored-by: tyankatsu <frips.ryilsufupe+dev@gmail.com> Co-authored-by: Dura <chris-dura@users.noreply.github.com> Co-authored-by: Julius Recep Colliander Celik <julius.cc@hotmail.com> Co-authored-by: nutlike <mail@Qnert.com> Co-authored-by: Felipe Santos <felipecassiors@gmail.com>
I am using the commitizen hook and I am working with git working trees. When I tried to commit from a worktree it failed with following message:
If using git working trees, then
.git
is a file and not a directory. This pull request determines the correct location to put theCOMMIT_EDITMSG
file.I think the same problem was described in #683, #677 and #643 (the proposed solution should work for submodules as well).