@rachel_rotenberg/ai-contribution-tracker 1.0.26 → 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 -43
- 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',
|
|
@@ -112,40 +113,6 @@ function ensurePassthroughHooks(hooksDir) {
|
|
|
112
113
|
}
|
|
113
114
|
}
|
|
114
115
|
|
|
115
|
-
function installPreCommitFramework(hooksDir) {
|
|
116
|
-
const configFile = path.join(process.cwd(), ".pre-commit-config.yaml");
|
|
117
|
-
if (!fs.existsSync(configFile)) return;
|
|
118
|
-
|
|
119
|
-
let preCommitBin = "";
|
|
120
|
-
try {
|
|
121
|
-
preCommitBin = execSync("which pre-commit 2>/dev/null || command -v pre-commit 2>/dev/null", {
|
|
122
|
-
encoding: "utf8", shell: true, stdio: ["pipe", "pipe", "pipe"],
|
|
123
|
-
}).trim();
|
|
124
|
-
} catch { }
|
|
125
|
-
if (!preCommitBin) return;
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
execFileSync("git", ["config", "--global", "--unset", "core.hooksPath"], {
|
|
129
|
-
encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
|
|
130
|
-
});
|
|
131
|
-
} catch { }
|
|
132
|
-
|
|
133
|
-
try {
|
|
134
|
-
execFileSync(preCommitBin, ["install"], {
|
|
135
|
-
encoding: "utf8", stdio: ["pipe", "pipe", "pipe"], cwd: process.cwd(),
|
|
136
|
-
});
|
|
137
|
-
ok("Installed pre-commit framework hooks");
|
|
138
|
-
} catch (e) {
|
|
139
|
-
warn(`Could not run pre-commit install: ${e.message}`);
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
try {
|
|
143
|
-
const gitPath = hooksDir.replace(/\\/g, "/");
|
|
144
|
-
execFileSync("git", ["config", "--global", "core.hooksPath", gitPath], {
|
|
145
|
-
encoding: "utf8", stdio: ["pipe", "pipe", "pipe"],
|
|
146
|
-
});
|
|
147
|
-
} catch { }
|
|
148
|
-
}
|
|
149
116
|
|
|
150
117
|
/** Install the global git commit-msg hook. */
|
|
151
118
|
function installGitHook() {
|
|
@@ -166,7 +133,6 @@ function installGitHook() {
|
|
|
166
133
|
fs.mkdirSync(existingPath, { recursive: true });
|
|
167
134
|
appendOrCreateHook(existingPath);
|
|
168
135
|
ensurePassthroughHooks(existingPath);
|
|
169
|
-
installPreCommitFramework(existingPath);
|
|
170
136
|
} else {
|
|
171
137
|
const hooksDir = path.join(os.homedir(), ".config", "ai-contribution-tracker", "git-hooks");
|
|
172
138
|
fs.mkdirSync(hooksDir, { recursive: true });
|
|
@@ -183,8 +149,6 @@ function installGitHook() {
|
|
|
183
149
|
} catch (e) {
|
|
184
150
|
fail(`Could not set core.hooksPath: ${e.message}`);
|
|
185
151
|
}
|
|
186
|
-
|
|
187
|
-
installPreCommitFramework(hooksDir);
|
|
188
152
|
}
|
|
189
153
|
}
|
|
190
154
|
|
|
@@ -325,6 +289,17 @@ function removeGitHook() {
|
|
|
325
289
|
if (!skipping) filtered.push(line);
|
|
326
290
|
}
|
|
327
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
|
+
|
|
328
303
|
const remaining = filtered.join("\n").trim();
|
|
329
304
|
if (remaining === "#!/bin/sh" || remaining === "") {
|
|
330
305
|
fs.unlinkSync(hookFile);
|
package/package.json
CHANGED