Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@fatso83/check-commit-msg

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@fatso83/check-commit-msg - npm Package Compare versions

Comparing version 0.3.0 to 1.0.0

git-root.js

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 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc