ide на основе vs code · VibeGit
ide на основе vs code Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
krutaya-ide-na-osnove-vs-code / extensions / copilot / src / platform / git / vscode-node / gitServiceImpl.ts 593 строк · изменён 14 нояб., 04:52
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
import * as vscode from 'vscode' ;
import { execFile } from 'child_process' ;
import { promisify } from 'util' ;
import { Uri } from 'vscode' ;
import { BatchedProcessor } from '../../../util/common/async' ;
import { coalesce } from '../../../util/vs/base/common/arrays' ;
import { raceTimeout, Sequencer } from '../../../util/vs/base/common/async' ;
import { CachedFunction } from
CancellationToken cancelOnDispose
Emitter Event
Disposable
autorun IObservable observableFromEvent observableSignalFromEvent observableValue waitForState
path
isEqual
ILogService
IGitExtensionService
IGitService RepoContext
parseGitRemotes
APIState Branch Change CommitOptions CommitShortStat DiffChange Ref RefQuery Repository RepositoryAccessDetails
execFileAsync execFile
_serviceBrand
activeRepository
_getRepositorySequencer
_onDidOpenRepository
onDidOpenRepository Event RepoContext _onDidOpenRepository event
_onDidCloseRepository
onDidCloseRepository Event RepoContext _onDidCloseRepository event
_onDidFinishInitialRepositoryDiscovery
onDidFinishInitialization Event _onDidFinishInitialRepositoryDiscovery event
_isInitialized
gitExtensionService IGitExtensionService
logService ILogService
_onDidOpenRepository
_onDidCloseRepository
_onDidFinishInitialRepositoryDiscovery
gitAPI gitExtensionService
gitAPI
gitAPI
gitExtensionService status
status enabled
gitAPI gitExtensionService
gitAPI
gitAPI
_onDidFinishInitialRepositoryDiscovery
_isInitialized
gitAPI
gitAPI repository repository
gitAPI repository repository
repository gitAPI repositories
repository
stateObs
gitAPI onDidChangeState Event APIState gitAPI state
reader
state stateObs reader
state
gitAPI repositories repository
repository state onDidChange Event repository state
state state _store
_isInitialized
_onDidFinishInitialRepositoryDiscovery
logService
_isInitialized
Iterable RepositoryAccessDetails
gitAPI gitExtensionService
gitAPI
gitAPI recentRepositories
uri Repository
gitAPI gitExtensionService
repository gitAPI uri
repository
repository
repository
uri Repository
repository uri
repository
repository
repository
uri Repository
repository uri
repository
uri forceOpen RepoContext
repository uri forceOpen
repository
repository
GitServiceImpl repository
uri forceOpen Repository
_getRepositorySequencer
gitAPI gitExtensionService
gitAPI
uri Uri
uri vscode Uri uri
repository gitAPI uri
repository
repository
forceOpen
repository gitAPI uri
repository
repository
uri Pick RepoContext
logService
gitAPI gitExtensionService
gitAPI
repository gitAPI uri
repository
repository
remotes
rootUri repository rootUri
remoteFetchUrls repository state remotes r r fetchUrl
logService
remotes
uri scheme
logService
uriStat vscode workspace fs uri
uriStat type vscode FileType Directory
uri path uri fsPath
repositoryRoot gitAPI uri
repositoryRoot
logService
logService
buffer vscode workspace fs path repositoryRoot fsPath
remotes
rootUri repositoryRoot
remoteFetchUrls buffer remote remote fetchUrl
logService
remotes
error
logService
uri paths
gitAPI gitExtensionService
repository gitAPI uri
repository paths
uri paths options staged ref
gitAPI gitExtensionService
repository gitAPI uri
repository paths options
uri vscode Uri ref1 ref2 path
gitAPI gitExtensionService
repository gitAPI uri
repository ref1 ref2 path
uri vscode Uri ref1 ref2 path DiffChange
gitAPI gitExtensionService
repository gitAPI uri
repository ref1 ref2 path
uri vscode Uri ref Change
gitAPI gitExtensionService
repository gitAPI uri
repository ref
uri CommitShortStat
gitAPI gitExtensionService
repository gitAPI uri
repository diffIndexWithHEADShortStats
repository uri fsPath
uri ref1 ref2
gitAPI gitExtensionService
repository gitAPI uri
repository ref1 ref2
uri message opts CommitOptions
gitAPI gitExtensionService
repository gitAPI uri
repository
repository message opts
uri patch
gitAPI gitExtensionService
repository gitAPI uri
repository patch
uri branch
gitAPI gitExtensionService
repository gitAPI uri
repository branch
error
logService
uri options path commitish branch noTrack
gitAPI gitExtensionService
repository gitAPI uri
repository options
uri path options force label
gitAPI gitExtensionService
repository gitAPI uri
repository path options
uri sourceRepositoryUri options confirmation deleteFromSource untracked
gitAPI gitExtensionService
repository gitAPI uri
repository sourceRepositoryUri fsPath options
uri name Branch
gitAPI gitExtensionService
repository gitAPI uri
repository name
uri name Branch
gitAPI gitExtensionService
repository gitAPI uri
repository name
uri query RefQuery cancellationToken CancellationToken Ref
gitAPI gitExtensionService
repository gitAPI uri
repository query cancellationToken
uri branch Branch
gitAPI gitExtensionService
repository gitAPI uri
repository
branchToCheck branch
repository branch
branch
repository branchToCheck
error
branchLabel branch branch branch name
logService
uri
gitAPI gitExtensionService
repository gitAPI uri
branchName repository
branchName
error
logService
cwd args env Record
gitAPI gitExtensionService
gitPath gitAPI git path
gitEnv Object process env env
satisfies Record
timer performance
result gitPath args
cwd cwd fsPath
encoding
env gitEnv
result stderr
logService
logService
result stdout
error
errorMessage error error message error
logService
_isInitialized
_isInitialized state state _store
repositories length
activeRepository state state _store
_initialDiscoverySettled
_isInitialized
_initialDiscoverySettled
_isInitialized state state _store
logService
_initialDiscoverySettled
repository Repository
logService
repository state onDidChange Event repository state
state state _store
logService
selectedObs
repository ui onDidChange Event repository ui selected
onDidChangeStateSignal repository state onDidChange Event
reader
onDidChangeStateSignal reader
selected selectedObs reader
activeRepository activeRepository
activeRepository selected activeRepository rootUri repository rootUri
repositoryContext GitServiceImpl repository
logService
activeRepository repositoryContext
repositoryContext GitServiceImpl repository
repositoryContext
_onDidOpenRepository repositoryContext
repository Repository
logService
repositoryContext GitServiceImpl repository
repositoryContext
_onDidCloseRepository repositoryContext
repository Repository
repository state
repository state onDidChange Event repository state
state state _store
repo Repository RepoContext
repo Repository RepoContext
repo Repository RepoContext
repo
repo
RepoContext
gitAPI gitExtensionService
gitAPI
gitAPI repositories
repository repository state
repository GitServiceImpl repository
rootUri _repo rootUri
kind _repo kind
isUsingVirtualFileSystem _repo isUsingVirtualFileSystem
headBranchName _repo state name
headCommitHash _repo state commit
headIncomingChanges _repo state behind
headOutgoingChanges _repo state ahead
upstreamBranchName _repo state upstream name
upstreamRemote _repo state upstream remote
isRebasing _repo state rebaseCommit
remotes _repo state remotes r r name
remoteFetchUrls _repo state remotes r r fetchUrl
worktrees _repo state worktrees
changes
mergeChanges _repo state mergeChanges
indexChanges _repo state indexChanges
workingTree _repo state workingTreeChanges
untrackedChanges _repo state untrackedChanges
_onDidChangeSignal _repo state onDidChange Event
headBranchNameObs IObservable _onDidChangeSignal _repo state name
headCommitHashObs IObservable _onDidChangeSignal _repo state commit
upstreamBranchNameObs IObservable _onDidChangeSignal _repo state upstream name
upstreamRemoteObs IObservable _onDidChangeSignal _repo state upstream remote
isRebasingObs IObservable _onDidChangeSignal _repo state rebaseCommit
_checkIsIgnored paths
result _repo paths
paths p result p
_isIgnored documentUri
path Uri documentUri fsPath
result _checkIsIgnored path
result
uri
_isIgnored uri
_repo Repository
'../../../util/vs/base/common/cache'
;
import
{
,
}
from
'../../../util/vs/base/common/cancellation'
;
import
{
,
}
from
'../../../util/vs/base/common/event'
;
import
{
}
from
'../../../util/vs/base/common/lifecycle'
;
import
{
,
,
,
,
,
}
from
'../../../util/vs/base/common/observableInternal'
;
import
*
as
from
'../../../util/vs/base/common/path'
;
import
{
}
from
'../../../util/vs/base/common/resources'
;
import
{
URI
}
from
'../../../util/vs/base/common/uri'
;
import
{
}
from
'../../log/common/logService'
;
import
{
}
from
'../common/gitExtensionService'
;
import
{
,
}
from
'../common/gitService'
;
import
{
}
from
'../common/utils'
;
import
{
API
,
,
,
,
,
,
,
,
,
,
}
from
'../vscode/git'
;
const
=
promisify
(
)
;
const
INITIAL_DISCOVERY_TIMEOUT_MS
=
30_000
;
export
class
GitServiceImpl
extends
Disposable
implements
IGitService
{
declare
readonly
:
undefined
;
readonly
=
observableValue < RepoContext | undefined >
(
this
,
undefined
)
;
private
readonly
=
new
Sequencer
(
)
;
private
=
new
Emitter< RepoContext>
(
)
;
readonly
:
<
>
=
this
.
.
;
private
=
new
Emitter< RepoContext>
(
)
;
readonly
:
<
>
=
this
.
.
;
private
=
new
Emitter< void >
(
)
;
readonly
:
<
void
>
=
this
.
.
;
private
=
observableValue
(
this
,
false
)
;
constructor
(
@ IGitExtensionService
private
readonly
:
,
@ ILogService
private
readonly
:
)
{
super
(
)
;
this
.
_register
(
this
.
)
;
this
.
_register
(
this
.
)
;
this
.
_register
(
this
.
)
;
const
=
this
.
.
getExtensionApi
(
)
;
if
(
)
{
this
.
registerGitAPIListeners
(
)
;
}
else
{
this
.
_register
(
this
.
.
onDidChange
(
(
)
=>
{
if
(
.
)
{
const
=
this
.
.
getExtensionApi
(
)
;
if
(
)
{
this
.
registerGitAPIListeners
(
)
;
return
;
}
}
this
.
.
fire
(
)
;
this
.
.
set
(
true
,
undefined
)
;
}
)
)
;
}
}
private
registerGitAPIListeners
(
:
API
)
{
this
.
_register
(
.
onDidOpenRepository
(
=>
this
.
doOpenRepository
(
)
)
)
;
this
.
_register
(
.
onDidCloseRepository
(
=>
this
.
doCloseRepository
(
)
)
)
;
for
(
const
of
.
)
{
this
.
doOpenRepository
(
)
;
}
const
=
observableFromEvent
(
this
,
.
as
<
>
,
(
)
=>
.
)
;
this
.
_register
(
autorun
(
async
=>
{
const
=
.
read
(
)
;
if
(
!==
'initialized'
)
{
return
;
}
await
Promise
.
all
(
.
.
map
(
=>
{
const
HEAD
=
observableFromEvent
(
this
,
.
.
as
<
void
>
,
(
)
=>
.
.
HEAD
)
;
return
waitForState
(
HEAD
,
=>
!==
undefined
,
undefined
,
cancelOnDispose
(
this
.
)
)
;
}
)
)
;
this
.
.
set
(
true
,
undefined
)
;
this
.
.
fire
(
)
;
this
.
.
trace
(
` [GitServiceImpl] Initial repository discovery finished: ${ this . repositories. length} repositories found. `
)
;
}
)
)
;
}
get
isInitialized
(
)
:
boolean
{
return
this
.
.
get
(
)
;
}
public
getRecentRepositories
(
)
:
<
>
{
const
=
this
.
.
getExtensionApi
(
)
;
if
(
!
)
{
return
[
]
;
}
return
.
;
}
async
initRepository
(
:
URI
)
:
Promise
<
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
await
?.
init
(
)
;
if
(
!
)
{
return
undefined
;
}
await
this
.
waitForRepositoryState
(
)
;
return
;
}
async
openRepository
(
:
URI
)
:
Promise
<
|
undefined
>
{
const
=
await
this
.
_getRepository
(
,
true
)
;
if
(
!
)
{
return
undefined
;
}
await
this
.
waitForRepositoryState
(
)
;
return
;
}
async
getRepository2
(
:
URI
)
:
Promise
<
|
undefined
>
{
const
=
await
this
.
_getRepository
(
,
false
)
;
return
;
}
async
getRepository
(
:
URI
,
=
true
)
:
Promise
<
|
undefined
>
{
const
=
await
this
.
_getRepository
(
,
)
;
if
(
!
)
{
return
undefined
;
}
await
this
.
waitForRepositoryState
(
)
;
return
.
repoToRepoContext
(
)
;
}
private
async
_getRepository
(
:
URI
,
=
true
)
:
Promise
<
|
undefined
>
{
return
this
.
.
queue
(
async
(
)
=>
{
const
=
this
.
.
getExtensionApi
(
)
;
if
(
!
)
{
return
undefined
;
}
if
(
!
(
instanceof
vscode
.
)
)
{
=
.
.
parse
(
.
toString
(
)
)
;
}
await
this
.
initialize
(
)
;
let
=
.
getRepository
(
)
;
if
(
)
{
return
;
}
if
(
!
)
{
return
undefined
;
}
=
await
.
openRepository
(
)
;
if
(
!
)
{
return
undefined
;
}
return
;
}
)
;
}
async
getRepositoryFetchUrls
(
:
URI
)
:
Promise
<
<
,
'rootUri'
|
'remoteFetchUrls'
>
|
undefined
>
{
this
.
.
trace
(
` [GitServiceImpl][getRepositoryFetchUrls] URI: ${ uri. toString ( ) } `
)
;
await
this
.
waitForInitialDiscovery
(
)
;
const
=
this
.
.
getExtensionApi
(
)
;
if
(
!
)
{
return
undefined
;
}
const
=
.
getRepository
(
)
;
if
(
)
{
await
this
.
waitForRepositoryState
(
)
;
const
=
{
:
.
,
:
.
.
.
map
(
=>
.
)
,
}
;
this
.
.
trace
(
` [GitServiceImpl][getRepositoryFetchUrls] Remotes (open repository): ${ JSON . stringify ( remotes) } `
)
;
return
;
}
if
(
.
!==
'file'
)
{
this
.
.
trace
(
` [GitServiceImpl][getRepositoryFetchUrls] No open repository found for non-file URI `
)
;
return
undefined
;
}
try
{
const
=
await
.
.
.
stat
(
)
;
if
(
.
!==
.
.
)
{
=
URI
.
file
(
.
dirname
(
.
)
)
;
}
const
=
await
.
getRepositoryRoot
(
)
;
if
(
!
)
{
this
.
.
trace
(
` [GitServiceImpl][getRepositoryFetchUrls] No repository root found `
)
;
return
undefined
;
}
this
.
.
trace
(
` [GitServiceImpl][getRepositoryFetchUrls] Repository root: ${ repositoryRoot. toString ( ) } `
)
;
const
=
await
.
.
.
readFile
(
URI
.
file
(
.
join
(
.
,
'.git'
,
'config'
)
)
)
;
const
=
{
:
,
:
parseGitRemotes
(
.
toString
(
)
)
.
map
(
=>
.
)
}
;
this
.
.
trace
(
` [GitServiceImpl][getRepositoryFetchUrls] Remotes (.git/config): ${ JSON . stringify ( remotes) } `
)
;
return
;
}
catch
(
)
{
this
.
.
error
(
` [GitServiceImpl][getRepositoryFetchUrls] Failed to read remotes from .git/config: ${ error. message} `
)
;
return
undefined
;
}
}
async
add
(
:
URI
,
:
string
[
]
)
:
Promise
<
void
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
await
?.
add
(
)
;
}
async
restore
(
:
URI
,
:
string
[
]
,
?
:
{
?
:
boolean
;
?
:
string
}
)
:
Promise
<
void
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
await
?.
restore
(
,
)
;
}
async
diffBetweenPatch
(
:
.
,
:
string
,
:
string
,
?
:
string
)
:
Promise
<
string
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
?.
diffBetweenPatch
(
,
,
)
;
}
async
diffBetweenWithStats
(
:
.
,
:
string
,
:
string
,
?
:
string
)
:
Promise
<
[
]
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
diffBetweenWithStats
(
,
,
)
;
}
async
diffWith
(
:
.
,
:
string
)
:
Promise
<
[
]
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
?.
diffWith
(
)
;
}
async
diffIndexWithHEADShortStats
(
:
URI
)
:
Promise
<
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
if
(
!
?.
)
{
return
undefined
;
}
return
await
?.
diffIndexWithHEADShortStats
(
.
)
;
}
async
getMergeBase
(
:
URI
,
:
string
,
:
string
)
:
Promise
<
string
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
?.
getMergeBase
(
,
)
;
}
async
commit
(
:
URI
,
:
string
,
?
:
)
:
Promise
<
void
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
if
(
!
)
{
return
;
}
await
.
commit
(
,
)
;
}
async
applyPatch
(
:
URI
,
:
string
)
:
Promise
<
void
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
apply
(
,
false
)
;
}
async
rebase
(
:
URI
,
:
string
)
:
Promise
<
void
>
{
try
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
await
?.
rebase
(
)
;
}
catch
(
)
{
this
.
.
error
(
` [GitServiceImpl][rebase] Failed to rebase ${ uri. toString ( ) } on ${ branch} : ${ error. message} `
)
;
}
}
async
createWorktree
(
:
URI
,
?
:
{
?
:
string
;
?
:
string
;
?
:
string
;
?
:
boolean
}
)
:
Promise
<
string
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
createWorktree
(
)
;
}
async
deleteWorktree
(
:
URI
,
:
string
,
?
:
{
?
:
boolean
;
?
:
string
}
)
:
Promise
<
void
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
deleteWorktree
(
,
)
;
}
async
migrateChanges
(
:
URI
,
:
URI
,
?
:
{
?
:
boolean
;
?
:
boolean
;
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
migrateChanges
(
.
,
)
;
}
async
getBranch
(
:
URI
,
:
string
)
:
Promise
<
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
getBranch
(
)
;
}
async
getBranchBase
(
:
URI
,
:
string
)
:
Promise
<
|
undefined
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
getBranchBase
(
)
;
}
async
getRefs
(
:
URI
,
:
,
?
:
)
:
Promise
<
[
]
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
return
await
?.
getRefs
(
,
)
??
[
]
;
}
async
isBranchProtected
(
:
URI
,
?
:
string
|
)
:
Promise
<
boolean
|
undefined
>
{
try
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
if
(
!
)
{
return
undefined
;
}
const
=
typeof
===
'string'
?
await
.
getBranch
(
)
:
;
return
.
isBranchProtected
(
)
;
}
catch
(
)
{
const
=
typeof
===
'string'
?
:
?.
;
this
.
.
error
(
` [GitServiceImpl][isBranchProtected] Failed to check branch protection for ${ uri. toString ( ) } ${ branchLabel ? ` ( ${ branchLabel} ) ` : '' } : ${ error instanceof Error ? error. message : String ( error) } `
)
;
return
undefined
;
}
}
async
generateRandomBranchName
(
:
URI
)
:
Promise
<
string
|
undefined
>
{
try
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
getRepository
(
)
;
const
=
await
?.
generateRandomBranchName
(
)
;
return
;
}
catch
(
)
{
this
.
.
error
(
` [GitServiceImpl][generateRandomBranchName] Failed to generate random branch name: ${ error instanceof Error ? error. message : String ( error) } `
)
;
return
undefined
;
}
}
async
exec
(
:
URI
,
:
string
[
]
,
?
:
<
string
,
string
>
)
:
Promise
<
string
>
{
const
=
this
.
.
getExtensionApi
(
)
;
const
=
?.
.
??
'git'
;
const
=
.
assign
(
{
}
,
.
,
,
{
GIT_AUTHOR_NAME
:
'VS Code'
,
GIT_AUTHOR_EMAIL
:
'vscode@users.noreply.github.com'
,
GIT_COMMITTER_NAME
:
'VS Code'
,
GIT_COMMITTER_EMAIL
:
'vscode@users.noreply.github.com'
,
LANG
:
'en_US.UTF-8'
,
LANGUAGE
:
'en'
,
LC_ALL
:
'en_US.UTF-8'
}
<
string
,
string
>
)
;
const
=
.
now
(
)
;
try
{
const
=
await
execFileAsync
(
,
,
{
:
.
,
:
'utf8'
,
:
}
)
;
if
(
.
)
{
this
.
.
error
(
` [GitServiceImpl][exec] git ${ args. join ( ' ' ) } [ ${ Math. round ( performance. now ( ) - timer) } ms] Error: ${ result. stderr} `
)
;
throw
new
Error
(
` Failed to execute git command (git ${ args. join ( ' ' ) } ). Error: ${ result. stderr} `
)
;
}
this
.
.
trace
(
` [GitServiceImpl][exec] git ${ args. join ( ' ' ) } [ ${ Math. round ( performance. now ( ) - timer) } ms] `
)
;
return
.
.
trim
(
)
;
}
catch
(
)
{
const
=
instanceof
Error
?
.
:
String
(
)
;
this
.
.
error
(
` [GitServiceImpl][exec] git ${ args. join ( ' ' ) } [ ${ Math. round ( performance. now ( ) - timer) } ms] Error: ${ errorMessage} `
)
;
throw
new
Error
(
` Failed to execute git command (git ${ args. join ( ' ' ) } ). Error: ${ errorMessage} `
)
;
}
}
async
initialize
(
)
:
Promise
<
void
>
{
if
(
this
.
.
get
(
)
)
{
return
;
}
await
waitForState
(
this
.
,
=>
,
undefined
,
cancelOnDispose
(
this
.
)
)
;
if
(
this
.
.
>
0
)
{
await
waitForState
(
this
.
,
=>
!==
undefined
,
undefined
,
cancelOnDispose
(
this
.
)
)
;
}
}
private
:
Promise
<
void
>
|
undefined
;
private
waitForInitialDiscovery
(
)
:
Promise
<
void
>
{
if
(
this
.
.
get
(
)
)
{
return
Promise
.
resolve
(
)
;
}
this
.
??=
raceTimeout
(
waitForState
(
this
.
,
=>
,
undefined
,
cancelOnDispose
(
this
.
)
)
.
catch
(
(
)
=>
undefined
)
,
INITIAL_DISCOVERY_TIMEOUT_MS
,
(
)
=>
this
.
.
warn
(
` [GitServiceImpl][waitForInitialDiscovery] Timed out after ${ INITIAL_DISCOVERY_TIMEOUT_MS } ms. `
)
)
.
then
(
(
)
=>
undefined
)
;
return
this
.
;
}
private
async
doOpenRepository
(
:
)
:
Promise
<
void
>
{
this
.
.
trace
(
` [GitServiceImpl][doOpenRepository] Repository: ${ repository. rootUri. toString ( ) } `
)
;
const
HEAD
=
observableFromEvent
(
this
,
.
.
as
<
void
>
,
(
)
=>
.
.
HEAD
)
;
await
waitForState
(
HEAD
,
=>
!==
undefined
,
undefined
,
cancelOnDispose
(
this
.
)
)
;
this
.
.
trace
(
` [GitServiceImpl][doOpenRepository] Repository initialized: ${ JSON . stringify ( HEAD . get ( ) ) } `
)
;
const
=
observableFromEvent
(
this
,
.
.
as
<
void
>
,
(
)
=>
.
.
)
;
const
=
observableSignalFromEvent
(
this
,
.
.
as
<
void
>
)
;
this
.
_register
(
autorun
(
=>
{
.
read
(
)
;
const
=
.
read
(
)
;
const
=
this
.
.
get
(
)
;
if
(
&&
!
&&
!
isEqual
(
.
,
.
)
)
{
return
;
}
const
=
.
repoToRepoContext
(
)
;
this
.
.
trace
(
` [GitServiceImpl][doOpenRepository] Active repository: ${ JSON . stringify ( repositoryContext) } `
)
;
this
.
.
set
(
,
undefined
)
;
}
)
)
;
const
=
.
repoToRepoContext
(
)
;
if
(
)
{
this
.
.
fire
(
)
;
}
}
private
doCloseRepository
(
:
)
:
void
{
this
.
.
trace
(
` [GitServiceImpl][doCloseRepository] Repository: ${ repository. rootUri. toString ( ) } `
)
;
const
=
.
repoToRepoContext
(
)
;
if
(
)
{
this
.
.
fire
(
)
;
}
}
private
async
waitForRepositoryState
(
:
)
:
Promise
<
void
>
{
if
(
.
.
HEAD
)
{
return
;
}
const
HEAD
=
observableFromEvent
(
this
,
.
.
as
<
void
>
,
(
)
=>
.
.
HEAD
)
;
await
waitForState
(
HEAD
,
=>
!==
undefined
,
undefined
,
cancelOnDispose
(
this
.
)
)
;
}
private
static
repoToRepoContext
(
:
)
:
;
private
static
repoToRepoContext
(
:
|
undefined
|
null
)
:
|
undefined
;
private
static
repoToRepoContext
(
:
|
undefined
|
null
)
:
|
undefined
{
if
(
!
)
{
return
undefined
;
}
return
new
RepoContextImpl
(
)
;
}
get
repositories
(
)
:
[
]
{
const
=
this
.
.
getExtensionApi
(
)
;
if
(
!
)
{
return
[
]
;
}
return
coalesce
(
.
.
filter
(
=>
.
.
HEAD
!==
undefined
)
.
map
(
=>
.
repoToRepoContext
(
)
)
)
;
}
}
export
class
RepoContextImpl
implements
RepoContext
{
public
readonly
=
this
.
.
;
public
readonly
=
this
.
.
;
public
readonly
=
this
.
.
;
public
readonly
=
this
.
.
.
HEAD
?.
;
public
readonly
=
this
.
.
.
HEAD
?.
;
public
readonly
=
this
.
.
.
HEAD
?.
;
public
readonly
=
this
.
.
.
HEAD
?.
;
public
readonly
=
this
.
.
.
HEAD
?.
?.
;
public
readonly
=
this
.
.
.
HEAD
?.
?.
;
public
readonly
=
this
.
.
.
!==
null
;
public
readonly
=
this
.
.
.
.
map
(
=>
.
)
;
public
readonly
=
this
.
.
.
.
map
(
=>
.
)
;
public
readonly
=
this
.
.
.
;
public
readonly
=
{
:
this
.
.
.
,
:
this
.
.
.
,
:
this
.
.
.
,
:
this
.
.
.
}
;
private
readonly
=
observableSignalFromEvent
(
this
,
this
.
.
.
as
<
void
>
)
;
public
readonly
:
<
string
|
undefined
>
=
this
.
.
map
(
(
)
=>
this
.
.
.
HEAD
?.
)
;
public
readonly
:
<
string
|
undefined
>
=
this
.
.
map
(
(
)
=>
this
.
.
.
HEAD
?.
)
;
public
readonly
:
<
string
|
undefined
>
=
this
.
.
map
(
(
)
=>
this
.
.
.
HEAD
?.
?.
)
;
public
readonly
:
<
string
|
undefined
>
=
this
.
.
map
(
(
)
=>
this
.
.
.
HEAD
?.
?.
)
;
public
readonly
:
<
boolean
>
=
this
.
.
map
(
(
)
=>
this
.
.
.
!==
null
)
;
private
readonly
=
new
BatchedProcessor< string , boolean >
(
async
(
)
=>
{
const
=
await
this
.
.
checkIgnore
(
)
;
return
.
map
(
=>
.
has
(
)
)
;
}
,
1000
)
;
private
readonly
=
new
CachedFunction
(
async
(
:
string
)
=>
{
const
=
.
parse
(
)
.
;
const
=
await
this
.
.
request
(
)
;
return
;
}
)
;
public
isIgnored
(
:
URI
)
:
Promise
<
boolean
>
{
return
this
.
.
get
(
.
toString
(
)
)
;
}
constructor
(
private
readonly
:
)
{
}
}