@fatso83/check-commit-msg
Advanced tools
Comparing version 0.3.0 to 1.0.0
35
husky.js
@@ -10,37 +10,10 @@ #!/usr/bin/env node | ||
*/ | ||
const gitRoot = require("./git-root"); | ||
const fs = require("fs"); | ||
const path = require("path"); | ||
const filename = process.env["GIT_PARAMS"].split(" ")[0]; // typically '.git/COMMIT_EDITMSG' | ||
const filename = process.env["GIT_PARAMS"].split(" ")[0]; | ||
const fullPath = filename.replace(".git", gitRoot); | ||
const commitMsg = fs.readFileSync(fullPath).toString(); | ||
function levelsBelowGitRoot() { | ||
// https://github.com/git/git/blob/77bd3ea9f54f1584147b594abc04c26ca516d987/Documentation/RelNotes/1.7.6.txt#L29-L31 | ||
// "Processes spawned by "[alias] <name> = !process" in the configuration | ||
// can inspect GIT_PREFIX environment variable to learn where in the | ||
// working tree the original command was invoked. | ||
// " | ||
const subDirectoryOfRoot = process.env["GIT_PREFIX"] || ""; | ||
const levels = subDirectoryOfRoot.split("/").filter(n => n).length; | ||
return levels; | ||
} | ||
// Handle issue #2: https://github.com/fatso83/check-commit-msg/issues/2 | ||
// sometimes the directory of the frontend project is not at the root of the git repo | ||
// that makes many Git hooks fail when executed through Husky, as Husky changes | ||
// the working directory to the sub-folder where `package.json` is, making | ||
// hooks that rely on file paths being relative to the repo root fail | ||
const dirPrefix = path.resolve( | ||
path.join(...Array(levelsBelowGitRoot()).fill("..")) | ||
); | ||
const fullFilePath = path.join(dirPrefix, filename); | ||
const commitMsg = fs.readFileSync(fullFilePath).toString(); | ||
// GIT_DIR is originally set by GIT when executing the hook, but as it's a relative directory | ||
// to the current working directory (which is the root in git's book), this ends up wrong when | ||
// Husky changes the current working directory. We therefore need to reset it to make | ||
// all the Git commands work, as they all utilize GIT_DIR when accessing .git/* files | ||
// See https://git-scm.com/book/en/v2/Git-Internals-Environment-Variables#_repository_locations | ||
process.env["GIT_DIR"] = path.join(dirPrefix, ".git"); | ||
const checkCommitMsg = require("./check-commit-msg"); | ||
checkCommitMsg(commitMsg); |
@@ -5,7 +5,4 @@ /* eslint-disable no-console */ | ||
const cp = require("child_process"); | ||
const rootDir = require("./git-root"); | ||
const rootDir = cp | ||
.execSync("git rev-parse --show-toplevel") | ||
.toString() | ||
.trim(); | ||
const rebasePath = path.join(rootDir, ".git/rebase-merge"); | ||
@@ -12,0 +9,0 @@ const mergePath = path.join(rootDir, ".git/MERGE_HEAD"); |
{ | ||
"name": "@fatso83/check-commit-msg", | ||
"version": "0.3.0", | ||
"version": "1.0.0", | ||
"bin": "./cli.js", | ||
@@ -19,4 +19,7 @@ "description": "Check if your commit message follows Chris Beam's \"Seven rules of a good commit message\"", | ||
"dependencies": { | ||
"chalk": "^2.4.1" | ||
"chalk": "^2.4.1", | ||
"debug": "^4.1.1", | ||
"find-up": "^4.0.0", | ||
"pkg-dir": "^4.2.0" | ||
} | ||
} |
@@ -35,3 +35,3 @@ # @fatso83/check-commit-msg | ||
``` | ||
"commitmsg": "node -e \"require('@fatso83/check-commit-msg/husky')\"" | ||
"commitmsg": "node -r '@fatso83/check-commit-msg/husky'" | ||
``` | ||
@@ -38,0 +38,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
11
1
6
6598
4
116
+ Addeddebug@^4.1.1
+ Addedfind-up@^4.0.0
+ Addedpkg-dir@^4.2.0
+ Addeddebug@4.4.0(transitive)
+ Addedfind-up@4.1.0(transitive)
+ Addedlocate-path@5.0.0(transitive)
+ Addedms@2.1.3(transitive)
+ Addedp-limit@2.3.0(transitive)
+ Addedp-locate@4.1.0(transitive)
+ Addedp-try@2.2.0(transitive)
+ Addedpath-exists@4.0.0(transitive)
+ Addedpkg-dir@4.2.0(transitive)