Skip to content
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

Merged
merged 1 commit into from Aug 21, 2020
Merged

fix(cli): determine correct location of COMMIT_EDITMSG #737

merged 1 commit into from Aug 21, 2020

Conversation

wkunert
Copy link
Contributor

@wkunert wkunert commented May 12, 2020

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:

Error: ENOTDIR: not a directory, open '/…/.git/COMMIT_EDITMSG'
    at openSync (fs.js:443:3)
    at commit (/…/node_modules/commitizen/dist/git/commit.js:844:62)
    at dispatchGitCommit (/…/node_modules/commitizen/dist/commitizen/commit.js:549:19)
    at /…/node_modules/commitizen/dist/commitizen/commit.js:630:11
    at /…/node_modules/cz-conventional-changelog/engine.js:217:9
    at process._tickCallback (internal/process/next_tick.js:68:7)

If using git working trees, then .git is a file and not a directory. This pull request determines the correct location to put the COMMIT_EDITMSG file.

I think the same problem was described in #683, #677 and #643 (the proposed solution should work for submodules as well).

@@ -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();
Copy link
Contributor

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?

Suggested change
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();

Copy link
Contributor Author

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. :)

Copy link
Contributor Author

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-io
Copy link

Codecov Report

❗ No coverage uploaded for pull request base (master@be08907). Click here to learn what that means.
The diff coverage is n/a.

@wkunert wkunert requested a review from LinusU May 13, 2020 10:07
Copy link
Contributor

@LinusU LinusU left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat 👍

@stvreumi
Copy link

Hello @LinusU, is there anything we can help to merge this PR?
This PR fixes the problem I encounter.
Thank you.

@karolinedealencar
Copy link

karolinedealencar commented Aug 7, 2020

Hello @LinusU, is there anything we can help to merge this PR?
This PR fixes the problem I encounter.
Thank you.

Same!
@LinusU We are having the same problem in our team, this PR fixes our problem.
Thanks!

@dmwelch dmwelch merged commit 994f3b0 into commitizen:master Aug 21, 2020
@commitizen-bot
Copy link

🎉 This PR is included in version 4.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

dmwelch pushed a commit that referenced this pull request Aug 25, 2020
* 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants