@statewalker/vcs-commands 0.3.2 → 0.5.0
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/README.md +19 -0
- package/dist/commands/add-command.d.ts +0 -6
- package/dist/commands/add-command.d.ts.map +1 -1
- package/dist/commands/blame-command.d.ts +14 -0
- package/dist/commands/blame-command.d.ts.map +1 -1
- package/dist/commands/branch-command.d.ts.map +1 -1
- package/dist/commands/checkout-command.d.ts +7 -24
- package/dist/commands/checkout-command.d.ts.map +1 -1
- package/dist/commands/clean-command.d.ts +34 -4
- package/dist/commands/clean-command.d.ts.map +1 -1
- package/dist/commands/clone-command.d.ts +61 -21
- package/dist/commands/clone-command.d.ts.map +1 -1
- package/dist/commands/core-config.d.ts +16 -0
- package/dist/commands/core-config.d.ts.map +1 -0
- package/dist/commands/fetch-command.d.ts +104 -37
- package/dist/commands/fetch-command.d.ts.map +1 -1
- package/dist/commands/index.d.ts +1 -0
- package/dist/commands/index.d.ts.map +1 -1
- package/dist/commands/index.js +2 -2
- package/dist/commands/init-command.d.ts.map +1 -1
- package/dist/commands/merge-command.d.ts +15 -2
- package/dist/commands/merge-command.d.ts.map +1 -1
- package/dist/commands/push-command.d.ts +58 -25
- package/dist/commands/push-command.d.ts.map +1 -1
- package/dist/commands/remote-command.d.ts +115 -6
- package/dist/commands/remote-command.d.ts.map +1 -1
- package/dist/commands/reset-command.d.ts.map +1 -1
- package/dist/commands/stash-apply-command.d.ts +35 -13
- package/dist/commands/stash-apply-command.d.ts.map +1 -1
- package/dist/commands/stash-create-command.d.ts +59 -25
- package/dist/commands/stash-create-command.d.ts.map +1 -1
- package/dist/commands/stash-drop-command.d.ts +8 -2
- package/dist/commands/stash-drop-command.d.ts.map +1 -1
- package/dist/commands/stash-list-command.d.ts +2 -4
- package/dist/commands/stash-list-command.d.ts.map +1 -1
- package/dist/commands/stash-working-tree.d.ts +72 -0
- package/dist/commands/stash-working-tree.d.ts.map +1 -0
- package/dist/commands/status-command.d.ts +29 -22
- package/dist/commands/status-command.d.ts.map +1 -1
- package/dist/commands/tag-command.d.ts.map +1 -1
- package/dist/commands/tree-restore.d.ts +52 -5
- package/dist/commands/tree-restore.d.ts.map +1 -1
- package/dist/commands/worktree-overwrite-checks.d.ts +64 -0
- package/dist/commands/worktree-overwrite-checks.d.ts.map +1 -0
- package/dist/{commands-COO4tJhv.js → commands-CsLNyvZ1.js} +3370 -1057
- package/dist/core-commands/add.command.impl.d.ts +0 -4
- package/dist/core-commands/add.command.impl.d.ts.map +1 -1
- package/dist/core-commands/index.d.ts +1 -3
- package/dist/core-commands/index.d.ts.map +1 -1
- package/dist/core-commands/store-worktree-file.d.ts +6 -0
- package/dist/core-commands/store-worktree-file.d.ts.map +1 -0
- package/dist/errors/checkout-errors.d.ts +13 -0
- package/dist/errors/checkout-errors.d.ts.map +1 -1
- package/dist/errors/index.js +18 -1
- package/dist/git-command.d.ts +10 -1
- package/dist/git-command.d.ts.map +1 -1
- package/dist/git.d.ts +21 -3
- package/dist/git.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/remote-config/index.d.ts +1 -0
- package/dist/remote-config/index.d.ts.map +1 -1
- package/dist/remote-config/remote-config-store.d.ts +22 -0
- package/dist/remote-config/remote-config-store.d.ts.map +1 -1
- package/dist/remote-config/remote-refs.d.ts +37 -0
- package/dist/remote-config/remote-refs.d.ts.map +1 -0
- package/dist/results/clone-result.d.ts +6 -0
- package/dist/results/clone-result.d.ts.map +1 -1
- package/dist/results/diff-formatter.d.ts +14 -7
- package/dist/results/diff-formatter.d.ts.map +1 -1
- package/dist/results/fetch-result.d.ts +16 -1
- package/dist/results/fetch-result.d.ts.map +1 -1
- package/dist/results/index.js +28 -23
- package/dist/results/push-result.d.ts +9 -2
- package/dist/results/push-result.d.ts.map +1 -1
- package/dist/results/status-result.d.ts +91 -20
- package/dist/results/status-result.d.ts.map +1 -1
- package/dist/{status-result-BwAyxq6R.js → status-result-BpyUK1Sg.js} +115 -5
- package/dist/transport-command.d.ts +12 -0
- package/dist/transport-command.d.ts.map +1 -1
- package/package.json +14 -12
- package/src/commands/add-command.ts +23 -30
- package/src/commands/blame-command.ts +41 -0
- package/src/commands/branch-command.ts +2 -53
- package/src/commands/checkout-command.ts +205 -127
- package/src/commands/clean-command.ts +187 -81
- package/src/commands/clone-command.ts +334 -137
- package/src/commands/core-config.ts +41 -0
- package/src/commands/fetch-command.ts +536 -211
- package/src/commands/gc-command.ts +1 -1
- package/src/commands/index.ts +1 -0
- package/src/commands/init-command.ts +108 -11
- package/src/commands/merge-command.ts +60 -27
- package/src/commands/pack-refs-command.ts +2 -2
- package/src/commands/push-command.ts +242 -308
- package/src/commands/reflog-command.ts +2 -2
- package/src/commands/remote-command.ts +429 -19
- package/src/commands/reset-command.ts +18 -5
- package/src/commands/stash-apply-command.ts +632 -97
- package/src/commands/stash-create-command.ts +142 -62
- package/src/commands/stash-drop-command.ts +53 -5
- package/src/commands/stash-list-command.ts +10 -4
- package/src/commands/stash-working-tree.ts +243 -0
- package/src/commands/status-command.ts +197 -91
- package/src/commands/tag-command.ts +2 -53
- package/src/commands/tree-restore.ts +143 -18
- package/src/commands/worktree-overwrite-checks.ts +215 -0
- package/src/core-commands/add.command.impl.ts +15 -20
- package/src/core-commands/index.ts +1 -8
- package/src/core-commands/store-worktree-file.ts +5 -0
- package/src/errors/checkout-errors.ts +20 -0
- package/src/git-command.ts +42 -1
- package/src/git.ts +30 -2
- package/src/remote-config/index.ts +1 -0
- package/src/remote-config/remote-config-store.ts +95 -8
- package/src/remote-config/remote-refs.ts +103 -0
- package/src/results/clone-result.ts +6 -0
- package/src/results/diff-formatter.ts +31 -38
- package/src/results/fetch-result.ts +16 -1
- package/src/results/push-result.ts +9 -2
- package/src/results/status-result.ts +212 -29
- package/src/transport-command.ts +18 -0
- package/dist/core-commands/checkout.command.d.ts +0 -103
- package/dist/core-commands/checkout.command.d.ts.map +0 -1
- package/dist/core-commands/checkout.command.impl.d.ts +0 -114
- package/dist/core-commands/checkout.command.impl.d.ts.map +0 -1
- package/dist/pack-import/index.d.ts +0 -8
- package/dist/pack-import/index.d.ts.map +0 -1
- package/dist/pack-import/pack-import.d.ts +0 -11
- package/dist/pack-import/pack-import.d.ts.map +0 -1
- package/src/core-commands/checkout.command.impl.ts +0 -586
- package/src/core-commands/checkout.command.ts +0 -125
- package/src/pack-import/index.ts +0 -8
- package/src/pack-import/pack-import.ts +0 -24
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import { FileMode, isValidWorktreePath } from "@statewalker/vcs-core";
|
|
2
|
+
import { directoriesOf, type Worktree } from "@statewalker/vcs-working-tree";
|
|
1
3
|
import { GitCommand } from "../git-command.js";
|
|
4
|
+
import { removeDirectoryIfEmpty } from "./worktree-overwrite-checks.js";
|
|
2
5
|
|
|
3
6
|
/**
|
|
4
7
|
* Result of a clean operation
|
|
@@ -6,6 +9,11 @@ import { GitCommand } from "../git-command.js";
|
|
|
6
9
|
export interface CleanResult {
|
|
7
10
|
/** Files that were (or would be) removed */
|
|
8
11
|
cleaned: Set<string>;
|
|
12
|
+
/**
|
|
13
|
+
* Nested repositories left in untracked directories (`git clean -n`: "Would skip
|
|
14
|
+
* repository"); one directly under a tracked directory is passed over silently, as git
|
|
15
|
+
*/
|
|
16
|
+
skipped: Set<string>;
|
|
9
17
|
/** Whether this was a dry run (no files actually removed) */
|
|
10
18
|
dryRun: boolean;
|
|
11
19
|
}
|
|
@@ -49,6 +57,7 @@ export class CleanCommand extends GitCommand<CleanResult> {
|
|
|
49
57
|
private dryRun = true; // Default to dry-run for safety
|
|
50
58
|
private directories = false;
|
|
51
59
|
private ignore = true; // Respect .gitignore
|
|
60
|
+
private forceNested = false;
|
|
52
61
|
|
|
53
62
|
/**
|
|
54
63
|
* Limit clean to specific paths.
|
|
@@ -76,7 +85,8 @@ export class CleanCommand extends GitCommand<CleanResult> {
|
|
|
76
85
|
}
|
|
77
86
|
|
|
78
87
|
/**
|
|
79
|
-
* Set whether to also clean directories
|
|
88
|
+
* Set whether to also clean untracked directories (`git clean -d`): their untracked
|
|
89
|
+
* files are removed and each directory once it is empty.
|
|
80
90
|
*
|
|
81
91
|
* @param directories Whether to clean directories
|
|
82
92
|
*/
|
|
@@ -101,7 +111,30 @@ export class CleanCommand extends GitCommand<CleanResult> {
|
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
/**
|
|
104
|
-
*
|
|
114
|
+
* Set whether nested repositories (untracked directories with their own `.git`) are
|
|
115
|
+
* removed too, as `git clean -ff`. Off by default: they are skipped, as `git clean -f`
|
|
116
|
+
* skips them, and listed in `skipped`.
|
|
117
|
+
*
|
|
118
|
+
* @param force Whether to remove nested repositories
|
|
119
|
+
*/
|
|
120
|
+
setForceNestedRepositories(force: boolean): this {
|
|
121
|
+
this.checkCallable();
|
|
122
|
+
this.forceNested = force;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Execute the clean command, as `git clean -f` (`-d` with `setCleanDirectories(true)`,
|
|
128
|
+
* `-x` with `setIgnore(false)`, `-ff` with `setForceNestedRepositories(true)`, `-n` with
|
|
129
|
+
* dry run):
|
|
130
|
+
* - only files the index does not track are removed, one at a time;
|
|
131
|
+
* - an untracked directory (one holding no tracked or staged path) is entered only with
|
|
132
|
+
* `-d` or a path filter; with `-d` it is removed once empty, deepest first and never
|
|
133
|
+
* recursively, so whatever stays in it (an ignored file without `-x`, a nested
|
|
134
|
+
* repository without `-ff`) keeps it;
|
|
135
|
+
* - `cleaned` lists what `git clean -n` prints after "Would remove": a wholly removed
|
|
136
|
+
* untracked directory as `dir/`, else the files; `skipped` the nested repositories
|
|
137
|
+
* ("Would skip repository").
|
|
105
138
|
*
|
|
106
139
|
* @returns CleanResult with set of cleaned files
|
|
107
140
|
*/
|
|
@@ -109,110 +142,183 @@ export class CleanCommand extends GitCommand<CleanResult> {
|
|
|
109
142
|
this.checkCallable();
|
|
110
143
|
this.setCallable(false);
|
|
111
144
|
|
|
112
|
-
const cleaned = new Set<string>();
|
|
113
|
-
const toRemove: Array<{ path: string; isDirectory: boolean }> = [];
|
|
114
|
-
|
|
115
|
-
// Check if worktree is available
|
|
116
145
|
const worktree = this.worktreeAccess;
|
|
117
146
|
if (!worktree) {
|
|
118
147
|
throw new Error("CleanCommand requires a WorkingCopy with worktree");
|
|
119
148
|
}
|
|
149
|
+
return worktree.batch ? worktree.batch(() => this.clean(worktree)) : this.clean(worktree);
|
|
150
|
+
}
|
|
120
151
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
152
|
+
/**
|
|
153
|
+
* Whether `path` is or lies in one of the requested paths, as git's pathspec matches it: a
|
|
154
|
+
* plain path matches itself and what is below it; one with `*`, `?` or `[...]` is a glob
|
|
155
|
+
* over the whole path (`*` matching `/` too).
|
|
156
|
+
*/
|
|
157
|
+
private matchesPaths(path: string, isDirectory = false): boolean {
|
|
158
|
+
if (this.paths.size === 0) return true;
|
|
159
|
+
for (const p of this.paths) {
|
|
160
|
+
const spec = p.replace(/\/+$/, "");
|
|
161
|
+
if (spec === "" || spec === ".") return true;
|
|
162
|
+
if (/[*?[]/.test(spec)) {
|
|
163
|
+
// a directory is matched with its trailing slash too (`u/*` names `u/`, as git)
|
|
164
|
+
const glob = globToRegExp(spec);
|
|
165
|
+
if (glob.test(path) || (isDirectory && glob.test(`${path}/`))) return true;
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (path === spec || path.startsWith(`${spec}/`)) return true;
|
|
125
169
|
}
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
126
172
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
const commit = await this.commits.load(head.objectId);
|
|
133
|
-
if (commit) {
|
|
134
|
-
await this.collectTreePaths(commit.tree, "", headPaths);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} catch {
|
|
138
|
-
// No HEAD yet, all files are "new"
|
|
173
|
+
/** Whether a requested path names `path` itself. */
|
|
174
|
+
private namesPath(path: string): boolean {
|
|
175
|
+
for (const p of this.paths) {
|
|
176
|
+
const spec = p.replace(/\/+$/, "");
|
|
177
|
+
if (spec === path || (/[*?[]/.test(spec) && globToRegExp(spec).test(path))) return true;
|
|
139
178
|
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
140
181
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
182
|
+
private async clean(worktree: Worktree): Promise<CleanResult> {
|
|
183
|
+
// what the index tracks (any stage): git clean looks at the index, not at HEAD
|
|
184
|
+
const tracked = new Set<string>();
|
|
185
|
+
for await (const entry of this.staging.entries()) tracked.add(entry.path);
|
|
186
|
+
const trackedDirs = directoriesOf(tracked);
|
|
187
|
+
const removeIgnored = !this.ignore;
|
|
188
|
+
// without -d (and without a path filter) git does not enter untracked directories; a
|
|
189
|
+
// path filter removes the directories it names as -d does
|
|
190
|
+
const enterUntracked = this.directories || this.paths.size > 0;
|
|
191
|
+
const ancestors = (path: string) => {
|
|
192
|
+
const parts = path.split("/");
|
|
193
|
+
const out: string[] = [];
|
|
194
|
+
for (let k = 1; k < parts.length; k++) out.push(parts.slice(0, k).join("/"));
|
|
195
|
+
return out;
|
|
145
196
|
};
|
|
146
197
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
let matches = false;
|
|
153
|
-
for (const p of this.paths) {
|
|
154
|
-
if (entryTyped.path === p || entryTyped.path.startsWith(`${p}/`)) {
|
|
155
|
-
matches = true;
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (!matches) continue;
|
|
198
|
+
// whether something under `dir` stays (an ignored file without -x)
|
|
199
|
+
const holdsKept = async (dir: string) => {
|
|
200
|
+
if (removeIgnored) return false;
|
|
201
|
+
for await (const inside of worktree.walk({ pathPrefix: dir, includeIgnored: true })) {
|
|
202
|
+
if (inside.isIgnored) return true;
|
|
160
203
|
}
|
|
204
|
+
return false;
|
|
205
|
+
};
|
|
161
206
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
207
|
+
const removeFiles: string[] = [];
|
|
208
|
+
const removeRepos: string[] = [];
|
|
209
|
+
const untrackedDirs: string[] = [];
|
|
210
|
+
const notEntered = new Set<string>();
|
|
211
|
+
const skipped = new Set<string>();
|
|
212
|
+
// the untracked directories something stays in: they stay too
|
|
213
|
+
const kept = new Set<string>();
|
|
214
|
+
const keep = (path: string, isDirectory = false) => {
|
|
215
|
+
for (const dir of ancestors(path)) kept.add(dir);
|
|
216
|
+
if (isDirectory) kept.add(path);
|
|
217
|
+
};
|
|
166
218
|
|
|
167
|
-
|
|
168
|
-
|
|
219
|
+
for await (const entry of worktree.walk({ includeIgnored: true, includeDirectories: true })) {
|
|
220
|
+
const path = entry.path;
|
|
221
|
+
if (ancestors(path).some((dir) => notEntered.has(dir))) continue;
|
|
222
|
+
const keptAsIgnored = entry.isIgnored && !removeIgnored;
|
|
223
|
+
if (entry.isDirectory) {
|
|
224
|
+
if (trackedDirs.has(path)) continue;
|
|
225
|
+
// a directory where the index has a file, link or submodule: git never enters it
|
|
226
|
+
if (tracked.has(path) || !enterUntracked) {
|
|
227
|
+
notEntered.add(path);
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
if (entry.mode === FileMode.GITLINK) {
|
|
231
|
+
notEntered.add(path);
|
|
232
|
+
// a `.git` that is no repository (an empty directory): an ordinary directory
|
|
233
|
+
// to git clean, removed with what is in it
|
|
234
|
+
if (worktree.isRepository && !(await worktree.isRepository(path))) {
|
|
235
|
+
if (keptAsIgnored || !this.matchesPaths(path) || (await holdsKept(path))) {
|
|
236
|
+
keep(path, true);
|
|
237
|
+
} else removeRepos.push(path);
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
// a nested repository: only `git clean -ff` removes it (whole)
|
|
241
|
+
if (keptAsIgnored || !this.matchesPaths(path)) keep(path, true);
|
|
242
|
+
else if (!this.forceNested) {
|
|
243
|
+
// git reports the ones it meets while removing an untracked directory
|
|
244
|
+
// ("Would skip repository u/sub"); one directly under a tracked directory, or
|
|
245
|
+
// named by a requested path, is passed over silently
|
|
246
|
+
if (ancestors(path).some((dir) => !trackedDirs.has(dir)) && !this.namesPath(path)) {
|
|
247
|
+
skipped.add(path);
|
|
248
|
+
}
|
|
249
|
+
keep(path, true);
|
|
250
|
+
} else removeRepos.push(path);
|
|
251
|
+
continue;
|
|
252
|
+
}
|
|
253
|
+
untrackedDirs.push(path);
|
|
254
|
+
// an ignored directory stays whole without -x
|
|
255
|
+
if (keptAsIgnored) keep(path, true);
|
|
169
256
|
continue;
|
|
170
257
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
258
|
+
if (tracked.has(path)) continue;
|
|
259
|
+
if (
|
|
260
|
+
keptAsIgnored ||
|
|
261
|
+
!this.matchesPaths(path) ||
|
|
262
|
+
// a name that spells `.git` is refused by the worktree (git's verify_path): left
|
|
263
|
+
!isValidWorktreePath(path)
|
|
264
|
+
) {
|
|
265
|
+
keep(path);
|
|
174
266
|
continue;
|
|
175
267
|
}
|
|
268
|
+
removeFiles.push(path);
|
|
269
|
+
}
|
|
176
270
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
271
|
+
// what git clean -n prints: the topmost wholly removed untracked directory, else files
|
|
272
|
+
const dirMode = this.directories || this.paths.size > 0;
|
|
273
|
+
const removedDir = (dir: string) =>
|
|
274
|
+
dirMode && !trackedDirs.has(dir) && !kept.has(dir) && this.matchesPaths(dir, true);
|
|
275
|
+
const reportFor = (path: string, suffix = "") => {
|
|
276
|
+
for (const dir of ancestors(path)) if (removedDir(dir)) return `${dir}/`;
|
|
277
|
+
return `${path}${suffix}`;
|
|
278
|
+
};
|
|
279
|
+
const cleaned = new Set<string>();
|
|
280
|
+
for (const path of removeFiles) cleaned.add(reportFor(path));
|
|
281
|
+
for (const path of removeRepos) cleaned.add(reportFor(path, "/"));
|
|
282
|
+
for (const dir of untrackedDirs) if (removedDir(dir)) cleaned.add(reportFor(dir, "/"));
|
|
180
283
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
|
|
284
|
+
if (!this.dryRun) {
|
|
285
|
+
for (const path of removeFiles) await worktree.remove(path);
|
|
286
|
+
// `git clean -ff` (or a `.git` that is no repository): the directory goes, whole
|
|
287
|
+
for (const path of removeRepos) await worktree.remove(path, { recursive: true });
|
|
288
|
+
if (dirMode) {
|
|
289
|
+
const deepestFirst = [...untrackedDirs].sort(
|
|
290
|
+
(a, b) => b.split("/").length - a.split("/").length || (a < b ? 1 : -1),
|
|
291
|
+
);
|
|
292
|
+
// only the directories the path filter names (a glob emptying one leaves it)
|
|
293
|
+
for (const dir of deepestFirst) {
|
|
294
|
+
if (this.matchesPaths(dir, true)) await removeDirectoryIfEmpty(worktree, dir);
|
|
295
|
+
}
|
|
186
296
|
}
|
|
187
297
|
}
|
|
188
298
|
|
|
189
|
-
|
|
190
|
-
await worktree.remove(path, { recursive: isDirectory });
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
return {
|
|
194
|
-
cleaned,
|
|
195
|
-
dryRun: this.dryRun,
|
|
196
|
-
};
|
|
299
|
+
return { cleaned, skipped, dryRun: this.dryRun };
|
|
197
300
|
}
|
|
301
|
+
}
|
|
198
302
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
303
|
+
/** A pathspec glob as a regular expression over the whole path (`*` matches `/` too). */
|
|
304
|
+
function globToRegExp(glob: string): RegExp {
|
|
305
|
+
let out = "";
|
|
306
|
+
for (let i = 0; i < glob.length; i++) {
|
|
307
|
+
const c = glob[i];
|
|
308
|
+
if (c === "*") out += ".*";
|
|
309
|
+
else if (c === "?") out += "[^/]";
|
|
310
|
+
else if (c === "[") {
|
|
311
|
+
const end = glob.indexOf("]", i + 1);
|
|
312
|
+
if (end < 0) out += "\\[";
|
|
313
|
+
else {
|
|
314
|
+
const body = glob
|
|
315
|
+
.slice(i + 1, end)
|
|
316
|
+
.replace(/^!/, "^")
|
|
317
|
+
.replace(/\\/g, "\\\\");
|
|
318
|
+
out += `[${body}]`;
|
|
319
|
+
i = end;
|
|
215
320
|
}
|
|
216
|
-
}
|
|
321
|
+
} else out += c.replace(/[.+^${}()|\\/]/g, "\\$&");
|
|
217
322
|
}
|
|
323
|
+
return new RegExp(`^${out}$`);
|
|
218
324
|
}
|