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(githook.ts): support for git < 2.9 and submodules #192

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions out/cli.cjs
Original file line number Diff line number Diff line change
@@ -16272,7 +16272,7 @@ function G3(t, e2) {
// package.json
var package_default = {
name: "opencommit",
version: "2.4.1",
version: "2.4.2",
description: "Auto-generate impressive commits in 1 second. Killing lame commits with AI \u{1F92F}\u{1F52B}",
keywords: [
"git",
@@ -18792,7 +18792,12 @@ var getHooksPath = async () => {
const hooksPath = await getCoreHooksPath();
return import_path2.default.join(hooksPath, HOOK_NAME);
} catch (error) {
return DEFAULT_SYMLINK_URL;
try {
const { stdout } = await execa("git", ["rev-parse", "--git-path", "hooks"]);
return import_path2.default.join(stdout, HOOK_NAME);
} catch (error2) {
return DEFAULT_SYMLINK_URL;
}
}
};
var isHookCalled = async () => {
10 changes: 9 additions & 1 deletion src/commands/githook.ts
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import { existsSync } from 'fs';
import chalk from 'chalk';
import { intro, outro } from '@clack/prompts';
import { COMMANDS } from '../CommandsEnum.js';
import { execa } from 'execa';

const HOOK_NAME = 'prepare-commit-msg';
const DEFAULT_SYMLINK_URL = path.join('.git', 'hooks', HOOK_NAME);
@@ -15,7 +16,14 @@ const getHooksPath = async (): Promise<string> => {
const hooksPath = await getCoreHooksPath();
return path.join(hooksPath, HOOK_NAME);
} catch (error) {
return DEFAULT_SYMLINK_URL;
try {
// Git < 2.9 will throw error. Hence, alternative hook path query for Git < 2.9
// This works for submodules too.
const { stdout } = await execa("git", ["rev-parse", "--git-path", "hooks"]);
return path.join(stdout, HOOK_NAME);
} catch (error) {
return DEFAULT_SYMLINK_URL;
}
}
};

Loading
Oops, something went wrong.