type-git 0.0.2 → 0.1.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 +33 -4
- package/dist/adapters/bun/index.cjs +421 -0
- package/dist/adapters/bun/index.cjs.map +1 -0
- package/dist/adapters/bun/index.d.cts +44 -0
- package/dist/adapters/bun/index.d.ts +38 -5
- package/dist/adapters/bun/index.js +388 -13
- package/dist/adapters/bun/index.js.map +1 -1
- package/dist/adapters/deno/index.cjs +472 -0
- package/dist/adapters/deno/index.cjs.map +1 -0
- package/dist/adapters/deno/index.d.cts +46 -0
- package/dist/adapters/deno/index.d.ts +40 -5
- package/dist/adapters/deno/index.js +439 -13
- package/dist/adapters/deno/index.js.map +1 -1
- package/dist/adapters/node/index.cjs +6254 -0
- package/dist/adapters/node/index.cjs.map +1 -0
- package/dist/{core/repo.d.ts → adapters/node/index.d.cts} +1452 -184
- package/dist/adapters/node/index.d.ts +4123 -13
- package/dist/adapters/node/index.js +6210 -119
- package/dist/adapters/node/index.js.map +1 -1
- package/dist/{core/types.d.ts → adapters-DehG3CsV.d.cts} +223 -29
- package/dist/adapters-DehG3CsV.d.ts +574 -0
- package/dist/index.cjs +6383 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -9
- package/dist/index.js +6320 -13
- package/dist/index.js.map +1 -1
- package/package.json +13 -7
- package/dist/adapters/bun/exec.d.ts +0 -13
- package/dist/adapters/bun/exec.d.ts.map +0 -1
- package/dist/adapters/bun/exec.js +0 -242
- package/dist/adapters/bun/exec.js.map +0 -1
- package/dist/adapters/bun/fs.d.ts +0 -20
- package/dist/adapters/bun/fs.d.ts.map +0 -1
- package/dist/adapters/bun/fs.js +0 -148
- package/dist/adapters/bun/fs.js.map +0 -1
- package/dist/adapters/bun/index.d.ts.map +0 -1
- package/dist/adapters/deno/exec.d.ts +0 -14
- package/dist/adapters/deno/exec.d.ts.map +0 -1
- package/dist/adapters/deno/exec.js +0 -266
- package/dist/adapters/deno/exec.js.map +0 -1
- package/dist/adapters/deno/fs.d.ts +0 -21
- package/dist/adapters/deno/fs.d.ts.map +0 -1
- package/dist/adapters/deno/fs.js +0 -191
- package/dist/adapters/deno/fs.js.map +0 -1
- package/dist/adapters/deno/index.d.ts.map +0 -1
- package/dist/adapters/node/exec.d.ts +0 -11
- package/dist/adapters/node/exec.d.ts.map +0 -1
- package/dist/adapters/node/exec.js +0 -161
- package/dist/adapters/node/exec.js.map +0 -1
- package/dist/adapters/node/fs.d.ts +0 -18
- package/dist/adapters/node/fs.d.ts.map +0 -1
- package/dist/adapters/node/fs.js +0 -164
- package/dist/adapters/node/fs.js.map +0 -1
- package/dist/adapters/node/index.d.ts.map +0 -1
- package/dist/core/adapters.d.ts +0 -192
- package/dist/core/adapters.d.ts.map +0 -1
- package/dist/core/adapters.js +0 -10
- package/dist/core/adapters.js.map +0 -1
- package/dist/core/git.d.ts +0 -426
- package/dist/core/git.d.ts.map +0 -1
- package/dist/core/git.js +0 -5
- package/dist/core/git.js.map +0 -1
- package/dist/core/index.d.ts +0 -8
- package/dist/core/index.d.ts.map +0 -1
- package/dist/core/index.js +0 -8
- package/dist/core/index.js.map +0 -1
- package/dist/core/repo.d.ts.map +0 -1
- package/dist/core/repo.js +0 -5
- package/dist/core/repo.js.map +0 -1
- package/dist/core/types.d.ts.map +0 -1
- package/dist/core/types.js +0 -100
- package/dist/core/types.js.map +0 -1
- package/dist/impl/bare-repo-impl.d.ts +0 -91
- package/dist/impl/bare-repo-impl.d.ts.map +0 -1
- package/dist/impl/bare-repo-impl.js +0 -446
- package/dist/impl/bare-repo-impl.js.map +0 -1
- package/dist/impl/git-impl.d.ts +0 -125
- package/dist/impl/git-impl.d.ts.map +0 -1
- package/dist/impl/git-impl.js +0 -554
- package/dist/impl/git-impl.js.map +0 -1
- package/dist/impl/index.d.ts +0 -7
- package/dist/impl/index.d.ts.map +0 -1
- package/dist/impl/index.js +0 -7
- package/dist/impl/index.js.map +0 -1
- package/dist/impl/worktree-repo-impl.d.ts +0 -226
- package/dist/impl/worktree-repo-impl.d.ts.map +0 -1
- package/dist/impl/worktree-repo-impl.js +0 -3887
- package/dist/impl/worktree-repo-impl.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/parsers/index.d.ts +0 -230
- package/dist/parsers/index.d.ts.map +0 -1
- package/dist/parsers/index.js +0 -529
- package/dist/parsers/index.js.map +0 -1
- package/dist/runner/cli-runner.d.ts +0 -94
- package/dist/runner/cli-runner.d.ts.map +0 -1
- package/dist/runner/cli-runner.js +0 -315
- package/dist/runner/cli-runner.js.map +0 -1
- package/dist/runner/index.d.ts +0 -5
- package/dist/runner/index.d.ts.map +0 -1
- package/dist/runner/index.js +0 -5
- package/dist/runner/index.js.map +0 -1
|
@@ -1,3887 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WorktreeRepo implementation - repository with working directory
|
|
3
|
-
*/
|
|
4
|
-
import { GIT_LOG_FORMAT, parseGitLog, parseLines, parsePorcelainV2, parseWorktreeList, } from '../parsers/index.js';
|
|
5
|
-
/**
|
|
6
|
-
* WorktreeRepo implementation
|
|
7
|
-
*/
|
|
8
|
-
export class WorktreeRepoImpl {
|
|
9
|
-
workdir;
|
|
10
|
-
runner;
|
|
11
|
-
_lfsMode = 'enabled';
|
|
12
|
-
lfs;
|
|
13
|
-
lfsExtra;
|
|
14
|
-
worktree;
|
|
15
|
-
branch;
|
|
16
|
-
stash;
|
|
17
|
-
tag;
|
|
18
|
-
submodule;
|
|
19
|
-
remote;
|
|
20
|
-
config;
|
|
21
|
-
constructor(runner, workdir, options) {
|
|
22
|
-
this.runner = runner;
|
|
23
|
-
this.workdir = workdir;
|
|
24
|
-
if (options?.lfs) {
|
|
25
|
-
this._lfsMode = options.lfs;
|
|
26
|
-
}
|
|
27
|
-
// Initialize LFS operations
|
|
28
|
-
this.lfs = {
|
|
29
|
-
pull: this.lfsPull.bind(this),
|
|
30
|
-
push: this.lfsPush.bind(this),
|
|
31
|
-
status: this.lfsStatus.bind(this),
|
|
32
|
-
prune: this.lfsPrune.bind(this),
|
|
33
|
-
fetch: this.lfsFetch.bind(this),
|
|
34
|
-
install: this.lfsInstall.bind(this),
|
|
35
|
-
uninstall: this.lfsUninstall.bind(this),
|
|
36
|
-
lsFiles: this.lfsLsFiles.bind(this),
|
|
37
|
-
track: this.lfsTrack.bind(this),
|
|
38
|
-
trackList: this.lfsTrackList.bind(this),
|
|
39
|
-
untrack: this.lfsUntrack.bind(this),
|
|
40
|
-
lock: this.lfsLock.bind(this),
|
|
41
|
-
unlock: this.lfsUnlock.bind(this),
|
|
42
|
-
locks: this.lfsLocks.bind(this),
|
|
43
|
-
checkout: this.lfsCheckout.bind(this),
|
|
44
|
-
migrateInfo: this.lfsMigrateInfo.bind(this),
|
|
45
|
-
migrateImport: this.lfsMigrateImport.bind(this),
|
|
46
|
-
migrateExport: this.lfsMigrateExport.bind(this),
|
|
47
|
-
env: this.lfsEnv.bind(this),
|
|
48
|
-
version: this.lfsVersion.bind(this),
|
|
49
|
-
};
|
|
50
|
-
// Initialize LFS extra operations
|
|
51
|
-
this.lfsExtra = {
|
|
52
|
-
preUpload: this.lfsPreUpload.bind(this),
|
|
53
|
-
preDownload: this.lfsPreDownload.bind(this),
|
|
54
|
-
};
|
|
55
|
-
// Initialize worktree operations
|
|
56
|
-
this.worktree = {
|
|
57
|
-
list: this.worktreeList.bind(this),
|
|
58
|
-
add: this.worktreeAdd.bind(this),
|
|
59
|
-
remove: this.worktreeRemove.bind(this),
|
|
60
|
-
prune: this.worktreePrune.bind(this),
|
|
61
|
-
lock: this.worktreeLock.bind(this),
|
|
62
|
-
unlock: this.worktreeUnlock.bind(this),
|
|
63
|
-
move: this.worktreeMove.bind(this),
|
|
64
|
-
repair: this.worktreeRepair.bind(this),
|
|
65
|
-
};
|
|
66
|
-
// Initialize branch operations
|
|
67
|
-
this.branch = {
|
|
68
|
-
list: this.branchList.bind(this),
|
|
69
|
-
current: this.branchCurrent.bind(this),
|
|
70
|
-
create: this.branchCreate.bind(this),
|
|
71
|
-
delete: this.branchDelete.bind(this),
|
|
72
|
-
rename: this.branchRename.bind(this),
|
|
73
|
-
};
|
|
74
|
-
// Initialize stash operations
|
|
75
|
-
this.stash = {
|
|
76
|
-
list: this.stashList.bind(this),
|
|
77
|
-
push: this.stashPush.bind(this),
|
|
78
|
-
pop: this.stashPop.bind(this),
|
|
79
|
-
apply: this.stashApply.bind(this),
|
|
80
|
-
drop: this.stashDrop.bind(this),
|
|
81
|
-
clear: this.stashClear.bind(this),
|
|
82
|
-
};
|
|
83
|
-
// Initialize tag operations
|
|
84
|
-
this.tag = {
|
|
85
|
-
list: this.tagList.bind(this),
|
|
86
|
-
create: this.tagCreate.bind(this),
|
|
87
|
-
delete: this.tagDelete.bind(this),
|
|
88
|
-
show: this.tagShow.bind(this),
|
|
89
|
-
};
|
|
90
|
-
// Initialize submodule operations
|
|
91
|
-
this.submodule = {
|
|
92
|
-
list: this.submoduleList.bind(this),
|
|
93
|
-
init: this.submoduleInit.bind(this),
|
|
94
|
-
update: this.submoduleUpdate.bind(this),
|
|
95
|
-
add: this.submoduleAdd.bind(this),
|
|
96
|
-
deinit: this.submoduleDeinit.bind(this),
|
|
97
|
-
status: this.submoduleStatus.bind(this),
|
|
98
|
-
summary: this.submoduleSummary.bind(this),
|
|
99
|
-
foreach: this.submoduleForeach.bind(this),
|
|
100
|
-
sync: this.submoduleSync.bind(this),
|
|
101
|
-
absorbGitDirs: this.submoduleAbsorbGitDirs.bind(this),
|
|
102
|
-
setBranch: this.submoduleSetBranch.bind(this),
|
|
103
|
-
setUrl: this.submoduleSetUrl.bind(this),
|
|
104
|
-
};
|
|
105
|
-
// Initialize remote operations
|
|
106
|
-
this.remote = {
|
|
107
|
-
list: this.remoteList.bind(this),
|
|
108
|
-
add: this.remoteAdd.bind(this),
|
|
109
|
-
remove: this.remoteRemove.bind(this),
|
|
110
|
-
rename: this.remoteRename.bind(this),
|
|
111
|
-
getUrl: this.remoteGetUrl.bind(this),
|
|
112
|
-
setUrl: this.remoteSetUrl.bind(this),
|
|
113
|
-
setHead: this.remoteSetHead.bind(this),
|
|
114
|
-
show: this.remoteShow.bind(this),
|
|
115
|
-
prune: this.remotePrune.bind(this),
|
|
116
|
-
update: this.remoteUpdate.bind(this),
|
|
117
|
-
setBranches: this.remoteSetBranches.bind(this),
|
|
118
|
-
};
|
|
119
|
-
// Initialize config operations (repository-level)
|
|
120
|
-
this.config = {
|
|
121
|
-
get: this.configGet.bind(this),
|
|
122
|
-
getAll: this.configGetAll.bind(this),
|
|
123
|
-
set: this.configSet.bind(this),
|
|
124
|
-
add: this.configAdd.bind(this),
|
|
125
|
-
unset: this.configUnset.bind(this),
|
|
126
|
-
getRaw: this.configGetRaw.bind(this),
|
|
127
|
-
setRaw: this.configSetRaw.bind(this),
|
|
128
|
-
unsetRaw: this.configUnsetRaw.bind(this),
|
|
129
|
-
list: this.configList.bind(this),
|
|
130
|
-
renameSection: this.configRenameSection.bind(this),
|
|
131
|
-
removeSection: this.configRemoveSection.bind(this),
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
get context() {
|
|
135
|
-
return { type: 'worktree', workdir: this.workdir };
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* Execute a raw git command in this repository context
|
|
139
|
-
*/
|
|
140
|
-
async raw(argv, opts) {
|
|
141
|
-
return this.runner.run(this.context, argv, opts);
|
|
142
|
-
}
|
|
143
|
-
/**
|
|
144
|
-
* Check if this repository is a worktree repository (has working directory)
|
|
145
|
-
*
|
|
146
|
-
* For WorktreeRepoImpl, this returns the actual state from git.
|
|
147
|
-
*/
|
|
148
|
-
async isWorktree() {
|
|
149
|
-
const result = await this.runner.run(this.context, ['rev-parse', '--is-inside-work-tree']);
|
|
150
|
-
return result.exitCode === 0 && result.stdout.trim() === 'true';
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Check if this repository is a bare repository (no working directory)
|
|
154
|
-
*
|
|
155
|
-
* For WorktreeRepoImpl, this queries git and returns the actual state.
|
|
156
|
-
*/
|
|
157
|
-
async isBare() {
|
|
158
|
-
const result = await this.runner.run(this.context, ['rev-parse', '--is-bare-repository']);
|
|
159
|
-
return result.exitCode === 0 && result.stdout.trim() === 'true';
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Get repository status
|
|
163
|
-
*/
|
|
164
|
-
async status(opts) {
|
|
165
|
-
const args = ['status', '--porcelain=v2'];
|
|
166
|
-
// Verbosity options
|
|
167
|
-
if (opts?.verbose) {
|
|
168
|
-
args.push('--verbose');
|
|
169
|
-
}
|
|
170
|
-
// Untracked files handling
|
|
171
|
-
if (opts?.untracked) {
|
|
172
|
-
switch (opts.untracked) {
|
|
173
|
-
case 'no':
|
|
174
|
-
args.push('-uno');
|
|
175
|
-
break;
|
|
176
|
-
case 'normal':
|
|
177
|
-
args.push('-unormal');
|
|
178
|
-
break;
|
|
179
|
-
case 'all':
|
|
180
|
-
args.push('-uall');
|
|
181
|
-
break;
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
// Add branch info
|
|
185
|
-
args.push('--branch');
|
|
186
|
-
// Show stash information
|
|
187
|
-
if (opts?.showStash) {
|
|
188
|
-
args.push('--show-stash');
|
|
189
|
-
}
|
|
190
|
-
// Ahead/behind tracking
|
|
191
|
-
if (opts?.aheadBehind === false) {
|
|
192
|
-
args.push('--no-ahead-behind');
|
|
193
|
-
}
|
|
194
|
-
// NUL terminator
|
|
195
|
-
if (opts?.nullTerminated) {
|
|
196
|
-
args.push('-z');
|
|
197
|
-
}
|
|
198
|
-
// Ignored files handling
|
|
199
|
-
if (opts?.ignored) {
|
|
200
|
-
switch (opts.ignored) {
|
|
201
|
-
case 'traditional':
|
|
202
|
-
args.push('--ignored=traditional');
|
|
203
|
-
break;
|
|
204
|
-
case 'no':
|
|
205
|
-
args.push('--ignored=no');
|
|
206
|
-
break;
|
|
207
|
-
case 'matching':
|
|
208
|
-
args.push('--ignored=matching');
|
|
209
|
-
break;
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
// Submodule handling
|
|
213
|
-
if (opts?.ignoreSubmodules) {
|
|
214
|
-
args.push(`--ignore-submodules=${opts.ignoreSubmodules}`);
|
|
215
|
-
}
|
|
216
|
-
// Rename detection
|
|
217
|
-
if (opts?.noRenames) {
|
|
218
|
-
args.push('--no-renames');
|
|
219
|
-
}
|
|
220
|
-
else if (opts?.findRenames !== undefined) {
|
|
221
|
-
if (opts.findRenames === true) {
|
|
222
|
-
args.push('--find-renames');
|
|
223
|
-
}
|
|
224
|
-
else if (typeof opts.findRenames === 'number') {
|
|
225
|
-
args.push(`--find-renames=${opts.findRenames}`);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
229
|
-
signal: opts?.signal,
|
|
230
|
-
});
|
|
231
|
-
return this.parseStatus(result.stdout);
|
|
232
|
-
}
|
|
233
|
-
parseStatus(stdout) {
|
|
234
|
-
const lines = parseLines(stdout);
|
|
235
|
-
const entries = [];
|
|
236
|
-
let branch;
|
|
237
|
-
let upstream;
|
|
238
|
-
let ahead;
|
|
239
|
-
let behind;
|
|
240
|
-
for (const line of lines) {
|
|
241
|
-
if (line.startsWith('# branch.head ')) {
|
|
242
|
-
branch = line.slice('# branch.head '.length);
|
|
243
|
-
}
|
|
244
|
-
else if (line.startsWith('# branch.upstream ')) {
|
|
245
|
-
upstream = line.slice('# branch.upstream '.length);
|
|
246
|
-
}
|
|
247
|
-
else if (line.startsWith('# branch.ab ')) {
|
|
248
|
-
const match = line.match(/# branch\.ab \+(\d+) -(\d+)/);
|
|
249
|
-
const aheadStr = match?.[1];
|
|
250
|
-
const behindStr = match?.[2];
|
|
251
|
-
if (aheadStr !== undefined && behindStr !== undefined) {
|
|
252
|
-
ahead = Number.parseInt(aheadStr, 10);
|
|
253
|
-
behind = Number.parseInt(behindStr, 10);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
else if (line.startsWith('1 ') || line.startsWith('2 ')) {
|
|
257
|
-
// Regular or renamed entry
|
|
258
|
-
const parsed = parsePorcelainV2(line);
|
|
259
|
-
const entry = parsed[0];
|
|
260
|
-
if (entry?.type === 'changed') {
|
|
261
|
-
const indexStatus = entry.xy[0];
|
|
262
|
-
const workdirStatus = entry.xy[1];
|
|
263
|
-
if (indexStatus !== undefined && workdirStatus !== undefined) {
|
|
264
|
-
entries.push({
|
|
265
|
-
path: entry.path,
|
|
266
|
-
index: indexStatus,
|
|
267
|
-
workdir: workdirStatus,
|
|
268
|
-
originalPath: entry.origPath,
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
else if (line.startsWith('u ')) {
|
|
274
|
-
// Unmerged entry
|
|
275
|
-
const parsed = parsePorcelainV2(line);
|
|
276
|
-
const entry = parsed[0];
|
|
277
|
-
if (entry?.type === 'unmerged') {
|
|
278
|
-
const indexStatus = entry.xy[0];
|
|
279
|
-
const workdirStatus = entry.xy[1];
|
|
280
|
-
if (indexStatus !== undefined && workdirStatus !== undefined) {
|
|
281
|
-
entries.push({
|
|
282
|
-
path: entry.path,
|
|
283
|
-
index: indexStatus,
|
|
284
|
-
workdir: workdirStatus,
|
|
285
|
-
});
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
else if (line.startsWith('? ')) {
|
|
290
|
-
// Untracked
|
|
291
|
-
entries.push({
|
|
292
|
-
path: line.slice(2),
|
|
293
|
-
index: '?',
|
|
294
|
-
workdir: '?',
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
else if (line.startsWith('! ')) {
|
|
298
|
-
// Ignored
|
|
299
|
-
entries.push({
|
|
300
|
-
path: line.slice(2),
|
|
301
|
-
index: '!',
|
|
302
|
-
workdir: '!',
|
|
303
|
-
});
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
return {
|
|
307
|
-
entries,
|
|
308
|
-
branch,
|
|
309
|
-
upstream,
|
|
310
|
-
ahead,
|
|
311
|
-
behind,
|
|
312
|
-
};
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Get commit log
|
|
316
|
-
*/
|
|
317
|
-
async log(opts) {
|
|
318
|
-
const args = ['log', `--format=${GIT_LOG_FORMAT}`];
|
|
319
|
-
if (opts?.maxCount !== undefined) {
|
|
320
|
-
args.push(`-n${opts.maxCount}`);
|
|
321
|
-
}
|
|
322
|
-
if (opts?.skip !== undefined) {
|
|
323
|
-
args.push(`--skip=${opts.skip}`);
|
|
324
|
-
}
|
|
325
|
-
// Date filters (since/after and until/before are aliases)
|
|
326
|
-
if (opts?.since) {
|
|
327
|
-
const since = opts.since instanceof Date ? opts.since.toISOString() : opts.since;
|
|
328
|
-
args.push(`--since=${since}`);
|
|
329
|
-
}
|
|
330
|
-
else if (opts?.after) {
|
|
331
|
-
const after = opts.after instanceof Date ? opts.after.toISOString() : opts.after;
|
|
332
|
-
args.push(`--after=${after}`);
|
|
333
|
-
}
|
|
334
|
-
if (opts?.until) {
|
|
335
|
-
const until = opts.until instanceof Date ? opts.until.toISOString() : opts.until;
|
|
336
|
-
args.push(`--until=${until}`);
|
|
337
|
-
}
|
|
338
|
-
else if (opts?.before) {
|
|
339
|
-
const before = opts.before instanceof Date ? opts.before.toISOString() : opts.before;
|
|
340
|
-
args.push(`--before=${before}`);
|
|
341
|
-
}
|
|
342
|
-
if (opts?.author) {
|
|
343
|
-
args.push(`--author=${opts.author}`);
|
|
344
|
-
}
|
|
345
|
-
if (opts?.grep) {
|
|
346
|
-
args.push(`--grep=${opts.grep}`);
|
|
347
|
-
}
|
|
348
|
-
if (opts?.all) {
|
|
349
|
-
args.push('--all');
|
|
350
|
-
}
|
|
351
|
-
if (opts?.firstParent) {
|
|
352
|
-
args.push('--first-parent');
|
|
353
|
-
}
|
|
354
|
-
// New options
|
|
355
|
-
if (opts?.source) {
|
|
356
|
-
args.push('--source');
|
|
357
|
-
}
|
|
358
|
-
if (opts?.useMailmap) {
|
|
359
|
-
args.push('--use-mailmap');
|
|
360
|
-
}
|
|
361
|
-
if (opts?.decorateRefs) {
|
|
362
|
-
args.push(`--decorate-refs=${opts.decorateRefs}`);
|
|
363
|
-
}
|
|
364
|
-
if (opts?.decorateRefsExclude) {
|
|
365
|
-
args.push(`--decorate-refs-exclude=${opts.decorateRefsExclude}`);
|
|
366
|
-
}
|
|
367
|
-
if (opts?.decorate) {
|
|
368
|
-
args.push(`--decorate=${opts.decorate}`);
|
|
369
|
-
}
|
|
370
|
-
if (opts?.stat) {
|
|
371
|
-
args.push('--stat');
|
|
372
|
-
}
|
|
373
|
-
if (opts?.shortstat) {
|
|
374
|
-
args.push('--shortstat');
|
|
375
|
-
}
|
|
376
|
-
if (opts?.nameOnly) {
|
|
377
|
-
args.push('--name-only');
|
|
378
|
-
}
|
|
379
|
-
if (opts?.nameStatus) {
|
|
380
|
-
args.push('--name-status');
|
|
381
|
-
}
|
|
382
|
-
if (opts?.merges) {
|
|
383
|
-
args.push('--merges');
|
|
384
|
-
}
|
|
385
|
-
if (opts?.noMerges) {
|
|
386
|
-
args.push('--no-merges');
|
|
387
|
-
}
|
|
388
|
-
if (opts?.ancestryPath) {
|
|
389
|
-
args.push('--ancestry-path');
|
|
390
|
-
}
|
|
391
|
-
if (opts?.reverse) {
|
|
392
|
-
args.push('--reverse');
|
|
393
|
-
}
|
|
394
|
-
// ref must be placed after all options (positional argument)
|
|
395
|
-
if (opts?.ref) {
|
|
396
|
-
args.push(opts.ref);
|
|
397
|
-
}
|
|
398
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
399
|
-
signal: opts?.signal,
|
|
400
|
-
});
|
|
401
|
-
const parsed = parseGitLog(result.stdout);
|
|
402
|
-
return parsed.map((p) => ({
|
|
403
|
-
hash: p.hash,
|
|
404
|
-
abbrevHash: p.abbrevHash,
|
|
405
|
-
parents: p.parents,
|
|
406
|
-
author: {
|
|
407
|
-
name: p.authorName,
|
|
408
|
-
email: p.authorEmail,
|
|
409
|
-
timestamp: p.authorTimestamp,
|
|
410
|
-
},
|
|
411
|
-
committer: {
|
|
412
|
-
name: p.committerName,
|
|
413
|
-
email: p.committerEmail,
|
|
414
|
-
timestamp: p.committerTimestamp,
|
|
415
|
-
},
|
|
416
|
-
subject: p.subject,
|
|
417
|
-
body: p.body,
|
|
418
|
-
}));
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Fetch from remote
|
|
422
|
-
*/
|
|
423
|
-
async fetch(opts) {
|
|
424
|
-
const args = ['fetch'];
|
|
425
|
-
// Progress tracking
|
|
426
|
-
if (opts?.onProgress) {
|
|
427
|
-
args.push('--progress');
|
|
428
|
-
}
|
|
429
|
-
// Verbosity options
|
|
430
|
-
if (opts?.verbose) {
|
|
431
|
-
args.push('--verbose');
|
|
432
|
-
}
|
|
433
|
-
if (opts?.quiet) {
|
|
434
|
-
args.push('--quiet');
|
|
435
|
-
}
|
|
436
|
-
// Fetch from all remotes
|
|
437
|
-
if (opts?.all) {
|
|
438
|
-
args.push('--all');
|
|
439
|
-
}
|
|
440
|
-
// Set upstream tracking
|
|
441
|
-
if (opts?.setUpstream) {
|
|
442
|
-
args.push('--set-upstream');
|
|
443
|
-
}
|
|
444
|
-
// Append to FETCH_HEAD
|
|
445
|
-
if (opts?.append) {
|
|
446
|
-
args.push('--append');
|
|
447
|
-
}
|
|
448
|
-
// Atomic transaction
|
|
449
|
-
if (opts?.atomic) {
|
|
450
|
-
args.push('--atomic');
|
|
451
|
-
}
|
|
452
|
-
// Force update
|
|
453
|
-
if (opts?.force) {
|
|
454
|
-
args.push('--force');
|
|
455
|
-
}
|
|
456
|
-
// Multiple remotes
|
|
457
|
-
if (opts?.multiple) {
|
|
458
|
-
args.push('--multiple');
|
|
459
|
-
}
|
|
460
|
-
// Prune options
|
|
461
|
-
if (opts?.prune) {
|
|
462
|
-
args.push('--prune');
|
|
463
|
-
}
|
|
464
|
-
if (opts?.pruneTags) {
|
|
465
|
-
args.push('--prune-tags');
|
|
466
|
-
}
|
|
467
|
-
// Tag handling
|
|
468
|
-
if (opts?.tags) {
|
|
469
|
-
args.push('--tags');
|
|
470
|
-
}
|
|
471
|
-
else if (opts?.noTags) {
|
|
472
|
-
args.push('--no-tags');
|
|
473
|
-
}
|
|
474
|
-
// Parallel jobs for submodules
|
|
475
|
-
if (opts?.jobs !== undefined) {
|
|
476
|
-
args.push(`--jobs=${opts.jobs}`);
|
|
477
|
-
}
|
|
478
|
-
// Prefetch mode
|
|
479
|
-
if (opts?.prefetch) {
|
|
480
|
-
args.push('--prefetch');
|
|
481
|
-
}
|
|
482
|
-
// Submodule recursion
|
|
483
|
-
if (opts?.recurseSubmodules !== undefined) {
|
|
484
|
-
if (opts.recurseSubmodules === true || opts.recurseSubmodules === 'yes') {
|
|
485
|
-
args.push('--recurse-submodules=yes');
|
|
486
|
-
}
|
|
487
|
-
else if (opts.recurseSubmodules === 'on-demand') {
|
|
488
|
-
args.push('--recurse-submodules=on-demand');
|
|
489
|
-
}
|
|
490
|
-
else if (opts.recurseSubmodules === 'no' || opts.recurseSubmodules === false) {
|
|
491
|
-
args.push('--recurse-submodules=no');
|
|
492
|
-
}
|
|
493
|
-
}
|
|
494
|
-
// Dry run
|
|
495
|
-
if (opts?.dryRun) {
|
|
496
|
-
args.push('--dry-run');
|
|
497
|
-
}
|
|
498
|
-
// FETCH_HEAD writing
|
|
499
|
-
if (opts?.writeFetchHead === false) {
|
|
500
|
-
args.push('--no-write-fetch-head');
|
|
501
|
-
}
|
|
502
|
-
// Keep downloaded pack
|
|
503
|
-
if (opts?.keep) {
|
|
504
|
-
args.push('--keep');
|
|
505
|
-
}
|
|
506
|
-
// Update head
|
|
507
|
-
if (opts?.updateHeadOk) {
|
|
508
|
-
args.push('--update-head-ok');
|
|
509
|
-
}
|
|
510
|
-
// Shallow clone options
|
|
511
|
-
if (opts?.depth !== undefined) {
|
|
512
|
-
args.push(`--depth=${opts.depth}`);
|
|
513
|
-
}
|
|
514
|
-
if (opts?.shallowSince) {
|
|
515
|
-
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
516
|
-
args.push(`--shallow-since=${since}`);
|
|
517
|
-
}
|
|
518
|
-
if (opts?.shallowExclude) {
|
|
519
|
-
const excludes = Array.isArray(opts.shallowExclude)
|
|
520
|
-
? opts.shallowExclude
|
|
521
|
-
: [opts.shallowExclude];
|
|
522
|
-
for (const exclude of excludes) {
|
|
523
|
-
args.push(`--shallow-exclude=${exclude}`);
|
|
524
|
-
}
|
|
525
|
-
}
|
|
526
|
-
if (opts?.deepen !== undefined) {
|
|
527
|
-
args.push(`--deepen=${opts.deepen}`);
|
|
528
|
-
}
|
|
529
|
-
if (opts?.unshallow) {
|
|
530
|
-
args.push('--unshallow');
|
|
531
|
-
}
|
|
532
|
-
// Refetch all objects
|
|
533
|
-
if (opts?.refetch) {
|
|
534
|
-
args.push('--refetch');
|
|
535
|
-
}
|
|
536
|
-
// Update shallow boundary
|
|
537
|
-
if (opts?.updateShallow) {
|
|
538
|
-
args.push('--update-shallow');
|
|
539
|
-
}
|
|
540
|
-
// Refmap override
|
|
541
|
-
if (opts?.refmap) {
|
|
542
|
-
args.push(`--refmap=${opts.refmap}`);
|
|
543
|
-
}
|
|
544
|
-
// Network options
|
|
545
|
-
if (opts?.ipv4) {
|
|
546
|
-
args.push('--ipv4');
|
|
547
|
-
}
|
|
548
|
-
if (opts?.ipv6) {
|
|
549
|
-
args.push('--ipv6');
|
|
550
|
-
}
|
|
551
|
-
// Partial clone filter
|
|
552
|
-
if (opts?.filter) {
|
|
553
|
-
args.push(`--filter=${opts.filter}`);
|
|
554
|
-
}
|
|
555
|
-
// Show forced updates
|
|
556
|
-
if (opts?.showForcedUpdates === false) {
|
|
557
|
-
args.push('--no-show-forced-updates');
|
|
558
|
-
}
|
|
559
|
-
// Write commit graph
|
|
560
|
-
if (opts?.writeCommitGraph) {
|
|
561
|
-
args.push('--write-commit-graph');
|
|
562
|
-
}
|
|
563
|
-
// Remote and refspec (must be last)
|
|
564
|
-
if (opts?.remote) {
|
|
565
|
-
args.push(opts.remote);
|
|
566
|
-
}
|
|
567
|
-
if (opts?.refspec) {
|
|
568
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
569
|
-
args.push(...refspecs);
|
|
570
|
-
}
|
|
571
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
572
|
-
signal: opts?.signal,
|
|
573
|
-
onProgress: opts?.onProgress,
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Push to remote
|
|
578
|
-
*/
|
|
579
|
-
async push(opts) {
|
|
580
|
-
const args = ['push'];
|
|
581
|
-
// Progress tracking
|
|
582
|
-
if (opts?.onProgress) {
|
|
583
|
-
args.push('--progress');
|
|
584
|
-
}
|
|
585
|
-
// Verbosity options
|
|
586
|
-
if (opts?.verbose) {
|
|
587
|
-
args.push('--verbose');
|
|
588
|
-
}
|
|
589
|
-
if (opts?.quiet) {
|
|
590
|
-
args.push('--quiet');
|
|
591
|
-
}
|
|
592
|
-
// Repository override
|
|
593
|
-
if (opts?.repo) {
|
|
594
|
-
args.push(`--repo=${opts.repo}`);
|
|
595
|
-
}
|
|
596
|
-
// Push all branches
|
|
597
|
-
if (opts?.all) {
|
|
598
|
-
args.push('--all');
|
|
599
|
-
}
|
|
600
|
-
else if (opts?.branches) {
|
|
601
|
-
args.push('--branches');
|
|
602
|
-
}
|
|
603
|
-
// Mirror mode
|
|
604
|
-
if (opts?.mirror) {
|
|
605
|
-
args.push('--mirror');
|
|
606
|
-
}
|
|
607
|
-
// Delete refs
|
|
608
|
-
if (opts?.deleteRefs) {
|
|
609
|
-
args.push('--delete');
|
|
610
|
-
}
|
|
611
|
-
// Force options
|
|
612
|
-
if (opts?.force) {
|
|
613
|
-
args.push('--force');
|
|
614
|
-
}
|
|
615
|
-
else if (opts?.forceWithLease !== undefined && opts.forceWithLease !== false) {
|
|
616
|
-
if (opts.forceWithLease === true) {
|
|
617
|
-
args.push('--force-with-lease');
|
|
618
|
-
}
|
|
619
|
-
else {
|
|
620
|
-
// ForceWithLeaseOpts: { refname: string; expect?: string }
|
|
621
|
-
const leaseOpts = opts.forceWithLease;
|
|
622
|
-
if (leaseOpts.expect !== undefined) {
|
|
623
|
-
args.push(`--force-with-lease=${leaseOpts.refname}:${leaseOpts.expect}`);
|
|
624
|
-
}
|
|
625
|
-
else {
|
|
626
|
-
args.push(`--force-with-lease=${leaseOpts.refname}`);
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
if (opts?.forceIfIncludes) {
|
|
631
|
-
args.push('--force-if-includes');
|
|
632
|
-
}
|
|
633
|
-
// Dry run
|
|
634
|
-
if (opts?.dryRun) {
|
|
635
|
-
args.push('--dry-run');
|
|
636
|
-
}
|
|
637
|
-
// Submodule recursion
|
|
638
|
-
if (opts?.recurseSubmodules) {
|
|
639
|
-
args.push(`--recurse-submodules=${opts.recurseSubmodules}`);
|
|
640
|
-
}
|
|
641
|
-
// Thin pack
|
|
642
|
-
if (opts?.thin === false) {
|
|
643
|
-
args.push('--no-thin');
|
|
644
|
-
}
|
|
645
|
-
// Prune remote-tracking branches
|
|
646
|
-
if (opts?.prune) {
|
|
647
|
-
args.push('--prune');
|
|
648
|
-
}
|
|
649
|
-
// Tag handling
|
|
650
|
-
if (opts?.tags) {
|
|
651
|
-
args.push('--tags');
|
|
652
|
-
}
|
|
653
|
-
if (opts?.followTags) {
|
|
654
|
-
args.push('--follow-tags');
|
|
655
|
-
}
|
|
656
|
-
// Atomic transaction
|
|
657
|
-
if (opts?.atomic) {
|
|
658
|
-
args.push('--atomic');
|
|
659
|
-
}
|
|
660
|
-
// Push options
|
|
661
|
-
if (opts?.pushOption) {
|
|
662
|
-
const pushOptions = Array.isArray(opts.pushOption) ? opts.pushOption : [opts.pushOption];
|
|
663
|
-
for (const opt of pushOptions) {
|
|
664
|
-
args.push('--push-option', opt);
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
// Set upstream tracking
|
|
668
|
-
if (opts?.setUpstream) {
|
|
669
|
-
args.push('--set-upstream');
|
|
670
|
-
}
|
|
671
|
-
// Bypass pre-push hook
|
|
672
|
-
if (opts?.noVerify) {
|
|
673
|
-
args.push('--no-verify');
|
|
674
|
-
}
|
|
675
|
-
// GPG signing
|
|
676
|
-
if (opts?.signed !== undefined) {
|
|
677
|
-
if (opts.signed === true) {
|
|
678
|
-
args.push('--signed');
|
|
679
|
-
}
|
|
680
|
-
else if (opts.signed === 'if-asked') {
|
|
681
|
-
args.push('--signed=if-asked');
|
|
682
|
-
}
|
|
683
|
-
}
|
|
684
|
-
// Network options
|
|
685
|
-
if (opts?.ipv4) {
|
|
686
|
-
args.push('--ipv4');
|
|
687
|
-
}
|
|
688
|
-
if (opts?.ipv6) {
|
|
689
|
-
args.push('--ipv6');
|
|
690
|
-
}
|
|
691
|
-
// Remote and refspec (must be last)
|
|
692
|
-
if (opts?.remote) {
|
|
693
|
-
args.push(opts.remote);
|
|
694
|
-
}
|
|
695
|
-
if (opts?.refspec) {
|
|
696
|
-
const refspecs = Array.isArray(opts.refspec) ? opts.refspec : [opts.refspec];
|
|
697
|
-
args.push(...refspecs);
|
|
698
|
-
}
|
|
699
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
700
|
-
signal: opts?.signal,
|
|
701
|
-
onProgress: opts?.onProgress,
|
|
702
|
-
});
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* Configure LFS mode for this repository
|
|
706
|
-
*/
|
|
707
|
-
setLfsMode(mode) {
|
|
708
|
-
this._lfsMode = mode;
|
|
709
|
-
}
|
|
710
|
-
// ==========================================================================
|
|
711
|
-
// LFS Operations
|
|
712
|
-
// ==========================================================================
|
|
713
|
-
async lfsPull(opts) {
|
|
714
|
-
if (this._lfsMode === 'disabled') {
|
|
715
|
-
return;
|
|
716
|
-
}
|
|
717
|
-
const args = ['lfs', 'pull'];
|
|
718
|
-
if (opts?.remote) {
|
|
719
|
-
args.push(opts.remote);
|
|
720
|
-
}
|
|
721
|
-
if (opts?.ref) {
|
|
722
|
-
args.push(opts.ref);
|
|
723
|
-
}
|
|
724
|
-
if (opts?.include && opts.include.length > 0) {
|
|
725
|
-
args.push('--include', opts.include.join(','));
|
|
726
|
-
}
|
|
727
|
-
if (opts?.exclude && opts.exclude.length > 0) {
|
|
728
|
-
args.push('--exclude', opts.exclude.join(','));
|
|
729
|
-
}
|
|
730
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
731
|
-
signal: opts?.signal,
|
|
732
|
-
onProgress: opts?.onProgress,
|
|
733
|
-
});
|
|
734
|
-
}
|
|
735
|
-
async lfsPush(opts) {
|
|
736
|
-
if (this._lfsMode === 'disabled') {
|
|
737
|
-
return;
|
|
738
|
-
}
|
|
739
|
-
const args = ['lfs', 'push'];
|
|
740
|
-
if (opts?.dryRun) {
|
|
741
|
-
args.push('--dry-run');
|
|
742
|
-
}
|
|
743
|
-
if (opts?.objectId) {
|
|
744
|
-
const oids = Array.isArray(opts.objectId) ? opts.objectId : [opts.objectId];
|
|
745
|
-
for (const oid of oids) {
|
|
746
|
-
args.push('--object-id', oid);
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
else {
|
|
750
|
-
// Default to --all if not pushing specific objects
|
|
751
|
-
args.push('--all');
|
|
752
|
-
}
|
|
753
|
-
if (opts?.remote) {
|
|
754
|
-
args.push(opts.remote);
|
|
755
|
-
}
|
|
756
|
-
else {
|
|
757
|
-
args.push('origin');
|
|
758
|
-
}
|
|
759
|
-
if (opts?.ref) {
|
|
760
|
-
args.push(opts.ref);
|
|
761
|
-
}
|
|
762
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
763
|
-
signal: opts?.signal,
|
|
764
|
-
onProgress: opts?.onProgress,
|
|
765
|
-
});
|
|
766
|
-
}
|
|
767
|
-
async lfsStatus(opts) {
|
|
768
|
-
const args = ['lfs', 'status'];
|
|
769
|
-
if (opts?.json) {
|
|
770
|
-
args.push('--json');
|
|
771
|
-
}
|
|
772
|
-
if (opts?.porcelain) {
|
|
773
|
-
args.push('--porcelain');
|
|
774
|
-
}
|
|
775
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
776
|
-
signal: opts?.signal,
|
|
777
|
-
});
|
|
778
|
-
// Parse LFS status output
|
|
779
|
-
// For now, return a simplified version
|
|
780
|
-
const files = [];
|
|
781
|
-
if (opts?.json) {
|
|
782
|
-
try {
|
|
783
|
-
const json = JSON.parse(result.stdout);
|
|
784
|
-
// Process JSON output
|
|
785
|
-
if (json.files) {
|
|
786
|
-
for (const [name, info] of Object.entries(json.files)) {
|
|
787
|
-
files.push({
|
|
788
|
-
name,
|
|
789
|
-
size: info.size ?? 0,
|
|
790
|
-
status: 'unknown',
|
|
791
|
-
});
|
|
792
|
-
}
|
|
793
|
-
}
|
|
794
|
-
}
|
|
795
|
-
catch {
|
|
796
|
-
// Fallback to text parsing
|
|
797
|
-
}
|
|
798
|
-
}
|
|
799
|
-
return { files };
|
|
800
|
-
}
|
|
801
|
-
/**
|
|
802
|
-
* Pre-upload LFS objects before commit/push (2-phase commit pattern)
|
|
803
|
-
*
|
|
804
|
-
* This allows uploading LFS objects to the remote before creating a commit,
|
|
805
|
-
* ensuring reliable large file handling. Objects are batched to handle
|
|
806
|
-
* Windows command line length limits (8KB).
|
|
807
|
-
*
|
|
808
|
-
* Usage pattern:
|
|
809
|
-
* 1. Stage changes: git add
|
|
810
|
-
* 2. Pre-upload LFS: await repo.lfs.preUpload()
|
|
811
|
-
* 3. Commit: git commit
|
|
812
|
-
* 4. Push refs: git push (only refs, objects already uploaded)
|
|
813
|
-
*/
|
|
814
|
-
async lfsPreUpload(opts) {
|
|
815
|
-
if (this._lfsMode === 'disabled') {
|
|
816
|
-
return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
|
|
817
|
-
}
|
|
818
|
-
const remote = opts?.remote ?? 'origin';
|
|
819
|
-
const batchSize = opts?.batchSize ?? 50; // Default 50 OIDs per batch (Windows 8KB limit)
|
|
820
|
-
// Get OIDs to upload
|
|
821
|
-
let oids;
|
|
822
|
-
if (opts?.oids && opts.oids.length > 0) {
|
|
823
|
-
oids = opts.oids;
|
|
824
|
-
}
|
|
825
|
-
else {
|
|
826
|
-
// Get all LFS objects that need to be pushed
|
|
827
|
-
const lsFilesResult = await this.runner.run(this.context, ['lfs', 'ls-files', '--all', '--long'], { signal: opts?.signal });
|
|
828
|
-
if (lsFilesResult.exitCode !== 0) {
|
|
829
|
-
return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
|
|
830
|
-
}
|
|
831
|
-
// Parse OIDs from ls-files output (format: <oid> [-|*] <path>)
|
|
832
|
-
oids = [];
|
|
833
|
-
for (const line of parseLines(lsFilesResult.stdout)) {
|
|
834
|
-
const match = line.match(/^([a-f0-9]{64})\s+[-*]\s+/);
|
|
835
|
-
const oid = match?.[1];
|
|
836
|
-
if (oid !== undefined) {
|
|
837
|
-
oids.push(oid);
|
|
838
|
-
}
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
if (oids.length === 0) {
|
|
842
|
-
return { uploadedCount: 0, uploadedBytes: 0, skippedCount: 0 };
|
|
843
|
-
}
|
|
844
|
-
// Process in batches
|
|
845
|
-
let uploadedCount = 0;
|
|
846
|
-
let uploadedBytes = 0;
|
|
847
|
-
let skippedCount = 0;
|
|
848
|
-
for (let i = 0; i < oids.length; i += batchSize) {
|
|
849
|
-
const batch = oids.slice(i, i + batchSize);
|
|
850
|
-
const args = ['lfs', 'push', remote, '--object-id', ...batch];
|
|
851
|
-
const result = await this.runner.run(this.context, args, {
|
|
852
|
-
signal: opts?.signal,
|
|
853
|
-
onProgress: opts?.onProgress,
|
|
854
|
-
});
|
|
855
|
-
if (result.exitCode === 0) {
|
|
856
|
-
// Parse upload stats from output if available
|
|
857
|
-
uploadedCount += batch.length;
|
|
858
|
-
// Try to extract bytes from progress output
|
|
859
|
-
const bytesMatch = result.stderr.match(/Uploading LFS objects:.*?\((\d+(?:\.\d+)?)\s*([KMG]?B)/i);
|
|
860
|
-
const bytesStr = bytesMatch?.[1];
|
|
861
|
-
if (bytesStr !== undefined) {
|
|
862
|
-
let bytes = Number.parseFloat(bytesStr);
|
|
863
|
-
const unit = bytesMatch?.[2]?.toUpperCase();
|
|
864
|
-
if (unit === 'KB') {
|
|
865
|
-
bytes *= 1024;
|
|
866
|
-
}
|
|
867
|
-
else if (unit === 'MB') {
|
|
868
|
-
bytes *= 1024 * 1024;
|
|
869
|
-
}
|
|
870
|
-
else if (unit === 'GB') {
|
|
871
|
-
bytes *= 1024 * 1024 * 1024;
|
|
872
|
-
}
|
|
873
|
-
uploadedBytes += bytes;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
else {
|
|
877
|
-
// Some objects may have been skipped (already on remote)
|
|
878
|
-
skippedCount += batch.length;
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
return { uploadedCount, uploadedBytes, skippedCount };
|
|
882
|
-
}
|
|
883
|
-
/**
|
|
884
|
-
* Pre-download LFS objects before checkout (2-phase fetch pattern)
|
|
885
|
-
*
|
|
886
|
-
* This allows downloading LFS objects before switching branches,
|
|
887
|
-
* ensuring files are available locally before checkout.
|
|
888
|
-
*
|
|
889
|
-
* Usage pattern:
|
|
890
|
-
* 1. Fetch refs: git fetch
|
|
891
|
-
* 2. Pre-download LFS: await repo.lfs.preDownload({ ref: 'origin/feature' })
|
|
892
|
-
* 3. Checkout: git checkout feature
|
|
893
|
-
*/
|
|
894
|
-
async lfsPreDownload(opts) {
|
|
895
|
-
if (this._lfsMode === 'disabled') {
|
|
896
|
-
return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
|
|
897
|
-
}
|
|
898
|
-
const remote = opts?.remote ?? 'origin';
|
|
899
|
-
const batchSize = opts?.batchSize ?? 50;
|
|
900
|
-
// Get OIDs to download
|
|
901
|
-
let oids;
|
|
902
|
-
if (opts?.oids && opts.oids.length > 0) {
|
|
903
|
-
oids = opts.oids;
|
|
904
|
-
}
|
|
905
|
-
else if (opts?.ref) {
|
|
906
|
-
// Get LFS objects for a specific ref
|
|
907
|
-
const lsFilesResult = await this.runner.run(this.context, ['lfs', 'ls-files', '--long', opts.ref], { signal: opts?.signal });
|
|
908
|
-
if (lsFilesResult.exitCode !== 0) {
|
|
909
|
-
return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
|
|
910
|
-
}
|
|
911
|
-
// Parse OIDs from ls-files output
|
|
912
|
-
oids = [];
|
|
913
|
-
for (const line of parseLines(lsFilesResult.stdout)) {
|
|
914
|
-
const match = line.match(/^([a-f0-9]{64})\s+[-*]\s+/);
|
|
915
|
-
const oid = match?.[1];
|
|
916
|
-
if (oid !== undefined) {
|
|
917
|
-
oids.push(oid);
|
|
918
|
-
}
|
|
919
|
-
}
|
|
920
|
-
}
|
|
921
|
-
else {
|
|
922
|
-
// No ref specified and no OIDs provided
|
|
923
|
-
return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
|
|
924
|
-
}
|
|
925
|
-
if (oids.length === 0) {
|
|
926
|
-
return { downloadedCount: 0, downloadedBytes: 0, skippedCount: 0 };
|
|
927
|
-
}
|
|
928
|
-
// Process in batches
|
|
929
|
-
let downloadedCount = 0;
|
|
930
|
-
let downloadedBytes = 0;
|
|
931
|
-
let skippedCount = 0;
|
|
932
|
-
for (let i = 0; i < oids.length; i += batchSize) {
|
|
933
|
-
const batch = oids.slice(i, i + batchSize);
|
|
934
|
-
const args = ['lfs', 'fetch', remote, '--', ...batch];
|
|
935
|
-
const result = await this.runner.run(this.context, args, {
|
|
936
|
-
signal: opts?.signal,
|
|
937
|
-
onProgress: opts?.onProgress,
|
|
938
|
-
});
|
|
939
|
-
if (result.exitCode === 0) {
|
|
940
|
-
downloadedCount += batch.length;
|
|
941
|
-
// Try to extract bytes from progress output
|
|
942
|
-
const bytesMatch = result.stderr.match(/Downloading LFS objects:.*?\((\d+(?:\.\d+)?)\s*([KMG]?B)/i);
|
|
943
|
-
const bytesStr = bytesMatch?.[1];
|
|
944
|
-
if (bytesStr !== undefined) {
|
|
945
|
-
let bytes = Number.parseFloat(bytesStr);
|
|
946
|
-
const unit = bytesMatch?.[2]?.toUpperCase();
|
|
947
|
-
if (unit === 'KB') {
|
|
948
|
-
bytes *= 1024;
|
|
949
|
-
}
|
|
950
|
-
else if (unit === 'MB') {
|
|
951
|
-
bytes *= 1024 * 1024;
|
|
952
|
-
}
|
|
953
|
-
else if (unit === 'GB') {
|
|
954
|
-
bytes *= 1024 * 1024 * 1024;
|
|
955
|
-
}
|
|
956
|
-
downloadedBytes += bytes;
|
|
957
|
-
}
|
|
958
|
-
}
|
|
959
|
-
else {
|
|
960
|
-
skippedCount += batch.length;
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
return { downloadedCount, downloadedBytes, skippedCount };
|
|
964
|
-
}
|
|
965
|
-
/**
|
|
966
|
-
* Prune old and unreferenced LFS objects from local storage
|
|
967
|
-
*/
|
|
968
|
-
async lfsPrune(opts) {
|
|
969
|
-
if (this._lfsMode === 'disabled') {
|
|
970
|
-
return;
|
|
971
|
-
}
|
|
972
|
-
const args = ['lfs', 'prune'];
|
|
973
|
-
if (opts?.force) {
|
|
974
|
-
args.push('--force');
|
|
975
|
-
}
|
|
976
|
-
if (opts?.dryRun) {
|
|
977
|
-
args.push('--dry-run');
|
|
978
|
-
}
|
|
979
|
-
if (opts?.verifyRemote) {
|
|
980
|
-
args.push('--verify-remote');
|
|
981
|
-
}
|
|
982
|
-
if (opts?.verifyUnreferenced) {
|
|
983
|
-
args.push('--verify-unreferenced');
|
|
984
|
-
}
|
|
985
|
-
if (opts?.recent) {
|
|
986
|
-
args.push('--recent');
|
|
987
|
-
}
|
|
988
|
-
if (opts?.verbose) {
|
|
989
|
-
args.push('--verbose');
|
|
990
|
-
}
|
|
991
|
-
if (opts?.whenUnverified) {
|
|
992
|
-
args.push(`--when-unverified=${opts.whenUnverified}`);
|
|
993
|
-
}
|
|
994
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
995
|
-
signal: opts?.signal,
|
|
996
|
-
onProgress: opts?.onProgress,
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
async lfsFetch(opts) {
|
|
1000
|
-
if (this._lfsMode === 'disabled') {
|
|
1001
|
-
return;
|
|
1002
|
-
}
|
|
1003
|
-
const args = ['lfs', 'fetch'];
|
|
1004
|
-
if (opts?.onProgress) {
|
|
1005
|
-
args.push('--progress');
|
|
1006
|
-
}
|
|
1007
|
-
if (opts?.all) {
|
|
1008
|
-
args.push('--all');
|
|
1009
|
-
}
|
|
1010
|
-
if (opts?.prune) {
|
|
1011
|
-
args.push('--prune');
|
|
1012
|
-
}
|
|
1013
|
-
if (opts?.recent) {
|
|
1014
|
-
args.push('--recent');
|
|
1015
|
-
}
|
|
1016
|
-
if (opts?.include) {
|
|
1017
|
-
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
1018
|
-
for (const pattern of patterns) {
|
|
1019
|
-
args.push('--include', pattern);
|
|
1020
|
-
}
|
|
1021
|
-
}
|
|
1022
|
-
if (opts?.exclude) {
|
|
1023
|
-
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
1024
|
-
for (const pattern of patterns) {
|
|
1025
|
-
args.push('--exclude', pattern);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
if (opts?.remote) {
|
|
1029
|
-
args.push(opts.remote);
|
|
1030
|
-
}
|
|
1031
|
-
if (opts?.refs) {
|
|
1032
|
-
const refList = Array.isArray(opts.refs) ? opts.refs : [opts.refs];
|
|
1033
|
-
args.push(...refList);
|
|
1034
|
-
}
|
|
1035
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1036
|
-
signal: opts?.signal,
|
|
1037
|
-
onProgress: opts?.onProgress,
|
|
1038
|
-
});
|
|
1039
|
-
}
|
|
1040
|
-
async lfsInstall(opts) {
|
|
1041
|
-
const args = ['lfs', 'install'];
|
|
1042
|
-
if (opts?.force) {
|
|
1043
|
-
args.push('--force');
|
|
1044
|
-
}
|
|
1045
|
-
// Use --worktree if specified, otherwise default to --local
|
|
1046
|
-
if (opts?.worktree) {
|
|
1047
|
-
args.push('--worktree');
|
|
1048
|
-
}
|
|
1049
|
-
else {
|
|
1050
|
-
args.push('--local');
|
|
1051
|
-
}
|
|
1052
|
-
if (opts?.skipSmudge) {
|
|
1053
|
-
args.push('--skip-smudge');
|
|
1054
|
-
}
|
|
1055
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1056
|
-
signal: opts?.signal,
|
|
1057
|
-
});
|
|
1058
|
-
}
|
|
1059
|
-
async lfsUninstall(opts) {
|
|
1060
|
-
const args = ['lfs', 'uninstall'];
|
|
1061
|
-
// Use --worktree if specified, otherwise default to --local
|
|
1062
|
-
if (opts?.worktree) {
|
|
1063
|
-
args.push('--worktree');
|
|
1064
|
-
}
|
|
1065
|
-
else {
|
|
1066
|
-
args.push('--local');
|
|
1067
|
-
}
|
|
1068
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1069
|
-
signal: opts?.signal,
|
|
1070
|
-
});
|
|
1071
|
-
}
|
|
1072
|
-
async lfsLsFiles(opts) {
|
|
1073
|
-
if (this._lfsMode === 'disabled') {
|
|
1074
|
-
return [];
|
|
1075
|
-
}
|
|
1076
|
-
const args = ['lfs', 'ls-files'];
|
|
1077
|
-
if (opts?.long) {
|
|
1078
|
-
args.push('--long');
|
|
1079
|
-
}
|
|
1080
|
-
// biome-ignore lint/style/useExplicitLengthCheck: size is a boolean option, not a length property
|
|
1081
|
-
if (opts?.size) {
|
|
1082
|
-
args.push('--size');
|
|
1083
|
-
}
|
|
1084
|
-
if (opts?.debug) {
|
|
1085
|
-
args.push('--debug');
|
|
1086
|
-
}
|
|
1087
|
-
if (opts?.all) {
|
|
1088
|
-
args.push('--all');
|
|
1089
|
-
}
|
|
1090
|
-
if (opts?.deleted) {
|
|
1091
|
-
args.push('--deleted');
|
|
1092
|
-
}
|
|
1093
|
-
if (opts?.include) {
|
|
1094
|
-
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
1095
|
-
for (const pattern of patterns) {
|
|
1096
|
-
args.push('--include', pattern);
|
|
1097
|
-
}
|
|
1098
|
-
}
|
|
1099
|
-
if (opts?.exclude) {
|
|
1100
|
-
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
1101
|
-
for (const pattern of patterns) {
|
|
1102
|
-
args.push('--exclude', pattern);
|
|
1103
|
-
}
|
|
1104
|
-
}
|
|
1105
|
-
if (opts?.ref) {
|
|
1106
|
-
args.push(opts.ref);
|
|
1107
|
-
}
|
|
1108
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1109
|
-
signal: opts?.signal,
|
|
1110
|
-
});
|
|
1111
|
-
const entries = [];
|
|
1112
|
-
for (const line of parseLines(result.stdout)) {
|
|
1113
|
-
// Format: <oid> <status> <filename> [size]
|
|
1114
|
-
// Status: - (not checked out), * (checked out)
|
|
1115
|
-
const match = line.match(/^([0-9a-f]+)\s+([-*])\s+(.+?)(?:\s+\((\d+)\s*(?:B|bytes)?\))?$/);
|
|
1116
|
-
if (match) {
|
|
1117
|
-
entries.push({
|
|
1118
|
-
oid: match[1],
|
|
1119
|
-
path: match[3],
|
|
1120
|
-
size: match[4] ? Number.parseInt(match[4], 10) : undefined,
|
|
1121
|
-
status: match[2] === '*' ? 'checked-out' : 'not-checked-out',
|
|
1122
|
-
});
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
return entries;
|
|
1126
|
-
}
|
|
1127
|
-
async lfsTrack(patterns, opts) {
|
|
1128
|
-
const args = ['lfs', 'track'];
|
|
1129
|
-
if (opts?.verbose) {
|
|
1130
|
-
args.push('--verbose');
|
|
1131
|
-
}
|
|
1132
|
-
if (opts?.dryRun) {
|
|
1133
|
-
args.push('--dry-run');
|
|
1134
|
-
}
|
|
1135
|
-
if (opts?.lockable) {
|
|
1136
|
-
args.push('--lockable');
|
|
1137
|
-
}
|
|
1138
|
-
if (opts?.noModifyAttrs) {
|
|
1139
|
-
args.push('--no-modify-attrs');
|
|
1140
|
-
}
|
|
1141
|
-
if (opts?.noExcluded) {
|
|
1142
|
-
args.push('--no-excluded');
|
|
1143
|
-
}
|
|
1144
|
-
const patternList = Array.isArray(patterns) ? patterns : [patterns];
|
|
1145
|
-
args.push(...patternList);
|
|
1146
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1147
|
-
signal: opts?.signal,
|
|
1148
|
-
});
|
|
1149
|
-
}
|
|
1150
|
-
async lfsTrackList(opts) {
|
|
1151
|
-
if (this._lfsMode === 'disabled') {
|
|
1152
|
-
return [];
|
|
1153
|
-
}
|
|
1154
|
-
const result = await this.runner.runOrThrow(this.context, ['lfs', 'track'], {
|
|
1155
|
-
signal: opts?.signal,
|
|
1156
|
-
});
|
|
1157
|
-
const entries = [];
|
|
1158
|
-
for (const line of parseLines(result.stdout)) {
|
|
1159
|
-
// Format: "Listing tracked patterns\n *.psd (.gitattributes)\n *.bin (.gitattributes) [lockable]"
|
|
1160
|
-
const match = line.match(/^\s+(\S+)\s+\(([^)]+)\)(?:\s+\[lockable\])?$/);
|
|
1161
|
-
if (match) {
|
|
1162
|
-
entries.push({
|
|
1163
|
-
pattern: match[1],
|
|
1164
|
-
source: match[2],
|
|
1165
|
-
lockable: line.includes('[lockable]'),
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
}
|
|
1169
|
-
return entries;
|
|
1170
|
-
}
|
|
1171
|
-
async lfsUntrack(patterns, opts) {
|
|
1172
|
-
const args = ['lfs', 'untrack'];
|
|
1173
|
-
const patternList = Array.isArray(patterns) ? patterns : [patterns];
|
|
1174
|
-
args.push(...patternList);
|
|
1175
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1176
|
-
signal: opts?.signal,
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
async lfsLock(path, opts) {
|
|
1180
|
-
if (this._lfsMode === 'disabled') {
|
|
1181
|
-
throw new Error('LFS is disabled');
|
|
1182
|
-
}
|
|
1183
|
-
const args = ['lfs', 'lock', '--json'];
|
|
1184
|
-
if (opts?.remote) {
|
|
1185
|
-
args.push('--remote', opts.remote);
|
|
1186
|
-
}
|
|
1187
|
-
args.push(path);
|
|
1188
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1189
|
-
signal: opts?.signal,
|
|
1190
|
-
});
|
|
1191
|
-
const data = JSON.parse(result.stdout);
|
|
1192
|
-
return {
|
|
1193
|
-
id: data.id,
|
|
1194
|
-
path: data.path,
|
|
1195
|
-
owner: { name: data.owner.name },
|
|
1196
|
-
lockedAt: new Date(data.locked_at),
|
|
1197
|
-
};
|
|
1198
|
-
}
|
|
1199
|
-
async lfsUnlock(pathOrId, opts) {
|
|
1200
|
-
if (this._lfsMode === 'disabled') {
|
|
1201
|
-
return;
|
|
1202
|
-
}
|
|
1203
|
-
const args = ['lfs', 'unlock'];
|
|
1204
|
-
if (opts?.id) {
|
|
1205
|
-
args.push('--id');
|
|
1206
|
-
}
|
|
1207
|
-
if (opts?.force) {
|
|
1208
|
-
args.push('--force');
|
|
1209
|
-
}
|
|
1210
|
-
if (opts?.remote) {
|
|
1211
|
-
args.push('--remote', opts.remote);
|
|
1212
|
-
}
|
|
1213
|
-
args.push(pathOrId);
|
|
1214
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1215
|
-
signal: opts?.signal,
|
|
1216
|
-
});
|
|
1217
|
-
}
|
|
1218
|
-
async lfsLocks(opts) {
|
|
1219
|
-
if (this._lfsMode === 'disabled') {
|
|
1220
|
-
return [];
|
|
1221
|
-
}
|
|
1222
|
-
const args = ['lfs', 'locks', '--json'];
|
|
1223
|
-
if (opts?.remote) {
|
|
1224
|
-
args.push('--remote', opts.remote);
|
|
1225
|
-
}
|
|
1226
|
-
if (opts?.path) {
|
|
1227
|
-
args.push('--path', opts.path);
|
|
1228
|
-
}
|
|
1229
|
-
if (opts?.id) {
|
|
1230
|
-
args.push('--id', opts.id);
|
|
1231
|
-
}
|
|
1232
|
-
if (opts?.local) {
|
|
1233
|
-
args.push('--local');
|
|
1234
|
-
}
|
|
1235
|
-
if (opts?.cached) {
|
|
1236
|
-
args.push('--cached');
|
|
1237
|
-
}
|
|
1238
|
-
if (opts?.limit !== undefined) {
|
|
1239
|
-
args.push('--limit', String(opts.limit));
|
|
1240
|
-
}
|
|
1241
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1242
|
-
signal: opts?.signal,
|
|
1243
|
-
});
|
|
1244
|
-
const data = JSON.parse(result.stdout);
|
|
1245
|
-
return data.map((lock) => ({
|
|
1246
|
-
id: lock.id,
|
|
1247
|
-
path: lock.path,
|
|
1248
|
-
owner: { name: lock.owner.name },
|
|
1249
|
-
lockedAt: new Date(lock.locked_at),
|
|
1250
|
-
}));
|
|
1251
|
-
}
|
|
1252
|
-
async lfsCheckout(patterns, opts) {
|
|
1253
|
-
if (this._lfsMode === 'disabled') {
|
|
1254
|
-
return;
|
|
1255
|
-
}
|
|
1256
|
-
const args = ['lfs', 'checkout'];
|
|
1257
|
-
if (opts?.onProgress) {
|
|
1258
|
-
args.push('--progress');
|
|
1259
|
-
}
|
|
1260
|
-
if (opts?.include) {
|
|
1261
|
-
const includes = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
1262
|
-
for (const pattern of includes) {
|
|
1263
|
-
args.push('--include', pattern);
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
if (opts?.exclude) {
|
|
1267
|
-
const excludes = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
1268
|
-
for (const pattern of excludes) {
|
|
1269
|
-
args.push('--exclude', pattern);
|
|
1270
|
-
}
|
|
1271
|
-
}
|
|
1272
|
-
if (patterns) {
|
|
1273
|
-
const patternList = Array.isArray(patterns) ? patterns : [patterns];
|
|
1274
|
-
args.push(...patternList);
|
|
1275
|
-
}
|
|
1276
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1277
|
-
signal: opts?.signal,
|
|
1278
|
-
onProgress: opts?.onProgress,
|
|
1279
|
-
});
|
|
1280
|
-
}
|
|
1281
|
-
async lfsMigrateInfo(opts) {
|
|
1282
|
-
if (this._lfsMode === 'disabled') {
|
|
1283
|
-
return '';
|
|
1284
|
-
}
|
|
1285
|
-
const args = ['lfs', 'migrate', 'info'];
|
|
1286
|
-
this.appendMigrateArgs(args, opts);
|
|
1287
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1288
|
-
signal: opts?.signal,
|
|
1289
|
-
});
|
|
1290
|
-
return result.stdout;
|
|
1291
|
-
}
|
|
1292
|
-
async lfsMigrateImport(opts) {
|
|
1293
|
-
if (this._lfsMode === 'disabled') {
|
|
1294
|
-
return;
|
|
1295
|
-
}
|
|
1296
|
-
const args = ['lfs', 'migrate', 'import'];
|
|
1297
|
-
this.appendMigrateArgs(args, opts);
|
|
1298
|
-
if (opts?.noRewrite) {
|
|
1299
|
-
args.push('--no-rewrite');
|
|
1300
|
-
}
|
|
1301
|
-
if (opts?.object) {
|
|
1302
|
-
const objects = Array.isArray(opts.object) ? opts.object : [opts.object];
|
|
1303
|
-
for (const obj of objects) {
|
|
1304
|
-
args.push('--object', obj);
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
if (opts?.verbose) {
|
|
1308
|
-
args.push('--verbose');
|
|
1309
|
-
}
|
|
1310
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1311
|
-
signal: opts?.signal,
|
|
1312
|
-
onProgress: opts?.onProgress,
|
|
1313
|
-
});
|
|
1314
|
-
}
|
|
1315
|
-
async lfsMigrateExport(opts) {
|
|
1316
|
-
if (this._lfsMode === 'disabled') {
|
|
1317
|
-
return;
|
|
1318
|
-
}
|
|
1319
|
-
const args = ['lfs', 'migrate', 'export'];
|
|
1320
|
-
this.appendMigrateArgs(args, opts);
|
|
1321
|
-
if (opts?.remote) {
|
|
1322
|
-
args.push('--remote', opts.remote);
|
|
1323
|
-
}
|
|
1324
|
-
if (opts?.verbose) {
|
|
1325
|
-
args.push('--verbose');
|
|
1326
|
-
}
|
|
1327
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1328
|
-
signal: opts?.signal,
|
|
1329
|
-
onProgress: opts?.onProgress,
|
|
1330
|
-
});
|
|
1331
|
-
}
|
|
1332
|
-
appendMigrateArgs(args, opts) {
|
|
1333
|
-
if (opts?.everything) {
|
|
1334
|
-
args.push('--everything');
|
|
1335
|
-
}
|
|
1336
|
-
if (opts?.include) {
|
|
1337
|
-
const patterns = Array.isArray(opts.include) ? opts.include : [opts.include];
|
|
1338
|
-
for (const pattern of patterns) {
|
|
1339
|
-
args.push('--include', pattern);
|
|
1340
|
-
}
|
|
1341
|
-
}
|
|
1342
|
-
if (opts?.exclude) {
|
|
1343
|
-
const patterns = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
1344
|
-
for (const pattern of patterns) {
|
|
1345
|
-
args.push('--exclude', pattern);
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
if (opts?.includeRef) {
|
|
1349
|
-
const refs = Array.isArray(opts.includeRef) ? opts.includeRef : [opts.includeRef];
|
|
1350
|
-
for (const ref of refs) {
|
|
1351
|
-
args.push('--include-ref', ref);
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
if (opts?.excludeRef) {
|
|
1355
|
-
const refs = Array.isArray(opts.excludeRef) ? opts.excludeRef : [opts.excludeRef];
|
|
1356
|
-
for (const ref of refs) {
|
|
1357
|
-
args.push('--exclude-ref', ref);
|
|
1358
|
-
}
|
|
1359
|
-
}
|
|
1360
|
-
if (opts?.above !== undefined) {
|
|
1361
|
-
args.push('--above', String(opts.above));
|
|
1362
|
-
}
|
|
1363
|
-
if (opts?.top !== undefined) {
|
|
1364
|
-
args.push('--top', String(opts.top));
|
|
1365
|
-
}
|
|
1366
|
-
if (opts?.skipFetch) {
|
|
1367
|
-
args.push('--skip-fetch');
|
|
1368
|
-
}
|
|
1369
|
-
if (opts?.yesReally) {
|
|
1370
|
-
args.push('--yes');
|
|
1371
|
-
}
|
|
1372
|
-
if (opts?.fixup) {
|
|
1373
|
-
args.push('--fixup');
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
async lfsEnv(opts) {
|
|
1377
|
-
const result = await this.runner.runOrThrow(this.context, ['lfs', 'env'], {
|
|
1378
|
-
signal: opts?.signal,
|
|
1379
|
-
});
|
|
1380
|
-
const info = {
|
|
1381
|
-
gitVersion: '',
|
|
1382
|
-
lfsVersion: '',
|
|
1383
|
-
endpoint: '',
|
|
1384
|
-
};
|
|
1385
|
-
for (const line of parseLines(result.stdout)) {
|
|
1386
|
-
if (line.startsWith('git version')) {
|
|
1387
|
-
info.gitVersion = line.replace('git version ', '').trim();
|
|
1388
|
-
}
|
|
1389
|
-
else if (line.startsWith('git-lfs/')) {
|
|
1390
|
-
info.lfsVersion = line.split(' ')[0]?.replace('git-lfs/', '') ?? '';
|
|
1391
|
-
}
|
|
1392
|
-
else if (line.startsWith('Endpoint=')) {
|
|
1393
|
-
info.endpoint = line.replace('Endpoint=', '').trim();
|
|
1394
|
-
}
|
|
1395
|
-
else if (line.startsWith(' SSH=')) {
|
|
1396
|
-
info.sshEndpoint = line.replace(' SSH=', '').trim();
|
|
1397
|
-
}
|
|
1398
|
-
else if (line.startsWith('LocalWorkingDir=')) {
|
|
1399
|
-
info.localWorkingDir = line.replace('LocalWorkingDir=', '').trim();
|
|
1400
|
-
}
|
|
1401
|
-
else if (line.startsWith('LocalGitDir=')) {
|
|
1402
|
-
info.localGitDir = line.replace('LocalGitDir=', '').trim();
|
|
1403
|
-
}
|
|
1404
|
-
else if (line.startsWith('LocalGitStorageDir=')) {
|
|
1405
|
-
info.localGitStorageDir = line.replace('LocalGitStorageDir=', '').trim();
|
|
1406
|
-
}
|
|
1407
|
-
else if (line.startsWith('LocalMediaDir=')) {
|
|
1408
|
-
info.localMediaDir = line.replace('LocalMediaDir=', '').trim();
|
|
1409
|
-
}
|
|
1410
|
-
else if (line.startsWith('LocalReferenceDirs=')) {
|
|
1411
|
-
info.localReferenceDirs = line.replace('LocalReferenceDirs=', '').trim();
|
|
1412
|
-
}
|
|
1413
|
-
else if (line.startsWith('TempDir=')) {
|
|
1414
|
-
info.tempDir = line.replace('TempDir=', '').trim();
|
|
1415
|
-
}
|
|
1416
|
-
else if (line.startsWith('ConcurrentTransfers=')) {
|
|
1417
|
-
info.concurrentTransfers = Number.parseInt(line.replace('ConcurrentTransfers=', '').trim(), 10);
|
|
1418
|
-
}
|
|
1419
|
-
else if (line.startsWith('TusTransfers=')) {
|
|
1420
|
-
info.tusTransfers = line.replace('TusTransfers=', '').trim() === 'true';
|
|
1421
|
-
}
|
|
1422
|
-
else if (line.startsWith('BasicTransfersOnly=')) {
|
|
1423
|
-
info.basicTransfersOnly = line.replace('BasicTransfersOnly=', '').trim() === 'true';
|
|
1424
|
-
}
|
|
1425
|
-
else if (line.startsWith('SkipDownloadErrors=')) {
|
|
1426
|
-
info.skipDownloadErrors = line.replace('SkipDownloadErrors=', '').trim() === 'true';
|
|
1427
|
-
}
|
|
1428
|
-
else if (line.startsWith('FetchRecentAlways=')) {
|
|
1429
|
-
info.fetchRecentAlways = line.replace('FetchRecentAlways=', '').trim() === 'true';
|
|
1430
|
-
}
|
|
1431
|
-
else if (line.startsWith('FetchRecentRefsDays=')) {
|
|
1432
|
-
info.fetchRecentRefsDays = Number.parseInt(line.replace('FetchRecentRefsDays=', '').trim(), 10);
|
|
1433
|
-
}
|
|
1434
|
-
else if (line.startsWith('FetchRecentCommitsDays=')) {
|
|
1435
|
-
info.fetchRecentCommitsDays = Number.parseInt(line.replace('FetchRecentCommitsDays=', '').trim(), 10);
|
|
1436
|
-
}
|
|
1437
|
-
else if (line.startsWith('FetchRecentRefsIncludeRemotes=')) {
|
|
1438
|
-
info.fetchRecentRefsIncludeRemotes =
|
|
1439
|
-
line.replace('FetchRecentRefsIncludeRemotes=', '').trim() === 'true';
|
|
1440
|
-
}
|
|
1441
|
-
else if (line.startsWith('PruneOffsetDays=')) {
|
|
1442
|
-
info.pruneOffsetDays = Number.parseInt(line.replace('PruneOffsetDays=', '').trim(), 10);
|
|
1443
|
-
}
|
|
1444
|
-
else if (line.startsWith('PruneVerifyRemoteAlways=')) {
|
|
1445
|
-
info.pruneVerifyRemoteAlways =
|
|
1446
|
-
line.replace('PruneVerifyRemoteAlways=', '').trim() === 'true';
|
|
1447
|
-
}
|
|
1448
|
-
else if (line.startsWith('PruneRemoteName=')) {
|
|
1449
|
-
info.pruneRemoteName = line.replace('PruneRemoteName=', '').trim();
|
|
1450
|
-
}
|
|
1451
|
-
else if (line.startsWith('AccessDownload=')) {
|
|
1452
|
-
info.accessDownload = line.replace('AccessDownload=', '').trim();
|
|
1453
|
-
}
|
|
1454
|
-
else if (line.startsWith('AccessUpload=')) {
|
|
1455
|
-
info.accessUpload = line.replace('AccessUpload=', '').trim();
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
return info;
|
|
1459
|
-
}
|
|
1460
|
-
async lfsVersion(opts) {
|
|
1461
|
-
const result = await this.runner.runOrThrow(this.context, ['lfs', 'version'], {
|
|
1462
|
-
signal: opts?.signal,
|
|
1463
|
-
});
|
|
1464
|
-
// Format: "git-lfs/3.4.0 (GitHub; linux amd64; go 1.21.1)"
|
|
1465
|
-
const match = result.stdout.match(/git-lfs\/(\S+)/);
|
|
1466
|
-
return match?.[1] ?? result.stdout.trim();
|
|
1467
|
-
}
|
|
1468
|
-
// ==========================================================================
|
|
1469
|
-
// Worktree Operations
|
|
1470
|
-
// ==========================================================================
|
|
1471
|
-
async worktreeList(opts) {
|
|
1472
|
-
const result = await this.runner.runOrThrow(this.context, ['worktree', 'list', '--porcelain'], {
|
|
1473
|
-
signal: opts?.signal,
|
|
1474
|
-
});
|
|
1475
|
-
return parseWorktreeList(result.stdout);
|
|
1476
|
-
}
|
|
1477
|
-
async worktreeAdd(path, opts) {
|
|
1478
|
-
const args = ['worktree', 'add'];
|
|
1479
|
-
if (opts?.detach) {
|
|
1480
|
-
args.push('--detach');
|
|
1481
|
-
}
|
|
1482
|
-
if (opts?.track) {
|
|
1483
|
-
args.push('--track');
|
|
1484
|
-
}
|
|
1485
|
-
// New options
|
|
1486
|
-
if (opts?.force) {
|
|
1487
|
-
args.push('--force');
|
|
1488
|
-
}
|
|
1489
|
-
if (opts?.checkout === true) {
|
|
1490
|
-
args.push('--checkout');
|
|
1491
|
-
}
|
|
1492
|
-
else if (opts?.checkout === false) {
|
|
1493
|
-
args.push('--no-checkout');
|
|
1494
|
-
}
|
|
1495
|
-
if (opts?.lock) {
|
|
1496
|
-
args.push('--lock');
|
|
1497
|
-
}
|
|
1498
|
-
if (opts?.orphan) {
|
|
1499
|
-
args.push('--orphan');
|
|
1500
|
-
}
|
|
1501
|
-
// -b must come before path
|
|
1502
|
-
if (opts?.branch && !(opts.detach || opts.orphan)) {
|
|
1503
|
-
args.push('-b', opts.branch);
|
|
1504
|
-
}
|
|
1505
|
-
args.push(path);
|
|
1506
|
-
// Add commit-ish after path (e.g., branch name, tag, or commit hash)
|
|
1507
|
-
if (opts?.commitish) {
|
|
1508
|
-
args.push(opts.commitish);
|
|
1509
|
-
}
|
|
1510
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1511
|
-
signal: opts?.signal,
|
|
1512
|
-
onProgress: opts?.onProgress,
|
|
1513
|
-
});
|
|
1514
|
-
// Return a new WorktreeRepo for the newly created worktree, preserving LFS mode
|
|
1515
|
-
return new WorktreeRepoImpl(this.runner, path, { lfs: this._lfsMode });
|
|
1516
|
-
}
|
|
1517
|
-
async worktreeRemove(path, opts) {
|
|
1518
|
-
const args = ['worktree', 'remove'];
|
|
1519
|
-
if (opts?.force) {
|
|
1520
|
-
args.push('--force');
|
|
1521
|
-
}
|
|
1522
|
-
args.push(path);
|
|
1523
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1524
|
-
signal: opts?.signal,
|
|
1525
|
-
});
|
|
1526
|
-
}
|
|
1527
|
-
async worktreePrune(opts) {
|
|
1528
|
-
const args = ['worktree', 'prune'];
|
|
1529
|
-
if (opts?.dryRun) {
|
|
1530
|
-
args.push('--dry-run');
|
|
1531
|
-
}
|
|
1532
|
-
if (opts?.verbose) {
|
|
1533
|
-
args.push('--verbose');
|
|
1534
|
-
}
|
|
1535
|
-
// New options
|
|
1536
|
-
if (opts?.expire) {
|
|
1537
|
-
args.push(`--expire=${opts.expire}`);
|
|
1538
|
-
}
|
|
1539
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1540
|
-
signal: opts?.signal,
|
|
1541
|
-
});
|
|
1542
|
-
// Parse pruned paths from output
|
|
1543
|
-
return parseLines(result.stdout);
|
|
1544
|
-
}
|
|
1545
|
-
async worktreeLock(path, opts) {
|
|
1546
|
-
const args = ['worktree', 'lock'];
|
|
1547
|
-
if (opts?.reason) {
|
|
1548
|
-
args.push('--reason', opts.reason);
|
|
1549
|
-
}
|
|
1550
|
-
args.push(path);
|
|
1551
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1552
|
-
signal: opts?.signal,
|
|
1553
|
-
});
|
|
1554
|
-
}
|
|
1555
|
-
async worktreeUnlock(path, opts) {
|
|
1556
|
-
await this.runner.runOrThrow(this.context, ['worktree', 'unlock', path], {
|
|
1557
|
-
signal: opts?.signal,
|
|
1558
|
-
});
|
|
1559
|
-
}
|
|
1560
|
-
async worktreeMove(src, dst, opts) {
|
|
1561
|
-
const args = ['worktree', 'move'];
|
|
1562
|
-
if (opts?.force) {
|
|
1563
|
-
args.push('--force');
|
|
1564
|
-
}
|
|
1565
|
-
args.push(src, dst);
|
|
1566
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1567
|
-
signal: opts?.signal,
|
|
1568
|
-
});
|
|
1569
|
-
// Return a new WorktreeRepo for the worktree at the new location, preserving LFS mode
|
|
1570
|
-
return new WorktreeRepoImpl(this.runner, dst, { lfs: this._lfsMode });
|
|
1571
|
-
}
|
|
1572
|
-
async worktreeRepair(paths, opts) {
|
|
1573
|
-
const args = ['worktree', 'repair'];
|
|
1574
|
-
if (paths && paths.length > 0) {
|
|
1575
|
-
args.push(...paths);
|
|
1576
|
-
}
|
|
1577
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1578
|
-
signal: opts?.signal,
|
|
1579
|
-
});
|
|
1580
|
-
}
|
|
1581
|
-
// ==========================================================================
|
|
1582
|
-
// High-level API - add
|
|
1583
|
-
// ==========================================================================
|
|
1584
|
-
async add(paths, opts) {
|
|
1585
|
-
const args = ['add'];
|
|
1586
|
-
// Verbosity
|
|
1587
|
-
if (opts?.verbose) {
|
|
1588
|
-
args.push('--verbose');
|
|
1589
|
-
}
|
|
1590
|
-
// Main options
|
|
1591
|
-
if (opts?.all) {
|
|
1592
|
-
args.push('--all');
|
|
1593
|
-
}
|
|
1594
|
-
if (opts?.dryRun) {
|
|
1595
|
-
args.push('--dry-run');
|
|
1596
|
-
}
|
|
1597
|
-
if (opts?.update) {
|
|
1598
|
-
args.push('--update');
|
|
1599
|
-
}
|
|
1600
|
-
if (opts?.force) {
|
|
1601
|
-
args.push('--force');
|
|
1602
|
-
}
|
|
1603
|
-
// New options
|
|
1604
|
-
if (opts?.intentToAdd) {
|
|
1605
|
-
args.push('--intent-to-add');
|
|
1606
|
-
}
|
|
1607
|
-
if (opts?.renormalize) {
|
|
1608
|
-
args.push('--renormalize');
|
|
1609
|
-
}
|
|
1610
|
-
if (opts?.ignoreRemoval) {
|
|
1611
|
-
args.push('--ignore-removal');
|
|
1612
|
-
}
|
|
1613
|
-
if (opts?.refresh) {
|
|
1614
|
-
args.push('--refresh');
|
|
1615
|
-
}
|
|
1616
|
-
if (opts?.ignoreErrors) {
|
|
1617
|
-
args.push('--ignore-errors');
|
|
1618
|
-
}
|
|
1619
|
-
if (opts?.ignoreMissing) {
|
|
1620
|
-
args.push('--ignore-missing');
|
|
1621
|
-
}
|
|
1622
|
-
if (opts?.sparse) {
|
|
1623
|
-
args.push('--sparse');
|
|
1624
|
-
}
|
|
1625
|
-
if (opts?.chmod) {
|
|
1626
|
-
args.push(`--chmod=${opts.chmod}`);
|
|
1627
|
-
}
|
|
1628
|
-
if (opts?.pathspecFromFile) {
|
|
1629
|
-
args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
|
|
1630
|
-
}
|
|
1631
|
-
const pathList = Array.isArray(paths) ? paths : [paths];
|
|
1632
|
-
args.push('--', ...pathList);
|
|
1633
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1634
|
-
signal: opts?.signal,
|
|
1635
|
-
});
|
|
1636
|
-
}
|
|
1637
|
-
// ==========================================================================
|
|
1638
|
-
// High-level API - Branch Operations
|
|
1639
|
-
// ==========================================================================
|
|
1640
|
-
async branchList(opts) {
|
|
1641
|
-
const args = [
|
|
1642
|
-
'branch',
|
|
1643
|
-
'--list',
|
|
1644
|
-
'--format=%(refname:short)%00%(objectname:short)%00%(upstream:short)%00%(upstream:track,nobracket)%00%(HEAD)',
|
|
1645
|
-
];
|
|
1646
|
-
// Existing options
|
|
1647
|
-
if (opts?.all) {
|
|
1648
|
-
args.push('--all');
|
|
1649
|
-
}
|
|
1650
|
-
if (opts?.remotes) {
|
|
1651
|
-
args.push('--remotes');
|
|
1652
|
-
}
|
|
1653
|
-
// New options
|
|
1654
|
-
if (opts?.quiet) {
|
|
1655
|
-
args.push('--quiet');
|
|
1656
|
-
}
|
|
1657
|
-
if (opts?.contains) {
|
|
1658
|
-
args.push(`--contains=${opts.contains}`);
|
|
1659
|
-
}
|
|
1660
|
-
if (opts?.noContains) {
|
|
1661
|
-
args.push(`--no-contains=${opts.noContains}`);
|
|
1662
|
-
}
|
|
1663
|
-
if (opts?.abbrev !== undefined) {
|
|
1664
|
-
args.push(`--abbrev=${opts.abbrev}`);
|
|
1665
|
-
}
|
|
1666
|
-
if (opts?.merged) {
|
|
1667
|
-
args.push(`--merged=${opts.merged}`);
|
|
1668
|
-
}
|
|
1669
|
-
if (opts?.noMerged) {
|
|
1670
|
-
args.push(`--no-merged=${opts.noMerged}`);
|
|
1671
|
-
}
|
|
1672
|
-
if (opts?.sort) {
|
|
1673
|
-
args.push(`--sort=${opts.sort}`);
|
|
1674
|
-
}
|
|
1675
|
-
if (opts?.pointsAt) {
|
|
1676
|
-
args.push(`--points-at=${opts.pointsAt}`);
|
|
1677
|
-
}
|
|
1678
|
-
if (opts?.ignoreCase) {
|
|
1679
|
-
args.push('--ignore-case');
|
|
1680
|
-
}
|
|
1681
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1682
|
-
signal: opts?.signal,
|
|
1683
|
-
});
|
|
1684
|
-
const branches = [];
|
|
1685
|
-
for (const line of parseLines(result.stdout)) {
|
|
1686
|
-
const parts = line.split('\0');
|
|
1687
|
-
const name = parts[0];
|
|
1688
|
-
const commit = parts[1];
|
|
1689
|
-
const upstream = parts[2];
|
|
1690
|
-
const trackInfo = parts[3];
|
|
1691
|
-
const head = parts[4];
|
|
1692
|
-
if (name !== undefined && commit !== undefined) {
|
|
1693
|
-
branches.push({
|
|
1694
|
-
name,
|
|
1695
|
-
commit,
|
|
1696
|
-
current: head === '*',
|
|
1697
|
-
upstream: upstream || undefined,
|
|
1698
|
-
gone: trackInfo?.includes('gone'),
|
|
1699
|
-
});
|
|
1700
|
-
}
|
|
1701
|
-
}
|
|
1702
|
-
return branches;
|
|
1703
|
-
}
|
|
1704
|
-
async branchCurrent(opts) {
|
|
1705
|
-
const result = await this.runner.run(this.context, ['symbolic-ref', '--short', 'HEAD'], {
|
|
1706
|
-
signal: opts?.signal,
|
|
1707
|
-
});
|
|
1708
|
-
if (result.exitCode !== 0) {
|
|
1709
|
-
// Detached HEAD
|
|
1710
|
-
return null;
|
|
1711
|
-
}
|
|
1712
|
-
return result.stdout.trim();
|
|
1713
|
-
}
|
|
1714
|
-
async branchCreate(name, opts) {
|
|
1715
|
-
const args = ['branch'];
|
|
1716
|
-
// Existing options
|
|
1717
|
-
if (opts?.force) {
|
|
1718
|
-
args.push('--force');
|
|
1719
|
-
}
|
|
1720
|
-
if (opts?.track) {
|
|
1721
|
-
args.push('--track');
|
|
1722
|
-
}
|
|
1723
|
-
// New options
|
|
1724
|
-
if (opts?.setUpstreamTo) {
|
|
1725
|
-
args.push(`--set-upstream-to=${opts.setUpstreamTo}`);
|
|
1726
|
-
}
|
|
1727
|
-
if (opts?.createReflog) {
|
|
1728
|
-
args.push('--create-reflog');
|
|
1729
|
-
}
|
|
1730
|
-
if (opts?.recurseSubmodules) {
|
|
1731
|
-
args.push('--recurse-submodules');
|
|
1732
|
-
}
|
|
1733
|
-
args.push(name);
|
|
1734
|
-
if (opts?.startPoint) {
|
|
1735
|
-
args.push(opts.startPoint);
|
|
1736
|
-
}
|
|
1737
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1738
|
-
signal: opts?.signal,
|
|
1739
|
-
});
|
|
1740
|
-
}
|
|
1741
|
-
async branchDelete(name, opts) {
|
|
1742
|
-
const args = ['branch'];
|
|
1743
|
-
if (opts?.remote) {
|
|
1744
|
-
args.push('-r');
|
|
1745
|
-
}
|
|
1746
|
-
if (opts?.force) {
|
|
1747
|
-
args.push('-D');
|
|
1748
|
-
}
|
|
1749
|
-
else {
|
|
1750
|
-
args.push('-d');
|
|
1751
|
-
}
|
|
1752
|
-
args.push(name);
|
|
1753
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1754
|
-
signal: opts?.signal,
|
|
1755
|
-
});
|
|
1756
|
-
}
|
|
1757
|
-
async branchRename(oldName, newName, opts) {
|
|
1758
|
-
await this.runner.runOrThrow(this.context, ['branch', '-m', oldName, newName], {
|
|
1759
|
-
signal: opts?.signal,
|
|
1760
|
-
});
|
|
1761
|
-
}
|
|
1762
|
-
// Implementation
|
|
1763
|
-
async checkout(targetOrPaths, opts) {
|
|
1764
|
-
const args = ['checkout'];
|
|
1765
|
-
// Determine mode based on first argument type
|
|
1766
|
-
const isPathMode = Array.isArray(targetOrPaths);
|
|
1767
|
-
if (isPathMode) {
|
|
1768
|
-
// Pathspec mode: git checkout [<tree-ish>] -- <pathspec>...
|
|
1769
|
-
const pathOpts = opts;
|
|
1770
|
-
if (pathOpts?.force) {
|
|
1771
|
-
args.push('--force');
|
|
1772
|
-
}
|
|
1773
|
-
if (pathOpts?.quiet) {
|
|
1774
|
-
args.push('--quiet');
|
|
1775
|
-
}
|
|
1776
|
-
if (pathOpts?.overlay !== undefined) {
|
|
1777
|
-
args.push(pathOpts.overlay ? '--overlay' : '--no-overlay');
|
|
1778
|
-
}
|
|
1779
|
-
if (pathOpts?.ours) {
|
|
1780
|
-
args.push('--ours');
|
|
1781
|
-
}
|
|
1782
|
-
if (pathOpts?.theirs) {
|
|
1783
|
-
args.push('--theirs');
|
|
1784
|
-
}
|
|
1785
|
-
if (pathOpts?.pathspecFromFile) {
|
|
1786
|
-
args.push(`--pathspec-from-file=${pathOpts.pathspecFromFile}`);
|
|
1787
|
-
}
|
|
1788
|
-
// Add source tree-ish if specified
|
|
1789
|
-
if (pathOpts?.source) {
|
|
1790
|
-
args.push(pathOpts.source);
|
|
1791
|
-
}
|
|
1792
|
-
// Add -- separator and pathspecs
|
|
1793
|
-
args.push('--');
|
|
1794
|
-
args.push(...targetOrPaths);
|
|
1795
|
-
}
|
|
1796
|
-
else {
|
|
1797
|
-
// Branch switching mode: git checkout <branch>
|
|
1798
|
-
const branchOpts = opts;
|
|
1799
|
-
if (branchOpts?.force) {
|
|
1800
|
-
args.push('--force');
|
|
1801
|
-
}
|
|
1802
|
-
if (branchOpts?.forceCreateBranch) {
|
|
1803
|
-
args.push('-B');
|
|
1804
|
-
}
|
|
1805
|
-
else if (branchOpts?.createBranch) {
|
|
1806
|
-
args.push('-b');
|
|
1807
|
-
}
|
|
1808
|
-
if (branchOpts?.track) {
|
|
1809
|
-
args.push('--track');
|
|
1810
|
-
}
|
|
1811
|
-
if (branchOpts?.createReflog) {
|
|
1812
|
-
args.push('-l');
|
|
1813
|
-
}
|
|
1814
|
-
if (branchOpts?.guess !== undefined) {
|
|
1815
|
-
args.push(branchOpts.guess ? '--guess' : '--no-guess');
|
|
1816
|
-
}
|
|
1817
|
-
if (branchOpts?.quiet) {
|
|
1818
|
-
args.push('--quiet');
|
|
1819
|
-
}
|
|
1820
|
-
if (branchOpts?.recurseSubmodules) {
|
|
1821
|
-
args.push('--recurse-submodules');
|
|
1822
|
-
}
|
|
1823
|
-
if (branchOpts?.merge) {
|
|
1824
|
-
args.push('--merge');
|
|
1825
|
-
}
|
|
1826
|
-
if (branchOpts?.conflict) {
|
|
1827
|
-
args.push(`--conflict=${branchOpts.conflict}`);
|
|
1828
|
-
}
|
|
1829
|
-
if (branchOpts?.detach) {
|
|
1830
|
-
args.push('--detach');
|
|
1831
|
-
}
|
|
1832
|
-
if (branchOpts?.orphan) {
|
|
1833
|
-
args.push('--orphan');
|
|
1834
|
-
}
|
|
1835
|
-
if (branchOpts?.overwriteIgnore === false) {
|
|
1836
|
-
args.push('--no-overwrite-ignore');
|
|
1837
|
-
}
|
|
1838
|
-
if (branchOpts?.ignoreOtherWorktrees) {
|
|
1839
|
-
args.push('--ignore-other-worktrees');
|
|
1840
|
-
}
|
|
1841
|
-
args.push(targetOrPaths);
|
|
1842
|
-
if (branchOpts?.startPoint) {
|
|
1843
|
-
args.push(branchOpts.startPoint);
|
|
1844
|
-
}
|
|
1845
|
-
}
|
|
1846
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
1847
|
-
signal: opts?.signal,
|
|
1848
|
-
});
|
|
1849
|
-
}
|
|
1850
|
-
// ==========================================================================
|
|
1851
|
-
// High-level API - commit
|
|
1852
|
-
// ==========================================================================
|
|
1853
|
-
async commit(opts) {
|
|
1854
|
-
const args = ['commit'];
|
|
1855
|
-
// Existing options
|
|
1856
|
-
if (opts?.message) {
|
|
1857
|
-
args.push('-m', opts.message);
|
|
1858
|
-
}
|
|
1859
|
-
if (opts?.allowEmpty) {
|
|
1860
|
-
args.push('--allow-empty');
|
|
1861
|
-
}
|
|
1862
|
-
if (opts?.amend) {
|
|
1863
|
-
args.push('--amend');
|
|
1864
|
-
}
|
|
1865
|
-
if (opts?.all) {
|
|
1866
|
-
args.push('-a');
|
|
1867
|
-
}
|
|
1868
|
-
if (opts?.author) {
|
|
1869
|
-
args.push('--author', opts.author);
|
|
1870
|
-
}
|
|
1871
|
-
if (opts?.date) {
|
|
1872
|
-
const date = opts.date instanceof Date ? opts.date.toISOString() : opts.date;
|
|
1873
|
-
args.push('--date', date);
|
|
1874
|
-
}
|
|
1875
|
-
if (opts?.dryRun) {
|
|
1876
|
-
args.push('--dry-run');
|
|
1877
|
-
}
|
|
1878
|
-
if (opts?.noVerify) {
|
|
1879
|
-
args.push('--no-verify');
|
|
1880
|
-
}
|
|
1881
|
-
if (opts?.gpgSign) {
|
|
1882
|
-
args.push('-S');
|
|
1883
|
-
}
|
|
1884
|
-
else if (opts?.noGpgSign) {
|
|
1885
|
-
args.push('--no-gpg-sign');
|
|
1886
|
-
}
|
|
1887
|
-
// New options
|
|
1888
|
-
if (opts?.quiet) {
|
|
1889
|
-
args.push('--quiet');
|
|
1890
|
-
}
|
|
1891
|
-
if (opts?.verbose) {
|
|
1892
|
-
args.push('--verbose');
|
|
1893
|
-
}
|
|
1894
|
-
if (opts?.file) {
|
|
1895
|
-
args.push('--file', opts.file);
|
|
1896
|
-
}
|
|
1897
|
-
if (opts?.reeditMessage) {
|
|
1898
|
-
args.push('--reedit-message', opts.reeditMessage);
|
|
1899
|
-
}
|
|
1900
|
-
if (opts?.reuseMessage) {
|
|
1901
|
-
args.push('--reuse-message', opts.reuseMessage);
|
|
1902
|
-
}
|
|
1903
|
-
if (opts?.fixup) {
|
|
1904
|
-
args.push('--fixup', opts.fixup);
|
|
1905
|
-
}
|
|
1906
|
-
if (opts?.squash) {
|
|
1907
|
-
args.push('--squash', opts.squash);
|
|
1908
|
-
}
|
|
1909
|
-
if (opts?.resetAuthor) {
|
|
1910
|
-
args.push('--reset-author');
|
|
1911
|
-
}
|
|
1912
|
-
if (opts?.trailer) {
|
|
1913
|
-
const trailers = Array.isArray(opts.trailer) ? opts.trailer : [opts.trailer];
|
|
1914
|
-
for (const trailer of trailers) {
|
|
1915
|
-
args.push('--trailer', trailer);
|
|
1916
|
-
}
|
|
1917
|
-
}
|
|
1918
|
-
if (opts?.signoff) {
|
|
1919
|
-
args.push('--signoff');
|
|
1920
|
-
}
|
|
1921
|
-
if (opts?.cleanup) {
|
|
1922
|
-
args.push(`--cleanup=${opts.cleanup}`);
|
|
1923
|
-
}
|
|
1924
|
-
if (opts?.include) {
|
|
1925
|
-
args.push('--include');
|
|
1926
|
-
}
|
|
1927
|
-
if (opts?.only) {
|
|
1928
|
-
args.push('--only');
|
|
1929
|
-
}
|
|
1930
|
-
if (opts?.noPostRewrite) {
|
|
1931
|
-
args.push('--no-post-rewrite');
|
|
1932
|
-
}
|
|
1933
|
-
if (opts?.untrackedFiles) {
|
|
1934
|
-
args.push(`--untracked-files=${opts.untrackedFiles}`);
|
|
1935
|
-
}
|
|
1936
|
-
if (opts?.pathspecFromFile) {
|
|
1937
|
-
args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
|
|
1938
|
-
}
|
|
1939
|
-
if (opts?.allowEmptyMessage) {
|
|
1940
|
-
args.push('--allow-empty-message');
|
|
1941
|
-
}
|
|
1942
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
1943
|
-
signal: opts?.signal,
|
|
1944
|
-
});
|
|
1945
|
-
// Parse commit output
|
|
1946
|
-
const output = result.stdout;
|
|
1947
|
-
let hash = '';
|
|
1948
|
-
let branch = '';
|
|
1949
|
-
let summary = '';
|
|
1950
|
-
let filesChanged = 0;
|
|
1951
|
-
let insertions = 0;
|
|
1952
|
-
let deletions = 0;
|
|
1953
|
-
// Get the commit hash
|
|
1954
|
-
const hashResult = await this.runner.runOrThrow(this.context, ['rev-parse', 'HEAD'], {
|
|
1955
|
-
signal: opts?.signal,
|
|
1956
|
-
});
|
|
1957
|
-
hash = hashResult.stdout.trim();
|
|
1958
|
-
// Get the branch name
|
|
1959
|
-
const branchResult = await this.runner.run(this.context, ['symbolic-ref', '--short', 'HEAD'], {
|
|
1960
|
-
signal: opts?.signal,
|
|
1961
|
-
});
|
|
1962
|
-
branch = branchResult.exitCode === 0 ? branchResult.stdout.trim() : 'HEAD';
|
|
1963
|
-
// Parse stats from output if available
|
|
1964
|
-
const statsMatch = output.match(/(\d+) files? changed(?:, (\d+) insertions?\(\+\))?(?:, (\d+) deletions?\(-\))?/);
|
|
1965
|
-
if (statsMatch) {
|
|
1966
|
-
filesChanged = Number.parseInt(statsMatch[1] || '0', 10);
|
|
1967
|
-
insertions = Number.parseInt(statsMatch[2] || '0', 10);
|
|
1968
|
-
deletions = Number.parseInt(statsMatch[3] || '0', 10);
|
|
1969
|
-
}
|
|
1970
|
-
// Get subject from log
|
|
1971
|
-
const logResult = await this.runner.runOrThrow(this.context, ['log', '-1', '--format=%s'], {
|
|
1972
|
-
signal: opts?.signal,
|
|
1973
|
-
});
|
|
1974
|
-
summary = logResult.stdout.trim();
|
|
1975
|
-
return {
|
|
1976
|
-
hash,
|
|
1977
|
-
branch,
|
|
1978
|
-
summary,
|
|
1979
|
-
filesChanged,
|
|
1980
|
-
insertions,
|
|
1981
|
-
deletions,
|
|
1982
|
-
};
|
|
1983
|
-
}
|
|
1984
|
-
// ==========================================================================
|
|
1985
|
-
// High-level API - diff
|
|
1986
|
-
// ==========================================================================
|
|
1987
|
-
async diff(target, opts) {
|
|
1988
|
-
const args = ['diff'];
|
|
1989
|
-
// Existing options
|
|
1990
|
-
if (opts?.staged) {
|
|
1991
|
-
args.push('--staged');
|
|
1992
|
-
}
|
|
1993
|
-
if (opts?.nameOnly) {
|
|
1994
|
-
args.push('--name-only');
|
|
1995
|
-
}
|
|
1996
|
-
else if (opts?.nameStatus) {
|
|
1997
|
-
args.push('--name-status');
|
|
1998
|
-
}
|
|
1999
|
-
else if (opts?.stat) {
|
|
2000
|
-
args.push('--stat');
|
|
2001
|
-
}
|
|
2002
|
-
if (opts?.context !== undefined) {
|
|
2003
|
-
args.push(`-U${opts.context}`);
|
|
2004
|
-
}
|
|
2005
|
-
if (opts?.ignoreWhitespace) {
|
|
2006
|
-
args.push('-w');
|
|
2007
|
-
}
|
|
2008
|
-
// New options
|
|
2009
|
-
if (opts?.nullTerminated) {
|
|
2010
|
-
args.push('-z');
|
|
2011
|
-
}
|
|
2012
|
-
if (opts?.patch) {
|
|
2013
|
-
args.push('-p');
|
|
2014
|
-
}
|
|
2015
|
-
if (opts?.patchWithRaw) {
|
|
2016
|
-
args.push('--patch-with-raw');
|
|
2017
|
-
}
|
|
2018
|
-
if (opts?.numstat) {
|
|
2019
|
-
args.push('--numstat');
|
|
2020
|
-
}
|
|
2021
|
-
if (opts?.patchWithStat) {
|
|
2022
|
-
args.push('--patch-with-stat');
|
|
2023
|
-
}
|
|
2024
|
-
if (opts?.fullIndex) {
|
|
2025
|
-
args.push('--full-index');
|
|
2026
|
-
}
|
|
2027
|
-
if (opts?.abbrev !== undefined) {
|
|
2028
|
-
args.push(`--abbrev=${opts.abbrev}`);
|
|
2029
|
-
}
|
|
2030
|
-
if (opts?.reverse) {
|
|
2031
|
-
args.push('-R');
|
|
2032
|
-
}
|
|
2033
|
-
if (opts?.detectRewrites !== undefined) {
|
|
2034
|
-
if (opts.detectRewrites === true) {
|
|
2035
|
-
args.push('-B');
|
|
2036
|
-
}
|
|
2037
|
-
else if (typeof opts.detectRewrites === 'string') {
|
|
2038
|
-
args.push(`-B${opts.detectRewrites}`);
|
|
2039
|
-
}
|
|
2040
|
-
}
|
|
2041
|
-
if (opts?.detectRenames !== undefined) {
|
|
2042
|
-
if (opts.detectRenames === true) {
|
|
2043
|
-
args.push('-M');
|
|
2044
|
-
}
|
|
2045
|
-
else if (typeof opts.detectRenames === 'string') {
|
|
2046
|
-
args.push(`-M${opts.detectRenames}`);
|
|
2047
|
-
}
|
|
2048
|
-
}
|
|
2049
|
-
if (opts?.detectCopies !== undefined) {
|
|
2050
|
-
if (opts.detectCopies === true) {
|
|
2051
|
-
args.push('-C');
|
|
2052
|
-
}
|
|
2053
|
-
else if (typeof opts.detectCopies === 'string') {
|
|
2054
|
-
args.push(`-C${opts.detectCopies}`);
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
if (opts?.findCopiesHarder) {
|
|
2058
|
-
args.push('--find-copies-harder');
|
|
2059
|
-
}
|
|
2060
|
-
if (opts?.renameLimit !== undefined) {
|
|
2061
|
-
args.push(`-l${opts.renameLimit}`);
|
|
2062
|
-
}
|
|
2063
|
-
if (opts?.pickaxe) {
|
|
2064
|
-
args.push(`-S${opts.pickaxe}`);
|
|
2065
|
-
}
|
|
2066
|
-
if (opts?.pickaxeAll) {
|
|
2067
|
-
args.push('--pickaxe-all');
|
|
2068
|
-
}
|
|
2069
|
-
if (opts?.text) {
|
|
2070
|
-
args.push('--text');
|
|
2071
|
-
}
|
|
2072
|
-
if (opts?.mergeBase) {
|
|
2073
|
-
args.push(`--merge-base=${opts.mergeBase}`);
|
|
2074
|
-
}
|
|
2075
|
-
if (opts?.noIndex) {
|
|
2076
|
-
args.push('--no-index');
|
|
2077
|
-
}
|
|
2078
|
-
if (opts?.wordDiff) {
|
|
2079
|
-
args.push(`--word-diff=${opts.wordDiff}`);
|
|
2080
|
-
}
|
|
2081
|
-
if (target) {
|
|
2082
|
-
args.push(target);
|
|
2083
|
-
}
|
|
2084
|
-
if (opts?.paths && opts.paths.length > 0) {
|
|
2085
|
-
args.push('--', ...opts.paths);
|
|
2086
|
-
}
|
|
2087
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2088
|
-
signal: opts?.signal,
|
|
2089
|
-
});
|
|
2090
|
-
// Parse nameStatus result
|
|
2091
|
-
if (opts?.nameStatus) {
|
|
2092
|
-
const files = [];
|
|
2093
|
-
for (const line of parseLines(result.stdout)) {
|
|
2094
|
-
const match = line.match(/^([AMDRTCUX])\t(.+?)(?:\t(.+))?$/);
|
|
2095
|
-
const status = match?.[1];
|
|
2096
|
-
const pathOrOld = match?.[2];
|
|
2097
|
-
const newPath = match?.[3];
|
|
2098
|
-
if (status !== undefined && pathOrOld !== undefined) {
|
|
2099
|
-
const entry = {
|
|
2100
|
-
status,
|
|
2101
|
-
path: newPath ?? pathOrOld,
|
|
2102
|
-
};
|
|
2103
|
-
if (newPath !== undefined) {
|
|
2104
|
-
entry.oldPath = pathOrOld;
|
|
2105
|
-
}
|
|
2106
|
-
files.push(entry);
|
|
2107
|
-
}
|
|
2108
|
-
}
|
|
2109
|
-
return { files };
|
|
2110
|
-
}
|
|
2111
|
-
// Parse nameOnly result
|
|
2112
|
-
if (opts?.nameOnly) {
|
|
2113
|
-
const files = [];
|
|
2114
|
-
for (const line of parseLines(result.stdout)) {
|
|
2115
|
-
files.push({ status: 'M', path: line });
|
|
2116
|
-
}
|
|
2117
|
-
return { files };
|
|
2118
|
-
}
|
|
2119
|
-
// Return raw result (default)
|
|
2120
|
-
return { files: [], raw: result.stdout };
|
|
2121
|
-
}
|
|
2122
|
-
// ==========================================================================
|
|
2123
|
-
// High-level API - merge
|
|
2124
|
-
// ==========================================================================
|
|
2125
|
-
async merge(branch, opts) {
|
|
2126
|
-
if (opts?.abort) {
|
|
2127
|
-
await this.runner.runOrThrow(this.context, ['merge', '--abort'], {
|
|
2128
|
-
signal: opts?.signal,
|
|
2129
|
-
});
|
|
2130
|
-
return { success: true };
|
|
2131
|
-
}
|
|
2132
|
-
if (opts?.continue) {
|
|
2133
|
-
await this.runner.runOrThrow(this.context, ['merge', '--continue'], {
|
|
2134
|
-
signal: opts?.signal,
|
|
2135
|
-
});
|
|
2136
|
-
const hash = (await this.runner.runOrThrow(this.context, ['rev-parse', 'HEAD'])).stdout.trim();
|
|
2137
|
-
return { success: true, hash };
|
|
2138
|
-
}
|
|
2139
|
-
const args = ['merge'];
|
|
2140
|
-
// Existing options
|
|
2141
|
-
if (opts?.message) {
|
|
2142
|
-
args.push('-m', opts.message);
|
|
2143
|
-
}
|
|
2144
|
-
if (opts?.ff === 'only') {
|
|
2145
|
-
args.push('--ff-only');
|
|
2146
|
-
}
|
|
2147
|
-
else if (opts?.ff === 'no' || opts?.ff === false) {
|
|
2148
|
-
args.push('--no-ff');
|
|
2149
|
-
}
|
|
2150
|
-
if (opts?.squash) {
|
|
2151
|
-
args.push('--squash');
|
|
2152
|
-
}
|
|
2153
|
-
if (opts?.noCommit) {
|
|
2154
|
-
args.push('--no-commit');
|
|
2155
|
-
}
|
|
2156
|
-
if (opts?.strategy) {
|
|
2157
|
-
args.push('-s', opts.strategy);
|
|
2158
|
-
}
|
|
2159
|
-
if (opts?.strategyOption) {
|
|
2160
|
-
const strategyOpts = Array.isArray(opts.strategyOption)
|
|
2161
|
-
? opts.strategyOption
|
|
2162
|
-
: [opts.strategyOption];
|
|
2163
|
-
for (const opt of strategyOpts) {
|
|
2164
|
-
args.push('-X', opt);
|
|
2165
|
-
}
|
|
2166
|
-
}
|
|
2167
|
-
if (opts?.noVerify) {
|
|
2168
|
-
args.push('--no-verify');
|
|
2169
|
-
}
|
|
2170
|
-
// New options
|
|
2171
|
-
if (opts?.noDiffstat) {
|
|
2172
|
-
args.push('-n');
|
|
2173
|
-
}
|
|
2174
|
-
else if (opts?.stat) {
|
|
2175
|
-
args.push('--stat');
|
|
2176
|
-
}
|
|
2177
|
-
if (opts?.compactSummary) {
|
|
2178
|
-
args.push('--compact-summary');
|
|
2179
|
-
}
|
|
2180
|
-
if (opts?.log !== undefined) {
|
|
2181
|
-
if (opts.log === true) {
|
|
2182
|
-
args.push('--log');
|
|
2183
|
-
}
|
|
2184
|
-
else if (typeof opts.log === 'number') {
|
|
2185
|
-
args.push(`--log=${opts.log}`);
|
|
2186
|
-
}
|
|
2187
|
-
}
|
|
2188
|
-
if (opts?.cleanup) {
|
|
2189
|
-
args.push(`--cleanup=${opts.cleanup}`);
|
|
2190
|
-
}
|
|
2191
|
-
if (opts?.rerereAutoupdate !== undefined) {
|
|
2192
|
-
args.push(opts.rerereAutoupdate ? '--rerere-autoupdate' : '--no-rerere-autoupdate');
|
|
2193
|
-
}
|
|
2194
|
-
if (opts?.verifySignatures) {
|
|
2195
|
-
args.push('--verify-signatures');
|
|
2196
|
-
}
|
|
2197
|
-
if (opts?.verbose) {
|
|
2198
|
-
args.push('--verbose');
|
|
2199
|
-
}
|
|
2200
|
-
if (opts?.quiet) {
|
|
2201
|
-
args.push('--quiet');
|
|
2202
|
-
}
|
|
2203
|
-
if (opts?.allowUnrelatedHistories) {
|
|
2204
|
-
args.push('--allow-unrelated-histories');
|
|
2205
|
-
}
|
|
2206
|
-
if (opts?.gpgSign !== undefined) {
|
|
2207
|
-
if (opts.gpgSign === true) {
|
|
2208
|
-
args.push('-S');
|
|
2209
|
-
}
|
|
2210
|
-
else if (typeof opts.gpgSign === 'string') {
|
|
2211
|
-
args.push(`-S${opts.gpgSign}`);
|
|
2212
|
-
}
|
|
2213
|
-
}
|
|
2214
|
-
if (opts?.autostash) {
|
|
2215
|
-
args.push('--autostash');
|
|
2216
|
-
}
|
|
2217
|
-
if (opts?.overwriteIgnore === false) {
|
|
2218
|
-
args.push('--no-overwrite-ignore');
|
|
2219
|
-
}
|
|
2220
|
-
if (opts?.signoff) {
|
|
2221
|
-
args.push('--signoff');
|
|
2222
|
-
}
|
|
2223
|
-
if (opts?.intoName) {
|
|
2224
|
-
args.push(`--into-name=${opts.intoName}`);
|
|
2225
|
-
}
|
|
2226
|
-
args.push(branch);
|
|
2227
|
-
const result = await this.runner.run(this.context, args, {
|
|
2228
|
-
signal: opts?.signal,
|
|
2229
|
-
});
|
|
2230
|
-
if (result.exitCode !== 0) {
|
|
2231
|
-
// Check for conflicts
|
|
2232
|
-
const statusResult = await this.runner.runOrThrow(this.context, ['status', '--porcelain'], {
|
|
2233
|
-
signal: opts?.signal,
|
|
2234
|
-
});
|
|
2235
|
-
const conflicts = parseLines(statusResult.stdout)
|
|
2236
|
-
.filter((line) => line.startsWith('UU ') || line.startsWith('AA ') || line.startsWith('DD '))
|
|
2237
|
-
.map((line) => line.slice(3));
|
|
2238
|
-
return {
|
|
2239
|
-
success: false,
|
|
2240
|
-
conflicts,
|
|
2241
|
-
};
|
|
2242
|
-
}
|
|
2243
|
-
// Get the new HEAD
|
|
2244
|
-
const hashResult = await this.runner.runOrThrow(this.context, ['rev-parse', 'HEAD'], {
|
|
2245
|
-
signal: opts?.signal,
|
|
2246
|
-
});
|
|
2247
|
-
// Check if it was a fast-forward
|
|
2248
|
-
const fastForward = result.stdout.includes('Fast-forward') || result.stderr.includes('Fast-forward');
|
|
2249
|
-
return {
|
|
2250
|
-
success: true,
|
|
2251
|
-
hash: hashResult.stdout.trim(),
|
|
2252
|
-
fastForward,
|
|
2253
|
-
};
|
|
2254
|
-
}
|
|
2255
|
-
// ==========================================================================
|
|
2256
|
-
// High-level API - pull
|
|
2257
|
-
// ==========================================================================
|
|
2258
|
-
async pull(opts) {
|
|
2259
|
-
const args = ['pull'];
|
|
2260
|
-
// Progress tracking
|
|
2261
|
-
if (opts?.onProgress) {
|
|
2262
|
-
args.push('--progress');
|
|
2263
|
-
}
|
|
2264
|
-
// Existing options
|
|
2265
|
-
if (opts?.rebase === true) {
|
|
2266
|
-
args.push('--rebase');
|
|
2267
|
-
}
|
|
2268
|
-
else if (opts?.rebase === 'merges') {
|
|
2269
|
-
args.push('--rebase=merges');
|
|
2270
|
-
}
|
|
2271
|
-
else if (opts?.rebase === 'interactive') {
|
|
2272
|
-
args.push('--rebase=interactive');
|
|
2273
|
-
}
|
|
2274
|
-
if (opts?.ff === 'only') {
|
|
2275
|
-
args.push('--ff-only');
|
|
2276
|
-
}
|
|
2277
|
-
else if (opts?.ff === 'no' || opts?.ff === false) {
|
|
2278
|
-
args.push('--no-ff');
|
|
2279
|
-
}
|
|
2280
|
-
if (opts?.tags) {
|
|
2281
|
-
args.push('--tags');
|
|
2282
|
-
}
|
|
2283
|
-
if (opts?.prune) {
|
|
2284
|
-
args.push('--prune');
|
|
2285
|
-
}
|
|
2286
|
-
// New options
|
|
2287
|
-
if (opts?.verbose) {
|
|
2288
|
-
args.push('--verbose');
|
|
2289
|
-
}
|
|
2290
|
-
if (opts?.quiet) {
|
|
2291
|
-
args.push('--quiet');
|
|
2292
|
-
}
|
|
2293
|
-
if (opts?.recurseSubmodules !== undefined) {
|
|
2294
|
-
if (opts.recurseSubmodules === true || opts.recurseSubmodules === 'yes') {
|
|
2295
|
-
args.push('--recurse-submodules=yes');
|
|
2296
|
-
}
|
|
2297
|
-
else if (opts.recurseSubmodules === 'on-demand') {
|
|
2298
|
-
args.push('--recurse-submodules=on-demand');
|
|
2299
|
-
}
|
|
2300
|
-
else if (opts.recurseSubmodules === 'no' || opts.recurseSubmodules === false) {
|
|
2301
|
-
args.push('--recurse-submodules=no');
|
|
2302
|
-
}
|
|
2303
|
-
}
|
|
2304
|
-
if (opts?.noStat) {
|
|
2305
|
-
args.push('-n');
|
|
2306
|
-
}
|
|
2307
|
-
else if (opts?.stat) {
|
|
2308
|
-
args.push('--stat');
|
|
2309
|
-
}
|
|
2310
|
-
if (opts?.compactSummary) {
|
|
2311
|
-
args.push('--compact-summary');
|
|
2312
|
-
}
|
|
2313
|
-
if (opts?.log !== undefined) {
|
|
2314
|
-
if (opts.log === true) {
|
|
2315
|
-
args.push('--log');
|
|
2316
|
-
}
|
|
2317
|
-
else if (typeof opts.log === 'number') {
|
|
2318
|
-
args.push(`--log=${opts.log}`);
|
|
2319
|
-
}
|
|
2320
|
-
}
|
|
2321
|
-
if (opts?.signoff) {
|
|
2322
|
-
args.push('--signoff');
|
|
2323
|
-
}
|
|
2324
|
-
if (opts?.squash) {
|
|
2325
|
-
args.push('--squash');
|
|
2326
|
-
}
|
|
2327
|
-
if (opts?.commit !== undefined) {
|
|
2328
|
-
args.push(opts.commit ? '--commit' : '--no-commit');
|
|
2329
|
-
}
|
|
2330
|
-
if (opts?.cleanup) {
|
|
2331
|
-
args.push(`--cleanup=${opts.cleanup}`);
|
|
2332
|
-
}
|
|
2333
|
-
if (opts?.verify !== undefined) {
|
|
2334
|
-
args.push(opts.verify ? '--verify' : '--no-verify');
|
|
2335
|
-
}
|
|
2336
|
-
if (opts?.verifySignatures) {
|
|
2337
|
-
args.push('--verify-signatures');
|
|
2338
|
-
}
|
|
2339
|
-
if (opts?.autostash) {
|
|
2340
|
-
args.push('--autostash');
|
|
2341
|
-
}
|
|
2342
|
-
if (opts?.strategy) {
|
|
2343
|
-
args.push(`--strategy=${opts.strategy}`);
|
|
2344
|
-
}
|
|
2345
|
-
if (opts?.strategyOption) {
|
|
2346
|
-
const strategyOpts = Array.isArray(opts.strategyOption)
|
|
2347
|
-
? opts.strategyOption
|
|
2348
|
-
: [opts.strategyOption];
|
|
2349
|
-
for (const opt of strategyOpts) {
|
|
2350
|
-
args.push('-X', opt);
|
|
2351
|
-
}
|
|
2352
|
-
}
|
|
2353
|
-
if (opts?.gpgSign !== undefined) {
|
|
2354
|
-
if (opts.gpgSign === true) {
|
|
2355
|
-
args.push('-S');
|
|
2356
|
-
}
|
|
2357
|
-
else if (typeof opts.gpgSign === 'string') {
|
|
2358
|
-
args.push(`-S${opts.gpgSign}`);
|
|
2359
|
-
}
|
|
2360
|
-
}
|
|
2361
|
-
if (opts?.allowUnrelatedHistories) {
|
|
2362
|
-
args.push('--allow-unrelated-histories');
|
|
2363
|
-
}
|
|
2364
|
-
if (opts?.all) {
|
|
2365
|
-
args.push('--all');
|
|
2366
|
-
}
|
|
2367
|
-
if (opts?.append) {
|
|
2368
|
-
args.push('--append');
|
|
2369
|
-
}
|
|
2370
|
-
if (opts?.force) {
|
|
2371
|
-
args.push('--force');
|
|
2372
|
-
}
|
|
2373
|
-
if (opts?.jobs !== undefined) {
|
|
2374
|
-
args.push(`--jobs=${opts.jobs}`);
|
|
2375
|
-
}
|
|
2376
|
-
if (opts?.dryRun) {
|
|
2377
|
-
args.push('--dry-run');
|
|
2378
|
-
}
|
|
2379
|
-
if (opts?.keep) {
|
|
2380
|
-
args.push('--keep');
|
|
2381
|
-
}
|
|
2382
|
-
if (opts?.depth !== undefined) {
|
|
2383
|
-
args.push(`--depth=${opts.depth}`);
|
|
2384
|
-
}
|
|
2385
|
-
if (opts?.shallowSince) {
|
|
2386
|
-
const since = opts.shallowSince instanceof Date ? opts.shallowSince.toISOString() : opts.shallowSince;
|
|
2387
|
-
args.push(`--shallow-since=${since}`);
|
|
2388
|
-
}
|
|
2389
|
-
if (opts?.shallowExclude) {
|
|
2390
|
-
const excludes = Array.isArray(opts.shallowExclude)
|
|
2391
|
-
? opts.shallowExclude
|
|
2392
|
-
: [opts.shallowExclude];
|
|
2393
|
-
for (const exclude of excludes) {
|
|
2394
|
-
args.push(`--shallow-exclude=${exclude}`);
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
|
-
if (opts?.deepen !== undefined) {
|
|
2398
|
-
args.push(`--deepen=${opts.deepen}`);
|
|
2399
|
-
}
|
|
2400
|
-
if (opts?.unshallow) {
|
|
2401
|
-
args.push('--unshallow');
|
|
2402
|
-
}
|
|
2403
|
-
if (opts?.updateShallow) {
|
|
2404
|
-
args.push('--update-shallow');
|
|
2405
|
-
}
|
|
2406
|
-
if (opts?.ipv4) {
|
|
2407
|
-
args.push('--ipv4');
|
|
2408
|
-
}
|
|
2409
|
-
if (opts?.ipv6) {
|
|
2410
|
-
args.push('--ipv6');
|
|
2411
|
-
}
|
|
2412
|
-
if (opts?.setUpstream) {
|
|
2413
|
-
args.push('--set-upstream');
|
|
2414
|
-
}
|
|
2415
|
-
// Remote and branch (must be last)
|
|
2416
|
-
if (opts?.remote) {
|
|
2417
|
-
args.push(opts.remote);
|
|
2418
|
-
}
|
|
2419
|
-
if (opts?.branch) {
|
|
2420
|
-
args.push(opts.branch);
|
|
2421
|
-
}
|
|
2422
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2423
|
-
signal: opts?.signal,
|
|
2424
|
-
onProgress: opts?.onProgress,
|
|
2425
|
-
});
|
|
2426
|
-
}
|
|
2427
|
-
// ==========================================================================
|
|
2428
|
-
// High-level API - reset
|
|
2429
|
-
// ==========================================================================
|
|
2430
|
-
async reset(target, opts) {
|
|
2431
|
-
const args = ['reset'];
|
|
2432
|
-
// Existing options
|
|
2433
|
-
if (opts?.mode) {
|
|
2434
|
-
args.push(`--${opts.mode}`);
|
|
2435
|
-
}
|
|
2436
|
-
// New options
|
|
2437
|
-
if (opts?.quiet) {
|
|
2438
|
-
args.push('--quiet');
|
|
2439
|
-
}
|
|
2440
|
-
if (opts?.noRefresh) {
|
|
2441
|
-
args.push('--no-refresh');
|
|
2442
|
-
}
|
|
2443
|
-
if (opts?.recurseSubmodules) {
|
|
2444
|
-
args.push('--recurse-submodules');
|
|
2445
|
-
}
|
|
2446
|
-
if (opts?.intentToAdd) {
|
|
2447
|
-
args.push('--intent-to-add');
|
|
2448
|
-
}
|
|
2449
|
-
if (opts?.pathspecFromFile) {
|
|
2450
|
-
args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
|
|
2451
|
-
}
|
|
2452
|
-
if (target) {
|
|
2453
|
-
args.push(target);
|
|
2454
|
-
}
|
|
2455
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2456
|
-
signal: opts?.signal,
|
|
2457
|
-
});
|
|
2458
|
-
}
|
|
2459
|
-
// ==========================================================================
|
|
2460
|
-
// High-level API - rm
|
|
2461
|
-
// ==========================================================================
|
|
2462
|
-
async rm(paths, opts) {
|
|
2463
|
-
const args = ['rm'];
|
|
2464
|
-
// Existing options
|
|
2465
|
-
if (opts?.force) {
|
|
2466
|
-
args.push('--force');
|
|
2467
|
-
}
|
|
2468
|
-
if (opts?.cached) {
|
|
2469
|
-
args.push('--cached');
|
|
2470
|
-
}
|
|
2471
|
-
if (opts?.recursive) {
|
|
2472
|
-
args.push('-r');
|
|
2473
|
-
}
|
|
2474
|
-
if (opts?.dryRun) {
|
|
2475
|
-
args.push('--dry-run');
|
|
2476
|
-
}
|
|
2477
|
-
// New options
|
|
2478
|
-
if (opts?.quiet) {
|
|
2479
|
-
args.push('--quiet');
|
|
2480
|
-
}
|
|
2481
|
-
if (opts?.ignoreUnmatch) {
|
|
2482
|
-
args.push('--ignore-unmatch');
|
|
2483
|
-
}
|
|
2484
|
-
if (opts?.sparse) {
|
|
2485
|
-
args.push('--sparse');
|
|
2486
|
-
}
|
|
2487
|
-
if (opts?.pathspecFromFile) {
|
|
2488
|
-
args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
|
|
2489
|
-
}
|
|
2490
|
-
const pathList = Array.isArray(paths) ? paths : [paths];
|
|
2491
|
-
args.push('--', ...pathList);
|
|
2492
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2493
|
-
signal: opts?.signal,
|
|
2494
|
-
});
|
|
2495
|
-
}
|
|
2496
|
-
// ==========================================================================
|
|
2497
|
-
// High-level API - Stash Operations
|
|
2498
|
-
// ==========================================================================
|
|
2499
|
-
async stashList(opts) {
|
|
2500
|
-
const result = await this.runner.runOrThrow(this.context, ['stash', 'list'], {
|
|
2501
|
-
signal: opts?.signal,
|
|
2502
|
-
});
|
|
2503
|
-
const entries = [];
|
|
2504
|
-
for (const line of parseLines(result.stdout)) {
|
|
2505
|
-
// Default format: stash@{0}: On branch: message
|
|
2506
|
-
// Or: stash@{0}: WIP on branch: hash (when using -m)
|
|
2507
|
-
const match = line.match(/^stash@\{(\d+)\}:\s*(?:On\s+)?(.+?):\s*(.+)$/);
|
|
2508
|
-
const indexStr = match?.[1];
|
|
2509
|
-
const branchOrContext = match?.[2];
|
|
2510
|
-
const message = match?.[3];
|
|
2511
|
-
if (indexStr !== undefined && message !== undefined) {
|
|
2512
|
-
// Check if branchOrContext includes "WIP on" format
|
|
2513
|
-
const wipMatch = branchOrContext?.match(/^WIP on (.+)$/);
|
|
2514
|
-
entries.push({
|
|
2515
|
-
index: Number.parseInt(indexStr, 10),
|
|
2516
|
-
message,
|
|
2517
|
-
branch: wipMatch?.[1] ?? branchOrContext,
|
|
2518
|
-
commit: '', // We'd need another command to get the commit hash
|
|
2519
|
-
});
|
|
2520
|
-
}
|
|
2521
|
-
}
|
|
2522
|
-
// Get commit hashes if entries were found
|
|
2523
|
-
if (entries.length > 0) {
|
|
2524
|
-
for (const entry of entries) {
|
|
2525
|
-
try {
|
|
2526
|
-
const hashResult = await this.runner.runOrThrow(this.context, ['rev-parse', `stash@{${entry.index}}`], { signal: opts?.signal });
|
|
2527
|
-
entry.commit = hashResult.stdout.trim();
|
|
2528
|
-
}
|
|
2529
|
-
catch {
|
|
2530
|
-
// Ignore errors getting commit hash
|
|
2531
|
-
}
|
|
2532
|
-
}
|
|
2533
|
-
}
|
|
2534
|
-
return entries;
|
|
2535
|
-
}
|
|
2536
|
-
async stashPush(opts) {
|
|
2537
|
-
const args = ['stash', 'push'];
|
|
2538
|
-
// Existing options
|
|
2539
|
-
if (opts?.message) {
|
|
2540
|
-
args.push('-m', opts.message);
|
|
2541
|
-
}
|
|
2542
|
-
if (opts?.includeUntracked) {
|
|
2543
|
-
args.push('--include-untracked');
|
|
2544
|
-
}
|
|
2545
|
-
if (opts?.keepIndex) {
|
|
2546
|
-
args.push('--keep-index');
|
|
2547
|
-
}
|
|
2548
|
-
// New options
|
|
2549
|
-
if (opts?.staged) {
|
|
2550
|
-
args.push('--staged');
|
|
2551
|
-
}
|
|
2552
|
-
if (opts?.quiet) {
|
|
2553
|
-
args.push('--quiet');
|
|
2554
|
-
}
|
|
2555
|
-
if (opts?.all) {
|
|
2556
|
-
args.push('--all');
|
|
2557
|
-
}
|
|
2558
|
-
if (opts?.pathspecFromFile) {
|
|
2559
|
-
args.push(`--pathspec-from-file=${opts.pathspecFromFile}`);
|
|
2560
|
-
}
|
|
2561
|
-
if (opts?.paths && opts.paths.length > 0) {
|
|
2562
|
-
args.push('--', ...opts.paths);
|
|
2563
|
-
}
|
|
2564
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2565
|
-
signal: opts?.signal,
|
|
2566
|
-
});
|
|
2567
|
-
}
|
|
2568
|
-
async stashPop(opts) {
|
|
2569
|
-
const args = ['stash', 'pop'];
|
|
2570
|
-
if (opts?.reinstateIndex) {
|
|
2571
|
-
args.push('--index');
|
|
2572
|
-
}
|
|
2573
|
-
if (opts?.index !== undefined) {
|
|
2574
|
-
args.push(`stash@{${opts.index}}`);
|
|
2575
|
-
}
|
|
2576
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2577
|
-
signal: opts?.signal,
|
|
2578
|
-
});
|
|
2579
|
-
}
|
|
2580
|
-
async stashApply(opts) {
|
|
2581
|
-
const args = ['stash', 'apply'];
|
|
2582
|
-
if (opts?.reinstateIndex) {
|
|
2583
|
-
args.push('--index');
|
|
2584
|
-
}
|
|
2585
|
-
if (opts?.index !== undefined) {
|
|
2586
|
-
args.push(`stash@{${opts.index}}`);
|
|
2587
|
-
}
|
|
2588
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2589
|
-
signal: opts?.signal,
|
|
2590
|
-
});
|
|
2591
|
-
}
|
|
2592
|
-
async stashDrop(index, opts) {
|
|
2593
|
-
const args = ['stash', 'drop'];
|
|
2594
|
-
if (index !== undefined) {
|
|
2595
|
-
args.push(`stash@{${index}}`);
|
|
2596
|
-
}
|
|
2597
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2598
|
-
signal: opts?.signal,
|
|
2599
|
-
});
|
|
2600
|
-
}
|
|
2601
|
-
async stashClear(opts) {
|
|
2602
|
-
await this.runner.runOrThrow(this.context, ['stash', 'clear'], {
|
|
2603
|
-
signal: opts?.signal,
|
|
2604
|
-
});
|
|
2605
|
-
}
|
|
2606
|
-
// ==========================================================================
|
|
2607
|
-
// High-level API - switch
|
|
2608
|
-
// ==========================================================================
|
|
2609
|
-
async switch(branch, opts) {
|
|
2610
|
-
const args = ['switch'];
|
|
2611
|
-
// Existing options
|
|
2612
|
-
if (opts?.create) {
|
|
2613
|
-
args.push('-c');
|
|
2614
|
-
}
|
|
2615
|
-
else if (opts?.forceCreate) {
|
|
2616
|
-
args.push('-C');
|
|
2617
|
-
}
|
|
2618
|
-
if (opts?.discard) {
|
|
2619
|
-
args.push('--discard-changes');
|
|
2620
|
-
}
|
|
2621
|
-
if (opts?.track) {
|
|
2622
|
-
args.push('--track');
|
|
2623
|
-
}
|
|
2624
|
-
if (opts?.detach) {
|
|
2625
|
-
args.push('--detach');
|
|
2626
|
-
}
|
|
2627
|
-
// New options
|
|
2628
|
-
if (opts?.guess !== undefined) {
|
|
2629
|
-
args.push(opts.guess ? '--guess' : '--no-guess');
|
|
2630
|
-
}
|
|
2631
|
-
if (opts?.quiet) {
|
|
2632
|
-
args.push('--quiet');
|
|
2633
|
-
}
|
|
2634
|
-
if (opts?.recurseSubmodules) {
|
|
2635
|
-
args.push('--recurse-submodules');
|
|
2636
|
-
}
|
|
2637
|
-
if (opts?.merge) {
|
|
2638
|
-
args.push('--merge');
|
|
2639
|
-
}
|
|
2640
|
-
if (opts?.conflict) {
|
|
2641
|
-
args.push(`--conflict=${opts.conflict}`);
|
|
2642
|
-
}
|
|
2643
|
-
if (opts?.force) {
|
|
2644
|
-
args.push('--force');
|
|
2645
|
-
}
|
|
2646
|
-
if (opts?.orphan) {
|
|
2647
|
-
args.push('--orphan');
|
|
2648
|
-
}
|
|
2649
|
-
if (opts?.overwriteIgnore === false) {
|
|
2650
|
-
args.push('--no-overwrite-ignore');
|
|
2651
|
-
}
|
|
2652
|
-
if (opts?.ignoreOtherWorktrees) {
|
|
2653
|
-
args.push('--ignore-other-worktrees');
|
|
2654
|
-
}
|
|
2655
|
-
args.push(branch);
|
|
2656
|
-
if (opts?.startPoint) {
|
|
2657
|
-
args.push(opts.startPoint);
|
|
2658
|
-
}
|
|
2659
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2660
|
-
signal: opts?.signal,
|
|
2661
|
-
});
|
|
2662
|
-
}
|
|
2663
|
-
// ==========================================================================
|
|
2664
|
-
// High-level API - Tag Operations
|
|
2665
|
-
// ==========================================================================
|
|
2666
|
-
async tagList(opts) {
|
|
2667
|
-
const args = ['tag', '--list'];
|
|
2668
|
-
// Existing options
|
|
2669
|
-
if (opts?.sort) {
|
|
2670
|
-
args.push(`--sort=${opts.sort}`);
|
|
2671
|
-
}
|
|
2672
|
-
// New options
|
|
2673
|
-
if (opts?.lines !== undefined) {
|
|
2674
|
-
args.push(`-n${opts.lines}`);
|
|
2675
|
-
}
|
|
2676
|
-
if (opts?.contains) {
|
|
2677
|
-
args.push(`--contains=${opts.contains}`);
|
|
2678
|
-
}
|
|
2679
|
-
if (opts?.noContains) {
|
|
2680
|
-
args.push(`--no-contains=${opts.noContains}`);
|
|
2681
|
-
}
|
|
2682
|
-
if (opts?.merged) {
|
|
2683
|
-
args.push(`--merged=${opts.merged}`);
|
|
2684
|
-
}
|
|
2685
|
-
if (opts?.noMerged) {
|
|
2686
|
-
args.push(`--no-merged=${opts.noMerged}`);
|
|
2687
|
-
}
|
|
2688
|
-
if (opts?.pointsAt) {
|
|
2689
|
-
args.push(`--points-at=${opts.pointsAt}`);
|
|
2690
|
-
}
|
|
2691
|
-
if (opts?.ignoreCase) {
|
|
2692
|
-
args.push('--ignore-case');
|
|
2693
|
-
}
|
|
2694
|
-
if (opts?.pattern) {
|
|
2695
|
-
args.push(opts.pattern);
|
|
2696
|
-
}
|
|
2697
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2698
|
-
signal: opts?.signal,
|
|
2699
|
-
});
|
|
2700
|
-
return parseLines(result.stdout);
|
|
2701
|
-
}
|
|
2702
|
-
async tagCreate(name, opts) {
|
|
2703
|
-
const args = ['tag'];
|
|
2704
|
-
// Existing options
|
|
2705
|
-
if (opts?.sign) {
|
|
2706
|
-
args.push('-s');
|
|
2707
|
-
}
|
|
2708
|
-
if (opts?.message) {
|
|
2709
|
-
// If signing with -s, we don't need -a (signed tags are always annotated)
|
|
2710
|
-
if (!opts.sign) {
|
|
2711
|
-
args.push('-a');
|
|
2712
|
-
}
|
|
2713
|
-
args.push('-m', opts.message);
|
|
2714
|
-
}
|
|
2715
|
-
if (opts?.force) {
|
|
2716
|
-
args.push('--force');
|
|
2717
|
-
}
|
|
2718
|
-
// New options
|
|
2719
|
-
if (opts?.file) {
|
|
2720
|
-
// If using file, we need -a for annotated tag (unless signing)
|
|
2721
|
-
if (!(opts.sign || opts.message)) {
|
|
2722
|
-
args.push('-a');
|
|
2723
|
-
}
|
|
2724
|
-
args.push('--file', opts.file);
|
|
2725
|
-
}
|
|
2726
|
-
if (opts?.trailer) {
|
|
2727
|
-
const trailers = Array.isArray(opts.trailer) ? opts.trailer : [opts.trailer];
|
|
2728
|
-
for (const trailer of trailers) {
|
|
2729
|
-
args.push('--trailer', trailer);
|
|
2730
|
-
}
|
|
2731
|
-
}
|
|
2732
|
-
if (opts?.cleanup) {
|
|
2733
|
-
args.push(`--cleanup=${opts.cleanup}`);
|
|
2734
|
-
}
|
|
2735
|
-
if (opts?.localUser) {
|
|
2736
|
-
args.push(`--local-user=${opts.localUser}`);
|
|
2737
|
-
}
|
|
2738
|
-
if (opts?.createReflog) {
|
|
2739
|
-
args.push('--create-reflog');
|
|
2740
|
-
}
|
|
2741
|
-
args.push(name);
|
|
2742
|
-
if (opts?.commit) {
|
|
2743
|
-
args.push(opts.commit);
|
|
2744
|
-
}
|
|
2745
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2746
|
-
signal: opts?.signal,
|
|
2747
|
-
});
|
|
2748
|
-
}
|
|
2749
|
-
async tagDelete(name, opts) {
|
|
2750
|
-
await this.runner.runOrThrow(this.context, ['tag', '-d', name], {
|
|
2751
|
-
signal: opts?.signal,
|
|
2752
|
-
});
|
|
2753
|
-
}
|
|
2754
|
-
async tagShow(name, opts) {
|
|
2755
|
-
// Try to get tag info using cat-file
|
|
2756
|
-
const typeResult = await this.runner.runOrThrow(this.context, ['cat-file', '-t', name], {
|
|
2757
|
-
signal: opts?.signal,
|
|
2758
|
-
});
|
|
2759
|
-
const isAnnotated = typeResult.stdout.trim() === 'tag';
|
|
2760
|
-
if (isAnnotated) {
|
|
2761
|
-
const result = await this.runner.runOrThrow(this.context, ['cat-file', 'tag', name], {
|
|
2762
|
-
signal: opts?.signal,
|
|
2763
|
-
});
|
|
2764
|
-
const lines = result.stdout.split('\n');
|
|
2765
|
-
let commit = '';
|
|
2766
|
-
let taggerName = '';
|
|
2767
|
-
let taggerEmail = '';
|
|
2768
|
-
let taggerDate;
|
|
2769
|
-
const messageLines = [];
|
|
2770
|
-
let inMessage = false;
|
|
2771
|
-
for (const line of lines) {
|
|
2772
|
-
if (line.startsWith('object ')) {
|
|
2773
|
-
commit = line.slice(7);
|
|
2774
|
-
}
|
|
2775
|
-
else if (line.startsWith('tagger ')) {
|
|
2776
|
-
const match = line.match(/^tagger (.+?) <(.+?)> (\d+)/);
|
|
2777
|
-
if (match) {
|
|
2778
|
-
const matchedName = match[1];
|
|
2779
|
-
const matchedEmail = match[2];
|
|
2780
|
-
const matchedTimestamp = match[3];
|
|
2781
|
-
if (matchedName !== undefined &&
|
|
2782
|
-
matchedEmail !== undefined &&
|
|
2783
|
-
matchedTimestamp !== undefined) {
|
|
2784
|
-
taggerName = matchedName;
|
|
2785
|
-
taggerEmail = matchedEmail;
|
|
2786
|
-
taggerDate = new Date(Number.parseInt(matchedTimestamp, 10) * 1000);
|
|
2787
|
-
}
|
|
2788
|
-
}
|
|
2789
|
-
}
|
|
2790
|
-
else if (line === '') {
|
|
2791
|
-
inMessage = true;
|
|
2792
|
-
}
|
|
2793
|
-
else if (inMessage) {
|
|
2794
|
-
messageLines.push(line);
|
|
2795
|
-
}
|
|
2796
|
-
}
|
|
2797
|
-
return {
|
|
2798
|
-
name,
|
|
2799
|
-
commit,
|
|
2800
|
-
annotated: true,
|
|
2801
|
-
message: messageLines.join('\n').trim() || undefined,
|
|
2802
|
-
tagger: taggerName && taggerDate
|
|
2803
|
-
? {
|
|
2804
|
-
name: taggerName,
|
|
2805
|
-
email: taggerEmail,
|
|
2806
|
-
date: taggerDate,
|
|
2807
|
-
}
|
|
2808
|
-
: undefined,
|
|
2809
|
-
};
|
|
2810
|
-
}
|
|
2811
|
-
else {
|
|
2812
|
-
// Lightweight tag - get the commit it points to
|
|
2813
|
-
const result = await this.runner.runOrThrow(this.context, ['rev-parse', name], {
|
|
2814
|
-
signal: opts?.signal,
|
|
2815
|
-
});
|
|
2816
|
-
return {
|
|
2817
|
-
name,
|
|
2818
|
-
commit: result.stdout.trim(),
|
|
2819
|
-
annotated: false,
|
|
2820
|
-
};
|
|
2821
|
-
}
|
|
2822
|
-
}
|
|
2823
|
-
// ==========================================================================
|
|
2824
|
-
// Medium Priority - cherry-pick
|
|
2825
|
-
// ==========================================================================
|
|
2826
|
-
async cherryPick(commits, opts) {
|
|
2827
|
-
if (opts?.abort) {
|
|
2828
|
-
await this.runner.runOrThrow(this.context, ['cherry-pick', '--abort'], {
|
|
2829
|
-
signal: opts?.signal,
|
|
2830
|
-
});
|
|
2831
|
-
return;
|
|
2832
|
-
}
|
|
2833
|
-
if (opts?.continue) {
|
|
2834
|
-
await this.runner.runOrThrow(this.context, ['cherry-pick', '--continue'], {
|
|
2835
|
-
signal: opts?.signal,
|
|
2836
|
-
});
|
|
2837
|
-
return;
|
|
2838
|
-
}
|
|
2839
|
-
if (opts?.skip) {
|
|
2840
|
-
await this.runner.runOrThrow(this.context, ['cherry-pick', '--skip'], {
|
|
2841
|
-
signal: opts?.signal,
|
|
2842
|
-
});
|
|
2843
|
-
return;
|
|
2844
|
-
}
|
|
2845
|
-
const args = ['cherry-pick'];
|
|
2846
|
-
if (opts?.edit) {
|
|
2847
|
-
args.push('-e');
|
|
2848
|
-
}
|
|
2849
|
-
if (opts?.noCommit) {
|
|
2850
|
-
args.push('-n');
|
|
2851
|
-
}
|
|
2852
|
-
if (opts?.signoff) {
|
|
2853
|
-
args.push('-s');
|
|
2854
|
-
}
|
|
2855
|
-
if (opts?.mainline !== undefined) {
|
|
2856
|
-
args.push('-m', opts.mainline.toString());
|
|
2857
|
-
}
|
|
2858
|
-
if (opts?.strategy) {
|
|
2859
|
-
args.push('-s', opts.strategy);
|
|
2860
|
-
}
|
|
2861
|
-
if (opts?.noVerify) {
|
|
2862
|
-
args.push('--no-verify');
|
|
2863
|
-
}
|
|
2864
|
-
// New options
|
|
2865
|
-
if (opts?.cleanup) {
|
|
2866
|
-
args.push('--cleanup', opts.cleanup);
|
|
2867
|
-
}
|
|
2868
|
-
if (opts?.rerereAutoupdate === true) {
|
|
2869
|
-
args.push('--rerere-autoupdate');
|
|
2870
|
-
}
|
|
2871
|
-
else if (opts?.rerereAutoupdate === false) {
|
|
2872
|
-
args.push('--no-rerere-autoupdate');
|
|
2873
|
-
}
|
|
2874
|
-
if (opts?.strategyOption) {
|
|
2875
|
-
const strategyOptions = Array.isArray(opts.strategyOption)
|
|
2876
|
-
? opts.strategyOption
|
|
2877
|
-
: [opts.strategyOption];
|
|
2878
|
-
for (const so of strategyOptions) {
|
|
2879
|
-
args.push('-X', so);
|
|
2880
|
-
}
|
|
2881
|
-
}
|
|
2882
|
-
if (opts?.gpgSign === true) {
|
|
2883
|
-
args.push('-S');
|
|
2884
|
-
}
|
|
2885
|
-
else if (typeof opts?.gpgSign === 'string') {
|
|
2886
|
-
args.push(`-S${opts.gpgSign}`);
|
|
2887
|
-
}
|
|
2888
|
-
if (opts?.appendCommitName) {
|
|
2889
|
-
args.push('-x');
|
|
2890
|
-
}
|
|
2891
|
-
if (opts?.ff) {
|
|
2892
|
-
args.push('--ff');
|
|
2893
|
-
}
|
|
2894
|
-
if (opts?.allowEmpty) {
|
|
2895
|
-
args.push('--allow-empty');
|
|
2896
|
-
}
|
|
2897
|
-
if (opts?.allowEmptyMessage) {
|
|
2898
|
-
args.push('--allow-empty-message');
|
|
2899
|
-
}
|
|
2900
|
-
if (opts?.empty) {
|
|
2901
|
-
args.push('--empty', opts.empty);
|
|
2902
|
-
}
|
|
2903
|
-
const commitList = Array.isArray(commits) ? commits : [commits];
|
|
2904
|
-
args.push(...commitList);
|
|
2905
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2906
|
-
signal: opts?.signal,
|
|
2907
|
-
});
|
|
2908
|
-
}
|
|
2909
|
-
// ==========================================================================
|
|
2910
|
-
// Medium Priority - clean
|
|
2911
|
-
// ==========================================================================
|
|
2912
|
-
async clean(opts) {
|
|
2913
|
-
const args = ['clean'];
|
|
2914
|
-
if (opts?.force) {
|
|
2915
|
-
args.push('-f');
|
|
2916
|
-
}
|
|
2917
|
-
if (opts?.directories) {
|
|
2918
|
-
args.push('-d');
|
|
2919
|
-
}
|
|
2920
|
-
if (opts?.ignored) {
|
|
2921
|
-
args.push('-x');
|
|
2922
|
-
}
|
|
2923
|
-
else if (opts?.onlyIgnored) {
|
|
2924
|
-
args.push('-X');
|
|
2925
|
-
}
|
|
2926
|
-
if (opts?.dryRun) {
|
|
2927
|
-
args.push('-n');
|
|
2928
|
-
}
|
|
2929
|
-
// New options
|
|
2930
|
-
if (opts?.quiet) {
|
|
2931
|
-
args.push('-q');
|
|
2932
|
-
}
|
|
2933
|
-
if (opts?.exclude) {
|
|
2934
|
-
const excludes = Array.isArray(opts.exclude) ? opts.exclude : [opts.exclude];
|
|
2935
|
-
for (const pattern of excludes) {
|
|
2936
|
-
args.push('-e', pattern);
|
|
2937
|
-
}
|
|
2938
|
-
}
|
|
2939
|
-
if (opts?.paths && opts.paths.length > 0) {
|
|
2940
|
-
args.push('--', ...opts.paths);
|
|
2941
|
-
}
|
|
2942
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
2943
|
-
signal: opts?.signal,
|
|
2944
|
-
});
|
|
2945
|
-
// Parse cleaned/would-be-cleaned paths from output
|
|
2946
|
-
const cleaned = [];
|
|
2947
|
-
for (const line of parseLines(result.stdout)) {
|
|
2948
|
-
// Output is like "Removing file.txt" or "Would remove file.txt"
|
|
2949
|
-
const match = line.match(/^(?:Removing|Would remove) (.+)$/);
|
|
2950
|
-
const matchedPath = match?.[1];
|
|
2951
|
-
if (matchedPath !== undefined) {
|
|
2952
|
-
cleaned.push(matchedPath);
|
|
2953
|
-
}
|
|
2954
|
-
}
|
|
2955
|
-
return cleaned;
|
|
2956
|
-
}
|
|
2957
|
-
// ==========================================================================
|
|
2958
|
-
// Medium Priority - mv
|
|
2959
|
-
// ==========================================================================
|
|
2960
|
-
async mv(source, destination, opts) {
|
|
2961
|
-
const args = ['mv'];
|
|
2962
|
-
if (opts?.force) {
|
|
2963
|
-
args.push('-f');
|
|
2964
|
-
}
|
|
2965
|
-
if (opts?.dryRun) {
|
|
2966
|
-
args.push('-n');
|
|
2967
|
-
}
|
|
2968
|
-
// New options
|
|
2969
|
-
if (opts?.verbose) {
|
|
2970
|
-
args.push('-v');
|
|
2971
|
-
}
|
|
2972
|
-
if (opts?.skipErrors) {
|
|
2973
|
-
args.push('-k');
|
|
2974
|
-
}
|
|
2975
|
-
if (opts?.sparse) {
|
|
2976
|
-
args.push('--sparse');
|
|
2977
|
-
}
|
|
2978
|
-
args.push(source, destination);
|
|
2979
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
2980
|
-
signal: opts?.signal,
|
|
2981
|
-
});
|
|
2982
|
-
}
|
|
2983
|
-
// ==========================================================================
|
|
2984
|
-
// Medium Priority - rebase
|
|
2985
|
-
// ==========================================================================
|
|
2986
|
-
async rebase(opts) {
|
|
2987
|
-
if (opts?.abort) {
|
|
2988
|
-
await this.runner.runOrThrow(this.context, ['rebase', '--abort'], {
|
|
2989
|
-
signal: opts?.signal,
|
|
2990
|
-
});
|
|
2991
|
-
return;
|
|
2992
|
-
}
|
|
2993
|
-
if (opts?.continue) {
|
|
2994
|
-
await this.runner.runOrThrow(this.context, ['rebase', '--continue'], {
|
|
2995
|
-
signal: opts?.signal,
|
|
2996
|
-
});
|
|
2997
|
-
return;
|
|
2998
|
-
}
|
|
2999
|
-
if (opts?.skip) {
|
|
3000
|
-
await this.runner.runOrThrow(this.context, ['rebase', '--skip'], {
|
|
3001
|
-
signal: opts?.signal,
|
|
3002
|
-
});
|
|
3003
|
-
return;
|
|
3004
|
-
}
|
|
3005
|
-
const args = ['rebase'];
|
|
3006
|
-
if (opts?.onto) {
|
|
3007
|
-
args.push('--onto', opts.onto);
|
|
3008
|
-
}
|
|
3009
|
-
if (opts?.rebaseMerges) {
|
|
3010
|
-
args.push('--rebase-merges');
|
|
3011
|
-
}
|
|
3012
|
-
if (opts?.noVerify) {
|
|
3013
|
-
args.push('--no-verify');
|
|
3014
|
-
}
|
|
3015
|
-
// New options
|
|
3016
|
-
if (opts?.keepBase) {
|
|
3017
|
-
args.push('--keep-base');
|
|
3018
|
-
}
|
|
3019
|
-
if (opts?.quiet) {
|
|
3020
|
-
args.push('--quiet');
|
|
3021
|
-
}
|
|
3022
|
-
if (opts?.verbose) {
|
|
3023
|
-
args.push('--verbose');
|
|
3024
|
-
}
|
|
3025
|
-
if (opts?.signoff) {
|
|
3026
|
-
args.push('--signoff');
|
|
3027
|
-
}
|
|
3028
|
-
if (opts?.committerDateIsAuthorDate) {
|
|
3029
|
-
args.push('--committer-date-is-author-date');
|
|
3030
|
-
}
|
|
3031
|
-
if (opts?.resetAuthorDate) {
|
|
3032
|
-
args.push('--reset-author-date');
|
|
3033
|
-
}
|
|
3034
|
-
if (opts?.ignoreWhitespace) {
|
|
3035
|
-
args.push('--ignore-whitespace');
|
|
3036
|
-
}
|
|
3037
|
-
if (opts?.whitespace) {
|
|
3038
|
-
args.push('--whitespace', opts.whitespace);
|
|
3039
|
-
}
|
|
3040
|
-
if (opts?.forceRebase) {
|
|
3041
|
-
args.push('--force-rebase');
|
|
3042
|
-
}
|
|
3043
|
-
if (opts?.noFf) {
|
|
3044
|
-
args.push('--no-ff');
|
|
3045
|
-
}
|
|
3046
|
-
if (opts?.apply) {
|
|
3047
|
-
args.push('--apply');
|
|
3048
|
-
}
|
|
3049
|
-
if (opts?.rerereAutoupdate === true) {
|
|
3050
|
-
args.push('--rerere-autoupdate');
|
|
3051
|
-
}
|
|
3052
|
-
else if (opts?.rerereAutoupdate === false) {
|
|
3053
|
-
args.push('--no-rerere-autoupdate');
|
|
3054
|
-
}
|
|
3055
|
-
if (opts?.empty) {
|
|
3056
|
-
args.push('--empty', opts.empty);
|
|
3057
|
-
}
|
|
3058
|
-
if (opts?.autosquash === true) {
|
|
3059
|
-
args.push('--autosquash');
|
|
3060
|
-
}
|
|
3061
|
-
else if (opts?.autosquash === false) {
|
|
3062
|
-
args.push('--no-autosquash');
|
|
3063
|
-
}
|
|
3064
|
-
if (opts?.updateRefs === true) {
|
|
3065
|
-
args.push('--update-refs');
|
|
3066
|
-
}
|
|
3067
|
-
else if (opts?.updateRefs === false) {
|
|
3068
|
-
args.push('--no-update-refs');
|
|
3069
|
-
}
|
|
3070
|
-
if (opts?.gpgSign === true) {
|
|
3071
|
-
args.push('-S');
|
|
3072
|
-
}
|
|
3073
|
-
else if (typeof opts?.gpgSign === 'string') {
|
|
3074
|
-
args.push(`-S${opts.gpgSign}`);
|
|
3075
|
-
}
|
|
3076
|
-
if (opts?.autostash === true) {
|
|
3077
|
-
args.push('--autostash');
|
|
3078
|
-
}
|
|
3079
|
-
else if (opts?.autostash === false) {
|
|
3080
|
-
args.push('--no-autostash');
|
|
3081
|
-
}
|
|
3082
|
-
if (opts?.exec) {
|
|
3083
|
-
const execs = Array.isArray(opts.exec) ? opts.exec : [opts.exec];
|
|
3084
|
-
for (const cmd of execs) {
|
|
3085
|
-
args.push('--exec', cmd);
|
|
3086
|
-
}
|
|
3087
|
-
}
|
|
3088
|
-
if (opts?.forkPoint === true) {
|
|
3089
|
-
args.push('--fork-point');
|
|
3090
|
-
}
|
|
3091
|
-
else if (opts?.forkPoint === false) {
|
|
3092
|
-
args.push('--no-fork-point');
|
|
3093
|
-
}
|
|
3094
|
-
if (opts?.strategy) {
|
|
3095
|
-
args.push('--strategy', opts.strategy);
|
|
3096
|
-
}
|
|
3097
|
-
if (opts?.strategyOption) {
|
|
3098
|
-
const strategyOptions = Array.isArray(opts.strategyOption)
|
|
3099
|
-
? opts.strategyOption
|
|
3100
|
-
: [opts.strategyOption];
|
|
3101
|
-
for (const so of strategyOptions) {
|
|
3102
|
-
args.push('-X', so);
|
|
3103
|
-
}
|
|
3104
|
-
}
|
|
3105
|
-
if (opts?.root) {
|
|
3106
|
-
args.push('--root');
|
|
3107
|
-
}
|
|
3108
|
-
if (opts?.rescheduleFailedExec === true) {
|
|
3109
|
-
args.push('--reschedule-failed-exec');
|
|
3110
|
-
}
|
|
3111
|
-
else if (opts?.rescheduleFailedExec === false) {
|
|
3112
|
-
args.push('--no-reschedule-failed-exec');
|
|
3113
|
-
}
|
|
3114
|
-
if (opts?.reapplyCherryPicks === true) {
|
|
3115
|
-
args.push('--reapply-cherry-picks');
|
|
3116
|
-
}
|
|
3117
|
-
else if (opts?.reapplyCherryPicks === false) {
|
|
3118
|
-
args.push('--no-reapply-cherry-picks');
|
|
3119
|
-
}
|
|
3120
|
-
if (opts?.upstream) {
|
|
3121
|
-
args.push(opts.upstream);
|
|
3122
|
-
}
|
|
3123
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3124
|
-
signal: opts?.signal,
|
|
3125
|
-
});
|
|
3126
|
-
}
|
|
3127
|
-
// ==========================================================================
|
|
3128
|
-
// Medium Priority - restore
|
|
3129
|
-
// ==========================================================================
|
|
3130
|
-
async restore(paths, opts) {
|
|
3131
|
-
const args = ['restore'];
|
|
3132
|
-
if (opts?.staged) {
|
|
3133
|
-
args.push('--staged');
|
|
3134
|
-
}
|
|
3135
|
-
if (opts?.worktree) {
|
|
3136
|
-
args.push('--worktree');
|
|
3137
|
-
}
|
|
3138
|
-
if (opts?.source) {
|
|
3139
|
-
args.push('--source', opts.source);
|
|
3140
|
-
}
|
|
3141
|
-
if (opts?.ours) {
|
|
3142
|
-
args.push('--ours');
|
|
3143
|
-
}
|
|
3144
|
-
else if (opts?.theirs) {
|
|
3145
|
-
args.push('--theirs');
|
|
3146
|
-
}
|
|
3147
|
-
// New options
|
|
3148
|
-
if (opts?.ignoreUnmerged) {
|
|
3149
|
-
args.push('--ignore-unmerged');
|
|
3150
|
-
}
|
|
3151
|
-
if (opts?.overlay === true) {
|
|
3152
|
-
args.push('--overlay');
|
|
3153
|
-
}
|
|
3154
|
-
else if (opts?.overlay === false) {
|
|
3155
|
-
args.push('--no-overlay');
|
|
3156
|
-
}
|
|
3157
|
-
if (opts?.quiet) {
|
|
3158
|
-
args.push('--quiet');
|
|
3159
|
-
}
|
|
3160
|
-
if (opts?.recurseSubmodules === true) {
|
|
3161
|
-
args.push('--recurse-submodules');
|
|
3162
|
-
}
|
|
3163
|
-
else if (opts?.recurseSubmodules === false) {
|
|
3164
|
-
args.push('--no-recurse-submodules');
|
|
3165
|
-
}
|
|
3166
|
-
if (opts?.progress === true) {
|
|
3167
|
-
args.push('--progress');
|
|
3168
|
-
}
|
|
3169
|
-
else if (opts?.progress === false) {
|
|
3170
|
-
args.push('--no-progress');
|
|
3171
|
-
}
|
|
3172
|
-
if (opts?.merge) {
|
|
3173
|
-
args.push('--merge');
|
|
3174
|
-
}
|
|
3175
|
-
if (opts?.conflict) {
|
|
3176
|
-
args.push('--conflict', opts.conflict);
|
|
3177
|
-
}
|
|
3178
|
-
if (opts?.ignoreSkipWorktreeBits) {
|
|
3179
|
-
args.push('--ignore-skip-worktree-bits');
|
|
3180
|
-
}
|
|
3181
|
-
if (opts?.pathspecFromFile) {
|
|
3182
|
-
args.push('--pathspec-from-file', opts.pathspecFromFile);
|
|
3183
|
-
}
|
|
3184
|
-
const pathList = Array.isArray(paths) ? paths : [paths];
|
|
3185
|
-
args.push('--', ...pathList);
|
|
3186
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3187
|
-
signal: opts?.signal,
|
|
3188
|
-
});
|
|
3189
|
-
}
|
|
3190
|
-
// ==========================================================================
|
|
3191
|
-
// Medium Priority - revert
|
|
3192
|
-
// ==========================================================================
|
|
3193
|
-
async revert(commits, opts) {
|
|
3194
|
-
if (opts?.abort) {
|
|
3195
|
-
await this.runner.runOrThrow(this.context, ['revert', '--abort'], {
|
|
3196
|
-
signal: opts?.signal,
|
|
3197
|
-
});
|
|
3198
|
-
return;
|
|
3199
|
-
}
|
|
3200
|
-
if (opts?.continue) {
|
|
3201
|
-
await this.runner.runOrThrow(this.context, ['revert', '--continue'], {
|
|
3202
|
-
signal: opts?.signal,
|
|
3203
|
-
});
|
|
3204
|
-
return;
|
|
3205
|
-
}
|
|
3206
|
-
if (opts?.skip) {
|
|
3207
|
-
await this.runner.runOrThrow(this.context, ['revert', '--skip'], {
|
|
3208
|
-
signal: opts?.signal,
|
|
3209
|
-
});
|
|
3210
|
-
return;
|
|
3211
|
-
}
|
|
3212
|
-
const args = ['revert'];
|
|
3213
|
-
if (opts?.edit) {
|
|
3214
|
-
args.push('-e');
|
|
3215
|
-
}
|
|
3216
|
-
if (opts?.noCommit) {
|
|
3217
|
-
args.push('-n');
|
|
3218
|
-
}
|
|
3219
|
-
if (opts?.mainline !== undefined) {
|
|
3220
|
-
args.push('-m', opts.mainline.toString());
|
|
3221
|
-
}
|
|
3222
|
-
if (opts?.noVerify) {
|
|
3223
|
-
args.push('--no-verify');
|
|
3224
|
-
}
|
|
3225
|
-
// New options
|
|
3226
|
-
if (opts?.cleanup) {
|
|
3227
|
-
args.push('--cleanup', opts.cleanup);
|
|
3228
|
-
}
|
|
3229
|
-
if (opts?.signoff) {
|
|
3230
|
-
args.push('--signoff');
|
|
3231
|
-
}
|
|
3232
|
-
if (opts?.rerereAutoupdate === true) {
|
|
3233
|
-
args.push('--rerere-autoupdate');
|
|
3234
|
-
}
|
|
3235
|
-
else if (opts?.rerereAutoupdate === false) {
|
|
3236
|
-
args.push('--no-rerere-autoupdate');
|
|
3237
|
-
}
|
|
3238
|
-
if (opts?.strategy) {
|
|
3239
|
-
args.push('--strategy', opts.strategy);
|
|
3240
|
-
}
|
|
3241
|
-
if (opts?.strategyOption) {
|
|
3242
|
-
const strategyOptions = Array.isArray(opts.strategyOption)
|
|
3243
|
-
? opts.strategyOption
|
|
3244
|
-
: [opts.strategyOption];
|
|
3245
|
-
for (const so of strategyOptions) {
|
|
3246
|
-
args.push('-X', so);
|
|
3247
|
-
}
|
|
3248
|
-
}
|
|
3249
|
-
if (opts?.gpgSign === true) {
|
|
3250
|
-
args.push('-S');
|
|
3251
|
-
}
|
|
3252
|
-
else if (typeof opts?.gpgSign === 'string') {
|
|
3253
|
-
args.push(`-S${opts.gpgSign}`);
|
|
3254
|
-
}
|
|
3255
|
-
if (opts?.reference) {
|
|
3256
|
-
args.push('--reference');
|
|
3257
|
-
}
|
|
3258
|
-
const commitList = Array.isArray(commits) ? commits : [commits];
|
|
3259
|
-
args.push(...commitList);
|
|
3260
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3261
|
-
signal: opts?.signal,
|
|
3262
|
-
});
|
|
3263
|
-
}
|
|
3264
|
-
// ==========================================================================
|
|
3265
|
-
// Medium Priority - show
|
|
3266
|
-
// ==========================================================================
|
|
3267
|
-
async show(object, opts) {
|
|
3268
|
-
const args = ['show'];
|
|
3269
|
-
if (opts?.stat) {
|
|
3270
|
-
args.push('--stat');
|
|
3271
|
-
}
|
|
3272
|
-
if (opts?.nameOnly) {
|
|
3273
|
-
args.push('--name-only');
|
|
3274
|
-
}
|
|
3275
|
-
else if (opts?.nameStatus) {
|
|
3276
|
-
args.push('--name-status');
|
|
3277
|
-
}
|
|
3278
|
-
if (opts?.format) {
|
|
3279
|
-
args.push(`--format=${opts.format}`);
|
|
3280
|
-
}
|
|
3281
|
-
// New options
|
|
3282
|
-
if (opts?.quiet) {
|
|
3283
|
-
args.push('--quiet');
|
|
3284
|
-
}
|
|
3285
|
-
if (opts?.source) {
|
|
3286
|
-
args.push('--source');
|
|
3287
|
-
}
|
|
3288
|
-
if (opts?.useMailmap) {
|
|
3289
|
-
args.push('--use-mailmap');
|
|
3290
|
-
}
|
|
3291
|
-
if (opts?.decorateRefs) {
|
|
3292
|
-
args.push('--decorate-refs', opts.decorateRefs);
|
|
3293
|
-
}
|
|
3294
|
-
if (opts?.decorateRefsExclude) {
|
|
3295
|
-
args.push('--decorate-refs-exclude', opts.decorateRefsExclude);
|
|
3296
|
-
}
|
|
3297
|
-
if (opts?.decorate) {
|
|
3298
|
-
args.push(`--decorate=${opts.decorate}`);
|
|
3299
|
-
}
|
|
3300
|
-
args.push(object);
|
|
3301
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3302
|
-
signal: opts?.signal,
|
|
3303
|
-
});
|
|
3304
|
-
return result.stdout;
|
|
3305
|
-
}
|
|
3306
|
-
// ==========================================================================
|
|
3307
|
-
// Plumbing Operations
|
|
3308
|
-
// ==========================================================================
|
|
3309
|
-
/**
|
|
3310
|
-
* Parse revision specification and return the object name (SHA)
|
|
3311
|
-
*/
|
|
3312
|
-
async revParse(ref, opts) {
|
|
3313
|
-
const result = await this.runner.runOrThrow(this.context, ['rev-parse', ref], {
|
|
3314
|
-
signal: opts?.signal,
|
|
3315
|
-
});
|
|
3316
|
-
return result.stdout.trim();
|
|
3317
|
-
}
|
|
3318
|
-
/**
|
|
3319
|
-
* Count the number of commits reachable from a ref
|
|
3320
|
-
*/
|
|
3321
|
-
async revListCount(ref, opts) {
|
|
3322
|
-
const args = ['rev-list', '--count'];
|
|
3323
|
-
if (ref) {
|
|
3324
|
-
args.push(ref);
|
|
3325
|
-
}
|
|
3326
|
-
else {
|
|
3327
|
-
args.push('HEAD');
|
|
3328
|
-
}
|
|
3329
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3330
|
-
signal: opts?.signal,
|
|
3331
|
-
});
|
|
3332
|
-
return Number.parseInt(result.stdout.trim(), 10);
|
|
3333
|
-
}
|
|
3334
|
-
/**
|
|
3335
|
-
* Read or modify symbolic refs
|
|
3336
|
-
*/
|
|
3337
|
-
async symbolicRef(name, newRef, opts) {
|
|
3338
|
-
if (newRef !== undefined) {
|
|
3339
|
-
// Set the symbolic ref
|
|
3340
|
-
await this.runner.runOrThrow(this.context, ['symbolic-ref', name, newRef], {
|
|
3341
|
-
signal: opts?.signal,
|
|
3342
|
-
});
|
|
3343
|
-
return undefined;
|
|
3344
|
-
}
|
|
3345
|
-
// Read the symbolic ref
|
|
3346
|
-
const result = await this.runner.runOrThrow(this.context, ['symbolic-ref', name], {
|
|
3347
|
-
signal: opts?.signal,
|
|
3348
|
-
});
|
|
3349
|
-
return result.stdout.trim();
|
|
3350
|
-
}
|
|
3351
|
-
// ==========================================================================
|
|
3352
|
-
// Medium Priority - Submodule Operations
|
|
3353
|
-
// ==========================================================================
|
|
3354
|
-
async submoduleList(opts) {
|
|
3355
|
-
const result = await this.runner.run(this.context, ['submodule', 'status'], {
|
|
3356
|
-
signal: opts?.signal,
|
|
3357
|
-
});
|
|
3358
|
-
if (result.exitCode !== 0) {
|
|
3359
|
-
return [];
|
|
3360
|
-
}
|
|
3361
|
-
const submodules = [];
|
|
3362
|
-
for (const line of parseLines(result.stdout)) {
|
|
3363
|
-
// Format: [+-U ]<sha1> <path> (<describe>)
|
|
3364
|
-
const match = line.match(/^[ +-U]?([a-f0-9]+) (.+?)(?: \((.+)\))?$/);
|
|
3365
|
-
if (match) {
|
|
3366
|
-
const commit = match[1];
|
|
3367
|
-
const path = match[2];
|
|
3368
|
-
if (commit === undefined || path === undefined) {
|
|
3369
|
-
continue;
|
|
3370
|
-
}
|
|
3371
|
-
// Get URL from .gitmodules
|
|
3372
|
-
const urlResult = await this.runner.run(this.context, ['config', '-f', '.gitmodules', '--get', `submodule.${path}.url`], { signal: opts?.signal });
|
|
3373
|
-
const url = urlResult.exitCode === 0 ? urlResult.stdout.trim() : '';
|
|
3374
|
-
// Get branch if configured
|
|
3375
|
-
const branchResult = await this.runner.run(this.context, ['config', '-f', '.gitmodules', '--get', `submodule.${path}.branch`], { signal: opts?.signal });
|
|
3376
|
-
const branch = branchResult.exitCode === 0 ? branchResult.stdout.trim() : undefined;
|
|
3377
|
-
submodules.push({
|
|
3378
|
-
name: path,
|
|
3379
|
-
path: path,
|
|
3380
|
-
url,
|
|
3381
|
-
branch,
|
|
3382
|
-
commit: commit,
|
|
3383
|
-
});
|
|
3384
|
-
}
|
|
3385
|
-
}
|
|
3386
|
-
return submodules;
|
|
3387
|
-
}
|
|
3388
|
-
async submoduleInit(paths, opts) {
|
|
3389
|
-
const args = ['submodule', 'init'];
|
|
3390
|
-
if (paths && paths.length > 0) {
|
|
3391
|
-
args.push('--', ...paths);
|
|
3392
|
-
}
|
|
3393
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3394
|
-
signal: opts?.signal,
|
|
3395
|
-
});
|
|
3396
|
-
}
|
|
3397
|
-
async submoduleUpdate(opts) {
|
|
3398
|
-
const args = ['submodule', 'update'];
|
|
3399
|
-
if (opts?.init) {
|
|
3400
|
-
args.push('--init');
|
|
3401
|
-
}
|
|
3402
|
-
if (opts?.recursive) {
|
|
3403
|
-
args.push('--recursive');
|
|
3404
|
-
}
|
|
3405
|
-
if (opts?.remote) {
|
|
3406
|
-
args.push('--remote');
|
|
3407
|
-
}
|
|
3408
|
-
if (opts?.force) {
|
|
3409
|
-
args.push('--force');
|
|
3410
|
-
}
|
|
3411
|
-
// New options
|
|
3412
|
-
if (opts?.noFetch) {
|
|
3413
|
-
args.push('--no-fetch');
|
|
3414
|
-
}
|
|
3415
|
-
if (opts?.checkout) {
|
|
3416
|
-
args.push('--checkout');
|
|
3417
|
-
}
|
|
3418
|
-
if (opts?.merge) {
|
|
3419
|
-
args.push('--merge');
|
|
3420
|
-
}
|
|
3421
|
-
if (opts?.rebase) {
|
|
3422
|
-
args.push('--rebase');
|
|
3423
|
-
}
|
|
3424
|
-
if (opts?.recommendShallow) {
|
|
3425
|
-
args.push('--recommend-shallow');
|
|
3426
|
-
}
|
|
3427
|
-
if (opts?.reference) {
|
|
3428
|
-
args.push(`--reference=${opts.reference}`);
|
|
3429
|
-
}
|
|
3430
|
-
if (opts?.singleBranch) {
|
|
3431
|
-
args.push('--single-branch');
|
|
3432
|
-
}
|
|
3433
|
-
if (opts?.filter) {
|
|
3434
|
-
args.push(`--filter=${opts.filter}`);
|
|
3435
|
-
}
|
|
3436
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3437
|
-
signal: opts?.signal,
|
|
3438
|
-
});
|
|
3439
|
-
}
|
|
3440
|
-
async submoduleAdd(url, path, opts) {
|
|
3441
|
-
const args = ['submodule', 'add'];
|
|
3442
|
-
if (opts?.branch) {
|
|
3443
|
-
args.push('-b', opts.branch);
|
|
3444
|
-
}
|
|
3445
|
-
if (opts?.force) {
|
|
3446
|
-
args.push('--force');
|
|
3447
|
-
}
|
|
3448
|
-
if (opts?.name) {
|
|
3449
|
-
args.push('--name', opts.name);
|
|
3450
|
-
}
|
|
3451
|
-
if (opts?.reference) {
|
|
3452
|
-
args.push('--reference', opts.reference);
|
|
3453
|
-
}
|
|
3454
|
-
if (opts?.depth !== undefined) {
|
|
3455
|
-
args.push('--depth', String(opts.depth));
|
|
3456
|
-
}
|
|
3457
|
-
args.push(url, path);
|
|
3458
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3459
|
-
signal: opts?.signal,
|
|
3460
|
-
});
|
|
3461
|
-
}
|
|
3462
|
-
async submoduleDeinit(path, opts) {
|
|
3463
|
-
const args = ['submodule', 'deinit'];
|
|
3464
|
-
if (opts?.force) {
|
|
3465
|
-
args.push('--force');
|
|
3466
|
-
}
|
|
3467
|
-
if (opts?.all) {
|
|
3468
|
-
args.push('--all');
|
|
3469
|
-
}
|
|
3470
|
-
else {
|
|
3471
|
-
args.push(path);
|
|
3472
|
-
}
|
|
3473
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3474
|
-
signal: opts?.signal,
|
|
3475
|
-
});
|
|
3476
|
-
}
|
|
3477
|
-
async submoduleStatus(paths, opts) {
|
|
3478
|
-
const args = ['submodule', 'status'];
|
|
3479
|
-
if (opts?.recursive) {
|
|
3480
|
-
args.push('--recursive');
|
|
3481
|
-
}
|
|
3482
|
-
if (paths && paths.length > 0) {
|
|
3483
|
-
args.push('--', ...paths);
|
|
3484
|
-
}
|
|
3485
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3486
|
-
signal: opts?.signal,
|
|
3487
|
-
});
|
|
3488
|
-
return result.stdout;
|
|
3489
|
-
}
|
|
3490
|
-
async submoduleSummary(opts) {
|
|
3491
|
-
const args = ['submodule', 'summary'];
|
|
3492
|
-
if (opts?.limit !== undefined) {
|
|
3493
|
-
args.push('-n', String(opts.limit));
|
|
3494
|
-
}
|
|
3495
|
-
if (opts?.files) {
|
|
3496
|
-
args.push('--files');
|
|
3497
|
-
}
|
|
3498
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3499
|
-
signal: opts?.signal,
|
|
3500
|
-
});
|
|
3501
|
-
return result.stdout;
|
|
3502
|
-
}
|
|
3503
|
-
async submoduleForeach(command, opts) {
|
|
3504
|
-
const args = ['submodule', 'foreach'];
|
|
3505
|
-
if (opts?.recursive) {
|
|
3506
|
-
args.push('--recursive');
|
|
3507
|
-
}
|
|
3508
|
-
args.push(command);
|
|
3509
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3510
|
-
signal: opts?.signal,
|
|
3511
|
-
});
|
|
3512
|
-
return result.stdout;
|
|
3513
|
-
}
|
|
3514
|
-
async submoduleSync(paths, opts) {
|
|
3515
|
-
const args = ['submodule', 'sync'];
|
|
3516
|
-
if (opts?.recursive) {
|
|
3517
|
-
args.push('--recursive');
|
|
3518
|
-
}
|
|
3519
|
-
if (paths && paths.length > 0) {
|
|
3520
|
-
args.push('--', ...paths);
|
|
3521
|
-
}
|
|
3522
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3523
|
-
signal: opts?.signal,
|
|
3524
|
-
});
|
|
3525
|
-
}
|
|
3526
|
-
async submoduleAbsorbGitDirs(opts) {
|
|
3527
|
-
await this.runner.runOrThrow(this.context, ['submodule', 'absorbgitdirs'], {
|
|
3528
|
-
signal: opts?.signal,
|
|
3529
|
-
});
|
|
3530
|
-
}
|
|
3531
|
-
async submoduleSetBranch(path, branch, opts) {
|
|
3532
|
-
const args = ['submodule', 'set-branch'];
|
|
3533
|
-
if (opts?.default) {
|
|
3534
|
-
args.push('--default');
|
|
3535
|
-
}
|
|
3536
|
-
else {
|
|
3537
|
-
args.push('--branch', branch);
|
|
3538
|
-
}
|
|
3539
|
-
args.push('--', path);
|
|
3540
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3541
|
-
signal: opts?.signal,
|
|
3542
|
-
});
|
|
3543
|
-
}
|
|
3544
|
-
async submoduleSetUrl(path, url, opts) {
|
|
3545
|
-
await this.runner.runOrThrow(this.context, ['submodule', 'set-url', '--', path, url], {
|
|
3546
|
-
signal: opts?.signal,
|
|
3547
|
-
});
|
|
3548
|
-
}
|
|
3549
|
-
// ==========================================================================
|
|
3550
|
-
// Remote Operations
|
|
3551
|
-
// ==========================================================================
|
|
3552
|
-
async remoteList(opts) {
|
|
3553
|
-
const result = await this.runner.runOrThrow(this.context, ['remote', '-v'], {
|
|
3554
|
-
signal: opts?.signal,
|
|
3555
|
-
});
|
|
3556
|
-
const remotes = new Map();
|
|
3557
|
-
for (const line of parseLines(result.stdout)) {
|
|
3558
|
-
// Format: origin https://github.com/user/repo.git (fetch)
|
|
3559
|
-
// Format: origin https://github.com/user/repo.git (push)
|
|
3560
|
-
const match = line.match(/^(\S+)\t(.+?)\s+\((fetch|push)\)$/);
|
|
3561
|
-
if (match) {
|
|
3562
|
-
const name = match[1];
|
|
3563
|
-
const url = match[2];
|
|
3564
|
-
const type = match[3];
|
|
3565
|
-
if (name !== undefined && url !== undefined) {
|
|
3566
|
-
const existing = remotes.get(name);
|
|
3567
|
-
if (existing) {
|
|
3568
|
-
if (type === 'fetch') {
|
|
3569
|
-
existing.fetchUrl = url;
|
|
3570
|
-
}
|
|
3571
|
-
else if (type === 'push') {
|
|
3572
|
-
existing.pushUrl = url;
|
|
3573
|
-
}
|
|
3574
|
-
}
|
|
3575
|
-
else {
|
|
3576
|
-
remotes.set(name, {
|
|
3577
|
-
name,
|
|
3578
|
-
fetchUrl: type === 'fetch' ? url : '',
|
|
3579
|
-
pushUrl: type === 'push' ? url : '',
|
|
3580
|
-
});
|
|
3581
|
-
}
|
|
3582
|
-
}
|
|
3583
|
-
}
|
|
3584
|
-
}
|
|
3585
|
-
// Fill in missing URLs (they're often the same)
|
|
3586
|
-
for (const remote of remotes.values()) {
|
|
3587
|
-
if (!remote.fetchUrl && remote.pushUrl) {
|
|
3588
|
-
remote.fetchUrl = remote.pushUrl;
|
|
3589
|
-
}
|
|
3590
|
-
if (!remote.pushUrl && remote.fetchUrl) {
|
|
3591
|
-
remote.pushUrl = remote.fetchUrl;
|
|
3592
|
-
}
|
|
3593
|
-
}
|
|
3594
|
-
return Array.from(remotes.values());
|
|
3595
|
-
}
|
|
3596
|
-
async remoteAdd(name, url, opts) {
|
|
3597
|
-
const args = ['remote', 'add'];
|
|
3598
|
-
if (opts?.track) {
|
|
3599
|
-
args.push('-t', opts.track);
|
|
3600
|
-
}
|
|
3601
|
-
if (opts?.fetch) {
|
|
3602
|
-
args.push('-f');
|
|
3603
|
-
}
|
|
3604
|
-
if (opts?.mirror === 'fetch') {
|
|
3605
|
-
args.push('--mirror=fetch');
|
|
3606
|
-
}
|
|
3607
|
-
else if (opts?.mirror === 'push') {
|
|
3608
|
-
args.push('--mirror=push');
|
|
3609
|
-
}
|
|
3610
|
-
// New option
|
|
3611
|
-
if (opts?.tags === true) {
|
|
3612
|
-
args.push('--tags');
|
|
3613
|
-
}
|
|
3614
|
-
else if (opts?.tags === false) {
|
|
3615
|
-
args.push('--no-tags');
|
|
3616
|
-
}
|
|
3617
|
-
args.push(name, url);
|
|
3618
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3619
|
-
signal: opts?.signal,
|
|
3620
|
-
});
|
|
3621
|
-
}
|
|
3622
|
-
async remoteRemove(name, opts) {
|
|
3623
|
-
await this.runner.runOrThrow(this.context, ['remote', 'remove', name], {
|
|
3624
|
-
signal: opts?.signal,
|
|
3625
|
-
});
|
|
3626
|
-
}
|
|
3627
|
-
async remoteRename(oldName, newName, opts) {
|
|
3628
|
-
await this.runner.runOrThrow(this.context, ['remote', 'rename', oldName, newName], {
|
|
3629
|
-
signal: opts?.signal,
|
|
3630
|
-
});
|
|
3631
|
-
}
|
|
3632
|
-
async remoteGetUrl(name, opts) {
|
|
3633
|
-
const args = ['remote', 'get-url'];
|
|
3634
|
-
if (opts?.push) {
|
|
3635
|
-
args.push('--push');
|
|
3636
|
-
}
|
|
3637
|
-
args.push(name);
|
|
3638
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3639
|
-
signal: opts?.signal,
|
|
3640
|
-
});
|
|
3641
|
-
return result.stdout.trim();
|
|
3642
|
-
}
|
|
3643
|
-
async remoteSetUrl(name, url, opts) {
|
|
3644
|
-
const args = ['remote', 'set-url'];
|
|
3645
|
-
if (opts?.push) {
|
|
3646
|
-
args.push('--push');
|
|
3647
|
-
}
|
|
3648
|
-
args.push(name, url);
|
|
3649
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3650
|
-
signal: opts?.signal,
|
|
3651
|
-
});
|
|
3652
|
-
}
|
|
3653
|
-
async remoteSetHead(remote, branch, opts) {
|
|
3654
|
-
const args = ['remote', 'set-head'];
|
|
3655
|
-
if (opts?.auto) {
|
|
3656
|
-
args.push('--auto');
|
|
3657
|
-
}
|
|
3658
|
-
else if (opts?.delete) {
|
|
3659
|
-
args.push('--delete');
|
|
3660
|
-
}
|
|
3661
|
-
args.push(remote);
|
|
3662
|
-
if (branch && !opts?.auto && !opts?.delete) {
|
|
3663
|
-
args.push(branch);
|
|
3664
|
-
}
|
|
3665
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3666
|
-
signal: opts?.signal,
|
|
3667
|
-
});
|
|
3668
|
-
}
|
|
3669
|
-
async remoteShow(remote, opts) {
|
|
3670
|
-
const args = ['remote', 'show'];
|
|
3671
|
-
if (opts?.noQuery) {
|
|
3672
|
-
args.push('-n');
|
|
3673
|
-
}
|
|
3674
|
-
args.push(remote);
|
|
3675
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3676
|
-
signal: opts?.signal,
|
|
3677
|
-
});
|
|
3678
|
-
return result.stdout;
|
|
3679
|
-
}
|
|
3680
|
-
async remotePrune(remote, opts) {
|
|
3681
|
-
const args = ['remote', 'prune'];
|
|
3682
|
-
if (opts?.dryRun) {
|
|
3683
|
-
args.push('--dry-run');
|
|
3684
|
-
}
|
|
3685
|
-
args.push(remote);
|
|
3686
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3687
|
-
signal: opts?.signal,
|
|
3688
|
-
});
|
|
3689
|
-
// Parse pruned refs from output
|
|
3690
|
-
const pruned = [];
|
|
3691
|
-
for (const line of parseLines(result.stdout)) {
|
|
3692
|
-
// Output is like " * [pruned] origin/some-branch"
|
|
3693
|
-
const match = line.match(/\* \[pruned\] (.+)/);
|
|
3694
|
-
const ref = match?.[1];
|
|
3695
|
-
if (ref) {
|
|
3696
|
-
pruned.push(ref);
|
|
3697
|
-
}
|
|
3698
|
-
}
|
|
3699
|
-
return pruned;
|
|
3700
|
-
}
|
|
3701
|
-
async remoteUpdate(remotes, opts) {
|
|
3702
|
-
const args = ['remote', 'update'];
|
|
3703
|
-
if (opts?.prune) {
|
|
3704
|
-
args.push('--prune');
|
|
3705
|
-
}
|
|
3706
|
-
if (remotes && remotes.length > 0) {
|
|
3707
|
-
args.push(...remotes);
|
|
3708
|
-
}
|
|
3709
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3710
|
-
signal: opts?.signal,
|
|
3711
|
-
});
|
|
3712
|
-
}
|
|
3713
|
-
async remoteSetBranches(remote, branches, opts) {
|
|
3714
|
-
const args = ['remote', 'set-branches'];
|
|
3715
|
-
if (opts?.add) {
|
|
3716
|
-
args.push('--add');
|
|
3717
|
-
}
|
|
3718
|
-
args.push(remote, ...branches);
|
|
3719
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3720
|
-
signal: opts?.signal,
|
|
3721
|
-
});
|
|
3722
|
-
}
|
|
3723
|
-
// ==========================================================================
|
|
3724
|
-
// Config Operations (Repository-level)
|
|
3725
|
-
// ==========================================================================
|
|
3726
|
-
/**
|
|
3727
|
-
* Get a typed config value
|
|
3728
|
-
*/
|
|
3729
|
-
async configGet(key, opts) {
|
|
3730
|
-
const result = await this.runner.run(this.context, ['config', '--get', key], {
|
|
3731
|
-
signal: opts?.signal,
|
|
3732
|
-
});
|
|
3733
|
-
if (result.exitCode !== 0) {
|
|
3734
|
-
return undefined;
|
|
3735
|
-
}
|
|
3736
|
-
return result.stdout.trim();
|
|
3737
|
-
}
|
|
3738
|
-
/**
|
|
3739
|
-
* Get all values for a typed multi-valued config key
|
|
3740
|
-
*/
|
|
3741
|
-
async configGetAll(key, opts) {
|
|
3742
|
-
const result = await this.runner.run(this.context, ['config', '--get-all', key], {
|
|
3743
|
-
signal: opts?.signal,
|
|
3744
|
-
});
|
|
3745
|
-
if (result.exitCode !== 0) {
|
|
3746
|
-
return [];
|
|
3747
|
-
}
|
|
3748
|
-
return parseLines(result.stdout);
|
|
3749
|
-
}
|
|
3750
|
-
/**
|
|
3751
|
-
* Set a typed config value
|
|
3752
|
-
*/
|
|
3753
|
-
async configSet(key, value, opts) {
|
|
3754
|
-
await this.runner.runOrThrow(this.context, ['config', key, String(value)], {
|
|
3755
|
-
signal: opts?.signal,
|
|
3756
|
-
});
|
|
3757
|
-
}
|
|
3758
|
-
/**
|
|
3759
|
-
* Add a value to a typed multi-valued config key
|
|
3760
|
-
*/
|
|
3761
|
-
async configAdd(key, value, opts) {
|
|
3762
|
-
await this.runner.runOrThrow(this.context, ['config', '--add', key, String(value)], {
|
|
3763
|
-
signal: opts?.signal,
|
|
3764
|
-
});
|
|
3765
|
-
}
|
|
3766
|
-
/**
|
|
3767
|
-
* Unset a typed config value
|
|
3768
|
-
*/
|
|
3769
|
-
async configUnset(key, opts) {
|
|
3770
|
-
await this.runner.runOrThrow(this.context, ['config', '--unset', key], {
|
|
3771
|
-
signal: opts?.signal,
|
|
3772
|
-
});
|
|
3773
|
-
}
|
|
3774
|
-
/**
|
|
3775
|
-
* Get a raw config value (for arbitrary keys)
|
|
3776
|
-
*/
|
|
3777
|
-
async configGetRaw(key, opts) {
|
|
3778
|
-
const args = ['config'];
|
|
3779
|
-
// New options
|
|
3780
|
-
if (opts?.type) {
|
|
3781
|
-
args.push(`--type=${opts.type}`);
|
|
3782
|
-
}
|
|
3783
|
-
if (opts?.default !== undefined) {
|
|
3784
|
-
args.push('--default', opts.default);
|
|
3785
|
-
}
|
|
3786
|
-
if (opts?.all) {
|
|
3787
|
-
args.push('--get-all');
|
|
3788
|
-
}
|
|
3789
|
-
else {
|
|
3790
|
-
args.push('--get');
|
|
3791
|
-
}
|
|
3792
|
-
args.push(key);
|
|
3793
|
-
const result = await this.runner.run(this.context, args, {
|
|
3794
|
-
signal: opts?.signal,
|
|
3795
|
-
});
|
|
3796
|
-
if (result.exitCode !== 0) {
|
|
3797
|
-
return undefined;
|
|
3798
|
-
}
|
|
3799
|
-
if (opts?.all) {
|
|
3800
|
-
return parseLines(result.stdout);
|
|
3801
|
-
}
|
|
3802
|
-
return result.stdout.trim();
|
|
3803
|
-
}
|
|
3804
|
-
/**
|
|
3805
|
-
* Set a raw config value (for arbitrary keys)
|
|
3806
|
-
*/
|
|
3807
|
-
async configSetRaw(key, value, opts) {
|
|
3808
|
-
const args = ['config'];
|
|
3809
|
-
if (opts?.add) {
|
|
3810
|
-
args.push('--add');
|
|
3811
|
-
}
|
|
3812
|
-
args.push(key, value);
|
|
3813
|
-
await this.runner.runOrThrow(this.context, args, {
|
|
3814
|
-
signal: opts?.signal,
|
|
3815
|
-
});
|
|
3816
|
-
}
|
|
3817
|
-
/**
|
|
3818
|
-
* Unset a raw config value (for arbitrary keys)
|
|
3819
|
-
*/
|
|
3820
|
-
async configUnsetRaw(key, opts) {
|
|
3821
|
-
await this.runner.runOrThrow(this.context, ['config', '--unset', key], {
|
|
3822
|
-
signal: opts?.signal,
|
|
3823
|
-
});
|
|
3824
|
-
}
|
|
3825
|
-
/**
|
|
3826
|
-
* List all config values
|
|
3827
|
-
*/
|
|
3828
|
-
async configList(opts) {
|
|
3829
|
-
const args = ['config', '--list'];
|
|
3830
|
-
if (opts?.showOrigin) {
|
|
3831
|
-
args.push('--show-origin');
|
|
3832
|
-
}
|
|
3833
|
-
if (opts?.showScope) {
|
|
3834
|
-
args.push('--show-scope');
|
|
3835
|
-
}
|
|
3836
|
-
// New options
|
|
3837
|
-
if (opts?.includes) {
|
|
3838
|
-
args.push('--includes');
|
|
3839
|
-
}
|
|
3840
|
-
if (opts?.nameOnly) {
|
|
3841
|
-
args.push('--name-only');
|
|
3842
|
-
}
|
|
3843
|
-
const result = await this.runner.runOrThrow(this.context, args, {
|
|
3844
|
-
signal: opts?.signal,
|
|
3845
|
-
});
|
|
3846
|
-
const entries = [];
|
|
3847
|
-
for (const line of parseLines(result.stdout)) {
|
|
3848
|
-
// Format: key=value or origin\tkey=value or scope\tkey=value
|
|
3849
|
-
// When showOrigin or showScope is used, there's a tab separator
|
|
3850
|
-
let keyValue = line;
|
|
3851
|
-
if (opts?.showOrigin || opts?.showScope) {
|
|
3852
|
-
const tabIndex = line.lastIndexOf('\t');
|
|
3853
|
-
if (tabIndex !== -1) {
|
|
3854
|
-
keyValue = line.slice(tabIndex + 1);
|
|
3855
|
-
}
|
|
3856
|
-
}
|
|
3857
|
-
// For nameOnly, there's no '=' separator
|
|
3858
|
-
if (opts?.nameOnly) {
|
|
3859
|
-
entries.push({
|
|
3860
|
-
key: keyValue,
|
|
3861
|
-
value: '',
|
|
3862
|
-
});
|
|
3863
|
-
}
|
|
3864
|
-
else {
|
|
3865
|
-
const eqIndex = keyValue.indexOf('=');
|
|
3866
|
-
if (eqIndex !== -1) {
|
|
3867
|
-
entries.push({
|
|
3868
|
-
key: keyValue.slice(0, eqIndex),
|
|
3869
|
-
value: keyValue.slice(eqIndex + 1),
|
|
3870
|
-
});
|
|
3871
|
-
}
|
|
3872
|
-
}
|
|
3873
|
-
}
|
|
3874
|
-
return entries;
|
|
3875
|
-
}
|
|
3876
|
-
async configRenameSection(oldName, newName, opts) {
|
|
3877
|
-
await this.runner.runOrThrow(this.context, ['config', '--rename-section', oldName, newName], {
|
|
3878
|
-
signal: opts?.signal,
|
|
3879
|
-
});
|
|
3880
|
-
}
|
|
3881
|
-
async configRemoveSection(name, opts) {
|
|
3882
|
-
await this.runner.runOrThrow(this.context, ['config', '--remove-section', name], {
|
|
3883
|
-
signal: opts?.signal,
|
|
3884
|
-
});
|
|
3885
|
-
}
|
|
3886
|
-
}
|
|
3887
|
-
//# sourceMappingURL=worktree-repo-impl.js.map
|