Title: Fails in hook mode when package is a subdirectory of git repo · Issue #683 · commitizen/cz-cli · GitHub
Open Graph Title: Fails in hook mode when package is a subdirectory of git repo · Issue #683 · commitizen/cz-cli
X Title: Fails in hook mode when package is a subdirectory of git repo · Issue #683 · commitizen/cz-cli
Description: Scenario: Everything Node.JS lives within a subfolder e.g myGitRepo/source/package.json: "devDependencies": { "commitizen": "^4.0.3", "cz-conventional-changelog": "^3.0.2", "husky": "^3.0.9" }, "config": { "commitizen": { "path": "cz-con...
Open Graph Description: Scenario: Everything Node.JS lives within a subfolder e.g myGitRepo/source/package.json: "devDependencies": { "commitizen": "^4.0.3", "cz-conventional-changelog": "^3.0.2", "husky": "^3.0.9" }, "co...
X Description: Scenario: Everything Node.JS lives within a subfolder e.g myGitRepo/source/package.json: "devDependencies": { "commitizen": "^4.0.3", "cz-conventional-changelog&q...
Opengraph URL: https://github.com/commitizen/cz-cli/issues/683
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Fails in hook mode when package is a subdirectory of git repo","articleBody":"### Scenario:\r\n\r\nEverything Node.JS lives within a subfolder e.g myGitRepo/source/package.json:\r\n```\r\n \"devDependencies\": {\r\n \"commitizen\": \"^4.0.3\",\r\n \"cz-conventional-changelog\": \"^3.0.2\",\r\n \"husky\": \"^3.0.9\"\r\n },\r\n \"config\": {\r\n \"commitizen\": {\r\n \"path\": \"cz-conventional-changelog\"\r\n }\r\n },\r\n \"husky\": {\r\n \"hooks\": {\r\n \"prepare-commit-msg\": \"exec \u003c /dev/tty \u0026\u0026 npx git cz --hook || true\"\r\n }\r\n }\r\n```\r\n\r\nOverriding `config.commitizen.path` to the plain npm module name `cz-conventional-changelog` (as per #469) is sufficient to get `npx git cz` working, BUT...\r\n\r\n### Problem:\r\n\r\nTrying to use the husky hook (which is from the README) will throw:\r\n```\r\nmyGitRepo/source $ git commit\r\n# (Prompting works fine, but then...)\r\nError: ENOENT: no such file or directory, open '/myCoolParentFolder/myGitRepo/source/.git/COMMIT_EDITMSG\r\n```\r\n\r\nNote that it's always taking the package.json folder, not the current working directory e.g:\r\n```\r\nmyGitRepo/source/packages $ git commit\r\n# (Also prompts fine, but tries to write to same wrong .git folder...)\r\nError: ENOENT: no such file or directory, open '/myCoolParentFolder/myGitRepo/source/.git/COMMIT_EDITMSG\r\n```\r\n\r\nIt doesn't seem to be possible to override via environment variables (e.g. by messing with `GIT_DIR` in the husky hook statement like they do [here](https://github.com/typicode/husky/issues/364) or [here](https://github.com/typicode/husky/issues/584)), because [cli/strategies/git-cz.js](https://github.com/commitizen/cz-cli/blob/master/src/cli/strategies/git-cz.js) explicitly calls `commitizen.commit` with `repoPath = process.cwd()`:\r\n\r\n```\r\n commit(sh, inquirer, process.cwd(), prompter, {\r\n args: parsedGitCzArgs,\r\n disableAppendPaths: true,\r\n emitData: true,\r\n quiet: false,\r\n retryLastCommit,\r\n hookMode\r\n }, function (error) {\r\n if (error) {\r\n throw error;\r\n }\r\n });\r\n```\r\n\r\n...and [git/commit.js](https://github.com/commitizen/cz-cli/blob/master/src/git/commit.js) uses that repoPath to store the captured message:\r\n```\r\nconst commitFilePath = path.join(repoPath, '/.git/COMMIT_EDITMSG');\r\n```\r\n\r\nThis issue only affects running in hook mode, because in standard `git cz` we just pass the message through as an argument to a spawned git process, which manages to figure out that it's in a subfolder of a repository.\r\n\r\n### Fix Investigation:\r\n\r\nI had a look around to try and figure what a fix might look like, but I don't really understand why `cliPath` and `repoPath` are tracked as separate variables when the CLI strategy seems to just force `repoPath` to the package root?","author":{"url":"https://github.com/athewsey","@type":"Person","name":"athewsey"},"datePublished":"2019-10-22T04:27:21.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":4},"url":"https://github.com/683/cz-cli/issues/683"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:55702c32-0468-4263-340d-635a8b2184e3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFEE:20E521:3DA99:56781:6A62F8A1 |
| html-safe-nonce | 610dd8241da73e652fb57de3d735d0ae76641fb9d60558599e6e9263a73b3462 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkVFOjIwRTUyMTozREE5OTo1Njc4MTo2QTYyRjhBMSIsInZpc2l0b3JfaWQiOiI0MTYwNjAwMzc4Njg0ODQ3NjkiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 1d202713029c7a90dcfa48729cd43fdef06f05f9a5ee044250254fb82b01ba59 |
| hovercard-subject-tag | issue:510421904 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/commitizen/cz-cli/683/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b7c53b2d51a22393e2ddbe2dceeb169212fa7633693a50439719bcf9dff9e8b6/commitizen/cz-cli/issues/683 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b7c53b2d51a22393e2ddbe2dceeb169212fa7633693a50439719bcf9dff9e8b6/commitizen/cz-cli/issues/683 |
| og:image:alt | Scenario: Everything Node.JS lives within a subfolder e.g myGitRepo/source/package.json: "devDependencies": { "commitizen": "^4.0.3", "cz-conventional-changelog": "^3.0.2", "husky": "^3.0.9" }, "co... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | athewsey |
| hostname | github.com |
| expected-hostname | github.com |
| None | 59e40dc698184067b40ef2d941585f66ed42711564a879644f984f1eacea129c |
| turbo-cache-control | no-preview |
| go-import | github.com/commitizen/cz-cli git https://github.com/commitizen/cz-cli.git |
| octolytics-dimension-user_id | 11980392 |
| octolytics-dimension-user_login | commitizen |
| octolytics-dimension-repository_id | 34230966 |
| octolytics-dimension-repository_nwo | commitizen/cz-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 34230966 |
| octolytics-dimension-repository_network_root_nwo | commitizen/cz-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | b4f544bf80583e749557efd76afda56317b6252d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width