@rachel_rotenberg/ai-contribution-tracker 1.0.27 → 1.0.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cli.js +18 -6
- package/package.json +1 -1
package/cli.js
CHANGED
|
@@ -22,7 +22,7 @@ const PLUGIN_NAME = "@rachel_rotenberg/ai-contribution-tracker";
|
|
|
22
22
|
const HOOK_BEGIN = "# BEGIN ai-contribution-tracker-cli";
|
|
23
23
|
const HOOK_END = "# END ai-contribution-tracker-cli";
|
|
24
24
|
const HOOK_DELEGATION = [
|
|
25
|
-
'LOCAL_HOOK="$(git rev-parse --git-dir)/hooks/commit-msg"',
|
|
25
|
+
'LOCAL_HOOK="$(git rev-parse --path-format=absolute --git-common-dir)/hooks/commit-msg"',
|
|
26
26
|
'if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then',
|
|
27
27
|
' "$LOCAL_HOOK" "$@" || exit $?',
|
|
28
28
|
'fi',
|
|
@@ -61,12 +61,13 @@ function appendOrCreateHook(hooksDir) {
|
|
|
61
61
|
const hookPath = path.join(hooksDir, "commit-msg");
|
|
62
62
|
|
|
63
63
|
if (fs.existsSync(hookPath)) {
|
|
64
|
-
let existing = fs.readFileSync(hookPath, "utf8");
|
|
64
|
+
let existing = fs.readFileSync(hookPath, "utf8").replace(/\r\n/g, "\n");
|
|
65
65
|
if (existing.includes(HOOK_BEGIN)) {
|
|
66
66
|
if (!existing.includes(HOOK_DELEGATION.split("\n")[0])) {
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
|
|
67
|
+
const lines = existing.split("\n");
|
|
68
|
+
const firstLine = lines[0].replace(/\r$/, "");
|
|
69
|
+
existing = firstLine + "\n" + HOOK_DELEGATION + "\n" + lines.slice(1).map(l => l.replace(/\r$/, "")).join("\n");
|
|
70
|
+
fs.writeFileSync(hookPath, existing);
|
|
70
71
|
ok(`Added local hook delegation to: ${hookPath}`);
|
|
71
72
|
} else {
|
|
72
73
|
skip(`commit-msg hook already up to date: ${hookPath}`);
|
|
@@ -100,7 +101,7 @@ function ensurePassthroughHooks(hooksDir) {
|
|
|
100
101
|
if (fs.existsSync(hookPath)) continue;
|
|
101
102
|
const content = [
|
|
102
103
|
"#!/bin/sh",
|
|
103
|
-
`LOCAL_HOOK="$(git rev-parse --git-dir)/hooks/${hookName}"`,
|
|
104
|
+
`LOCAL_HOOK="$(git rev-parse --path-format=absolute --git-common-dir)/hooks/${hookName}"`,
|
|
104
105
|
'if [ -f "$LOCAL_HOOK" ] && [ -x "$LOCAL_HOOK" ]; then',
|
|
105
106
|
' "$LOCAL_HOOK" "$@" || exit $?',
|
|
106
107
|
'fi',
|
|
@@ -288,6 +289,17 @@ function removeGitHook() {
|
|
|
288
289
|
if (!skipping) filtered.push(line);
|
|
289
290
|
}
|
|
290
291
|
|
|
292
|
+
for (const hookName of PASSTHROUGH_HOOKS) {
|
|
293
|
+
const p = path.join(hooksPath, hookName);
|
|
294
|
+
if (fs.existsSync(p)) {
|
|
295
|
+
const body = fs.readFileSync(p, "utf8");
|
|
296
|
+
if (body.includes(`git rev-parse --path-format=absolute --git-common-dir`)) {
|
|
297
|
+
fs.unlinkSync(p);
|
|
298
|
+
ok(`Removed passthrough hook: ${hookName}`);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
291
303
|
const remaining = filtered.join("\n").trim();
|
|
292
304
|
if (remaining === "#!/bin/sh" || remaining === "") {
|
|
293
305
|
fs.unlinkSync(hookFile);
|
package/package.json
CHANGED