slicekit 0.1.1 → 0.1.2
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/package.json
CHANGED
package/src/init.js
CHANGED
|
@@ -24,6 +24,10 @@ const IGNORE_RULES = [
|
|
|
24
24
|
{ rule: '.slicekit/journal/*.lock', forms: new Set(['.slicekit/journal/*.lock', '/.slicekit/journal/*.lock']) },
|
|
25
25
|
// Slice worktrees (REQ-2.6 step 1) live under the root and are never part of the checkout.
|
|
26
26
|
{ rule: '.worktrees/', forms: new Set(['.worktrees/', '/.worktrees/', '.worktrees', '/.worktrees']) },
|
|
27
|
+
// The README's path is an npm install (S-28): what it installs is never part of the project. A file
|
|
28
|
+
// that already has any node_modules rule keeps its own, since a line below a negation such as
|
|
29
|
+
// `!node_modules/local-pkg/` would cancel it (P2/S-28 review H-1).
|
|
30
|
+
{ rule: 'node_modules/', forms: new Set(['node_modules/', '/node_modules/', 'node_modules', '/node_modules']), mentions: 'node_modules' },
|
|
27
31
|
];
|
|
28
32
|
// Hooks checked out with CRLF break sh (REQ-3.9).
|
|
29
33
|
// Intake snapshots (S-10) are stored byte for byte, so git must not convert their line endings. The
|
|
@@ -85,7 +89,8 @@ function ensureLines(file, rules) {
|
|
|
85
89
|
const raw = fs.readFileSync(file, 'utf8');
|
|
86
90
|
const squash = (line) => line.trim().replace(/\s+/g, ' ');
|
|
87
91
|
const present = new Set(raw.split(/\r?\n/).map(squash));
|
|
88
|
-
const
|
|
92
|
+
const mentioned = (word) => [...present].some((l) => l.includes(word));
|
|
93
|
+
const missing = rules.filter(({ forms, mentions }) => ![...forms].some((f) => present.has(squash(f))) && !(mentions && mentioned(mentions)));
|
|
89
94
|
if (missing.length === 0) return 'skipped';
|
|
90
95
|
const eol = raw.includes('\r\n') ? '\r\n' : '\n';
|
|
91
96
|
const sep = raw === '' || raw.endsWith('\n') ? '' : eol;
|
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
# slicekit: refuses a commit on a protected branch (REQ-3.9). Installed as pre-commit and as
|
|
3
3
|
# pre-merge-commit, byte for byte; prepare-commit-msg carries the same check between the markers.
|
|
4
4
|
# >>> slicekit protected-branch check (identical in every slicekit hook)
|
|
5
|
-
#
|
|
5
|
+
# Sets slicekit_b to the branch a commit lands on: HEAD's branch, or during a rebase the branch being
|
|
6
|
+
# rebased; empty on a detached HEAD. A variable, not output, so no extra shell starts to read it.
|
|
6
7
|
slicekit_branch() {
|
|
8
|
+
slicekit_b=
|
|
7
9
|
# The full ref, stripped here: --short says heads/main when a tag main exists.
|
|
8
10
|
if slicekit_r=$(git symbolic-ref -q HEAD); then
|
|
9
|
-
case $slicekit_r in refs/heads/*)
|
|
11
|
+
case $slicekit_r in refs/heads/*) slicekit_b=${slicekit_r#refs/heads/} ;; esac
|
|
10
12
|
return 0
|
|
11
13
|
fi
|
|
12
14
|
for slicekit_d in rebase-merge rebase-apply; do
|
|
13
15
|
slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
|
|
14
16
|
if [ -f "$slicekit_f" ]; then
|
|
15
|
-
sed -e 's#^refs/heads/##' "$slicekit_f"
|
|
17
|
+
slicekit_b=$(sed -e 's#^refs/heads/##' "$slicekit_f")
|
|
16
18
|
return 0
|
|
17
19
|
fi
|
|
18
20
|
done
|
|
@@ -31,10 +33,28 @@ slicekit_op() {
|
|
|
31
33
|
# Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
|
|
32
34
|
# the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
|
|
33
35
|
# globs: globbing is off while they are compared.
|
|
36
|
+
# False only when the config's text proves branch $1 cannot be protected, so node need not start; true
|
|
37
|
+
# whenever only node can say (D-42). Proof is kept to the hot path: a slice branch spelled in ASCII
|
|
38
|
+
# letters, digits and / . _ -, whose text appears nowhere in the file, in a file with no \u or \/
|
|
39
|
+
# escape. node prints every protectedBranches value joined, numbers in JavaScript's form and nested
|
|
40
|
+
# arrays joined with commas, so no other name can be ruled out from the text alone. Shell built-ins
|
|
41
|
+
# only, and every character class spelled out, so no locale widens it.
|
|
42
|
+
slicekit_named() {
|
|
43
|
+
[ -f .slicekit/config.json ] || return 1
|
|
44
|
+
case $1 in slice/P*-S-*) ;; *) return 0 ;; esac
|
|
45
|
+
case $1 in *[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-]*) return 0 ;; esac
|
|
46
|
+
while IFS= read -r slicekit_line || [ -n "$slicekit_line" ]; do
|
|
47
|
+
case $slicekit_line in *'\u'* | *'\/'* | *"$1"*) return 0 ;; esac
|
|
48
|
+
done < .slicekit/config.json
|
|
49
|
+
return 1
|
|
50
|
+
}
|
|
34
51
|
slicekit_check_protected() {
|
|
35
52
|
[ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
|
|
36
|
-
|
|
53
|
+
slicekit_branch
|
|
37
54
|
[ -n "$slicekit_b" ] || return 0
|
|
55
|
+
# Without node or the file the list is main alone, so a branch other than main that the file never
|
|
56
|
+
# names cannot be protected: decided here without starting node (D-42).
|
|
57
|
+
[ "$slicekit_b" != main ] && ! slicekit_named "$slicekit_b" && return 0
|
|
38
58
|
slicekit_p=main
|
|
39
59
|
if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
|
|
40
60
|
if slicekit_l=$(node -e 'const c=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8").replace(/^\uFEFF/,""));const p=c.protectedBranches;if(!Array.isArray(p))process.exit(1);process.stdout.write(p.join("\n"))' .slicekit/config.json 2>/dev/null); then
|
|
@@ -2,17 +2,19 @@
|
|
|
2
2
|
# slicekit: refuses a commit on a protected branch (REQ-3.9). Installed as pre-commit and as
|
|
3
3
|
# pre-merge-commit, byte for byte; prepare-commit-msg carries the same check between the markers.
|
|
4
4
|
# >>> slicekit protected-branch check (identical in every slicekit hook)
|
|
5
|
-
#
|
|
5
|
+
# Sets slicekit_b to the branch a commit lands on: HEAD's branch, or during a rebase the branch being
|
|
6
|
+
# rebased; empty on a detached HEAD. A variable, not output, so no extra shell starts to read it.
|
|
6
7
|
slicekit_branch() {
|
|
8
|
+
slicekit_b=
|
|
7
9
|
# The full ref, stripped here: --short says heads/main when a tag main exists.
|
|
8
10
|
if slicekit_r=$(git symbolic-ref -q HEAD); then
|
|
9
|
-
case $slicekit_r in refs/heads/*)
|
|
11
|
+
case $slicekit_r in refs/heads/*) slicekit_b=${slicekit_r#refs/heads/} ;; esac
|
|
10
12
|
return 0
|
|
11
13
|
fi
|
|
12
14
|
for slicekit_d in rebase-merge rebase-apply; do
|
|
13
15
|
slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
|
|
14
16
|
if [ -f "$slicekit_f" ]; then
|
|
15
|
-
sed -e 's#^refs/heads/##' "$slicekit_f"
|
|
17
|
+
slicekit_b=$(sed -e 's#^refs/heads/##' "$slicekit_f")
|
|
16
18
|
return 0
|
|
17
19
|
fi
|
|
18
20
|
done
|
|
@@ -31,10 +33,28 @@ slicekit_op() {
|
|
|
31
33
|
# Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
|
|
32
34
|
# the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
|
|
33
35
|
# globs: globbing is off while they are compared.
|
|
36
|
+
# False only when the config's text proves branch $1 cannot be protected, so node need not start; true
|
|
37
|
+
# whenever only node can say (D-42). Proof is kept to the hot path: a slice branch spelled in ASCII
|
|
38
|
+
# letters, digits and / . _ -, whose text appears nowhere in the file, in a file with no \u or \/
|
|
39
|
+
# escape. node prints every protectedBranches value joined, numbers in JavaScript's form and nested
|
|
40
|
+
# arrays joined with commas, so no other name can be ruled out from the text alone. Shell built-ins
|
|
41
|
+
# only, and every character class spelled out, so no locale widens it.
|
|
42
|
+
slicekit_named() {
|
|
43
|
+
[ -f .slicekit/config.json ] || return 1
|
|
44
|
+
case $1 in slice/P*-S-*) ;; *) return 0 ;; esac
|
|
45
|
+
case $1 in *[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-]*) return 0 ;; esac
|
|
46
|
+
while IFS= read -r slicekit_line || [ -n "$slicekit_line" ]; do
|
|
47
|
+
case $slicekit_line in *'\u'* | *'\/'* | *"$1"*) return 0 ;; esac
|
|
48
|
+
done < .slicekit/config.json
|
|
49
|
+
return 1
|
|
50
|
+
}
|
|
34
51
|
slicekit_check_protected() {
|
|
35
52
|
[ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
|
|
36
|
-
|
|
53
|
+
slicekit_branch
|
|
37
54
|
[ -n "$slicekit_b" ] || return 0
|
|
55
|
+
# Without node or the file the list is main alone, so a branch other than main that the file never
|
|
56
|
+
# names cannot be protected: decided here without starting node (D-42).
|
|
57
|
+
[ "$slicekit_b" != main ] && ! slicekit_named "$slicekit_b" && return 0
|
|
38
58
|
slicekit_p=main
|
|
39
59
|
if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
|
|
40
60
|
if slicekit_l=$(node -e 'const c=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8").replace(/^\uFEFF/,""));const p=c.protectedBranches;if(!Array.isArray(p))process.exit(1);process.stdout.write(p.join("\n"))' .slicekit/config.json 2>/dev/null); then
|
|
@@ -4,17 +4,19 @@
|
|
|
4
4
|
# a non-zero exit aborts the commit, so the check here covers what pre-commit never sees.
|
|
5
5
|
# Arguments: <message file> [source [sha]].
|
|
6
6
|
# >>> slicekit protected-branch check (identical in every slicekit hook)
|
|
7
|
-
#
|
|
7
|
+
# Sets slicekit_b to the branch a commit lands on: HEAD's branch, or during a rebase the branch being
|
|
8
|
+
# rebased; empty on a detached HEAD. A variable, not output, so no extra shell starts to read it.
|
|
8
9
|
slicekit_branch() {
|
|
10
|
+
slicekit_b=
|
|
9
11
|
# The full ref, stripped here: --short says heads/main when a tag main exists.
|
|
10
12
|
if slicekit_r=$(git symbolic-ref -q HEAD); then
|
|
11
|
-
case $slicekit_r in refs/heads/*)
|
|
13
|
+
case $slicekit_r in refs/heads/*) slicekit_b=${slicekit_r#refs/heads/} ;; esac
|
|
12
14
|
return 0
|
|
13
15
|
fi
|
|
14
16
|
for slicekit_d in rebase-merge rebase-apply; do
|
|
15
17
|
slicekit_f=$(git rev-parse --git-path "$slicekit_d/head-name")
|
|
16
18
|
if [ -f "$slicekit_f" ]; then
|
|
17
|
-
sed -e 's#^refs/heads/##' "$slicekit_f"
|
|
19
|
+
slicekit_b=$(sed -e 's#^refs/heads/##' "$slicekit_f")
|
|
18
20
|
return 0
|
|
19
21
|
fi
|
|
20
22
|
done
|
|
@@ -33,10 +35,28 @@ slicekit_op() {
|
|
|
33
35
|
# Refuses when that branch is in protectedBranches of .slicekit/config.json, or is main when node or
|
|
34
36
|
# the file is absent or unreadable. ALLOW_PROTECTED_COMMIT=1 overrides. Entries are names, never
|
|
35
37
|
# globs: globbing is off while they are compared.
|
|
38
|
+
# False only when the config's text proves branch $1 cannot be protected, so node need not start; true
|
|
39
|
+
# whenever only node can say (D-42). Proof is kept to the hot path: a slice branch spelled in ASCII
|
|
40
|
+
# letters, digits and / . _ -, whose text appears nowhere in the file, in a file with no \u or \/
|
|
41
|
+
# escape. node prints every protectedBranches value joined, numbers in JavaScript's form and nested
|
|
42
|
+
# arrays joined with commas, so no other name can be ruled out from the text alone. Shell built-ins
|
|
43
|
+
# only, and every character class spelled out, so no locale widens it.
|
|
44
|
+
slicekit_named() {
|
|
45
|
+
[ -f .slicekit/config.json ] || return 1
|
|
46
|
+
case $1 in slice/P*-S-*) ;; *) return 0 ;; esac
|
|
47
|
+
case $1 in *[!abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/._-]*) return 0 ;; esac
|
|
48
|
+
while IFS= read -r slicekit_line || [ -n "$slicekit_line" ]; do
|
|
49
|
+
case $slicekit_line in *'\u'* | *'\/'* | *"$1"*) return 0 ;; esac
|
|
50
|
+
done < .slicekit/config.json
|
|
51
|
+
return 1
|
|
52
|
+
}
|
|
36
53
|
slicekit_check_protected() {
|
|
37
54
|
[ "$ALLOW_PROTECTED_COMMIT" = "1" ] && return 0
|
|
38
|
-
|
|
55
|
+
slicekit_branch
|
|
39
56
|
[ -n "$slicekit_b" ] || return 0
|
|
57
|
+
# Without node or the file the list is main alone, so a branch other than main that the file never
|
|
58
|
+
# names cannot be protected: decided here without starting node (D-42).
|
|
59
|
+
[ "$slicekit_b" != main ] && ! slicekit_named "$slicekit_b" && return 0
|
|
40
60
|
slicekit_p=main
|
|
41
61
|
if [ -f .slicekit/config.json ] && command -v node >/dev/null 2>&1; then
|
|
42
62
|
if slicekit_l=$(node -e 'const c=JSON.parse(require("fs").readFileSync(process.argv[1],"utf8").replace(/^\uFEFF/,""));const p=c.protectedBranches;if(!Array.isArray(p))process.exit(1);process.stdout.write(p.join("\n"))' .slicekit/config.json 2>/dev/null); then
|
|
@@ -65,7 +85,23 @@ case "$2" in
|
|
|
65
85
|
merge) exit 0 ;;
|
|
66
86
|
esac
|
|
67
87
|
|
|
68
|
-
|
|
88
|
+
# The branch the check read; under ALLOW_PROTECTED_COMMIT=1 the check reads none, so it is read here.
|
|
89
|
+
[ "$ALLOW_PROTECTED_COMMIT" = "1" ] && slicekit_branch
|
|
90
|
+
# slice/P<n>-S-<nn>[-<descr>] gives P<n>/S-<nn>, with shell built-ins only.
|
|
91
|
+
slice=
|
|
92
|
+
case $slicekit_b in
|
|
93
|
+
slice/P*-S-*)
|
|
94
|
+
slicekit_n=${slicekit_b#slice/P}
|
|
95
|
+
slicekit_s=${slicekit_n#*-S-}
|
|
96
|
+
slicekit_n=${slicekit_n%%-S-*}
|
|
97
|
+
case $slicekit_s in
|
|
98
|
+
[0123456789][0123456789] | [0123456789][0123456789]-*) slicekit_s=${slicekit_s%%-*} ;;
|
|
99
|
+
*) slicekit_s= ;;
|
|
100
|
+
esac
|
|
101
|
+
case $slicekit_n in '' | *[!0123456789]*) slicekit_s= ;; esac
|
|
102
|
+
[ -n "$slicekit_s" ] && slice="P$slicekit_n/S-$slicekit_s"
|
|
103
|
+
;;
|
|
104
|
+
esac
|
|
69
105
|
[ -n "$slice" ] || exit 0
|
|
70
106
|
|
|
71
107
|
# The trailer joins the message's final trailer block as its first line, or starts one; a block
|