@commonlyai/cli 0.1.181 → 0.1.182
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 +1 -1
- package/src/lib/git-readonly.js +20 -8
package/package.json
CHANGED
package/src/lib/git-readonly.js
CHANGED
|
@@ -127,16 +127,28 @@ const TOP_LEVEL = Object.freeze([
|
|
|
127
127
|
]);
|
|
128
128
|
|
|
129
129
|
// A %G placeholder (%G?, %GG, %GS, %GK, %GF, %GP, %GT) runs gpg on each signed
|
|
130
|
-
// commit
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
|
|
130
|
+
// commit, and git reads one behind a `+`, `-` or space modifier (`%+G?`,
|
|
131
|
+
// `%-GG`, `% GS`) as the same placeholder. A value with no %, no format: and
|
|
132
|
+
// no tformat: is looked up by prefix among the built-in formats and the
|
|
133
|
+
// repository's `pretty.<name>` aliases, and an alias can hold one, so only a
|
|
134
|
+
// built-in name is taken.
|
|
135
|
+
const SIGNATURE_PLACEHOLDER = /%[-+ ]?G/;
|
|
134
136
|
const BUILTIN_FORMATS = Object.freeze(['oneline', 'short', 'medium', 'full', 'fuller', 'reference', 'email', 'mboxrd', 'raw']);
|
|
137
|
+
// Git's revision parser reads --pretty and --format only by their exact names,
|
|
138
|
+
// and their format only after `=`: a bare --pretty means medium, and a bare
|
|
139
|
+
// --format is an unrecognized argument. The check does not depend on that. An
|
|
140
|
+
// abbreviation (`--form=`, `--pret=`) is checked like the full name, and a
|
|
141
|
+
// --format that would take its format from the next argument is refused.
|
|
142
|
+
const FORMAT_OPTIONS = Object.freeze(['--pretty', '--format']);
|
|
135
143
|
const checkFormat = (arg) => {
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
if (
|
|
144
|
+
const [name] = arg.split('=', 1);
|
|
145
|
+
const option = name.length >= 3 && FORMAT_OPTIONS.find((full) => full.startsWith(name));
|
|
146
|
+
if (!option) return null;
|
|
147
|
+
if (name === arg) {
|
|
148
|
+
return option === '--format' ? `${arg} is refused: give the format in the same argument, as --format=<format>` : null;
|
|
149
|
+
}
|
|
150
|
+
const value = arg.slice(name.length + 1);
|
|
151
|
+
if (SIGNATURE_PLACEHOLDER.test(value)) return `${arg} is refused: a %G placeholder runs gpg to check a signature`;
|
|
140
152
|
const userFormat = value === '' || value.startsWith('format:') || value.startsWith('tformat:') || value.includes('%');
|
|
141
153
|
if (userFormat || BUILTIN_FORMATS.includes(value.toLowerCase())) return null;
|
|
142
154
|
return `${arg} is refused: name a built-in format (${BUILTIN_FORMATS.join(', ')}) or give format:<placeholders>`;
|