Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
// In order to avoid hitting the command line limit due to large number of reference
// names (can happen when the `all` filter is used in the Source Control Graph view),
// we are passing the reference names via stdin.
.
=
.
.
join
(
'\n'
)
;
.
push
(
'--stdin'
)
;
}
if
(
?.
)
{
.
push
(
'--'
,
.
)
;
}
const
=
await
this
.
exec
(
,
)
;
if
(
.
)
{
// An empty repo
return
[
]
;
}
return
parseGitCommits
(
.
)
;
}
async
logFile
(
:
,
?
:
,
?
:
)
:
Promise
<
[
]
>
{
const
=
[
'log'
,
`--format=${COMMIT_FORMAT}`
,
'-z'
]
;
if
(
?.
&&
!
?.
)
{
.
push
(
`-n${options.maxEntries}`
)
;
}
if
(
?.
)
{
// If we are reversing, we must add a range (with HEAD) because we are using --ancestry-path for better reverse walking
if
(
?.
)
{
.
push
(
'--reverse'
,
'--ancestry-path'
,
`${options.hash}..HEAD`
)
;
}
else
{
.
push
(
.
)
;
}
}
if
(
?.
)
{
.
push
(
'--shortstat'
)
;
}
if
(
?.
)
{
.
push
(
'--author-date-order'
)
;
}
if
(
?.
)
{
.
push
(
'--follow'
)
;
}
.
push
(
'--'
,
.
)
;
try
{
const
=
await
this
.
exec
(
,
{
}
)
;
if
(
.
)
{
// No file history, e.g. a new file or untracked
return
[
]
;
}
return
parseGitCommits
(
.
)
;
}
catch
(
)
{
// Repository has no commits yet
if
(
/does not have any commits yet/
.
test
(
.
)
)
{
return
[
]
;
}
throw
;
}
}
async
reflog
(
:
string
,
:
string
)
:
Promise
<
string
[
]
>
{
const
=
[
'reflog'
,
,
`--grep-reflog=${pattern}`
]
;
const
=
await
this
.
exec
(
)
;
if
(
.
)
{
return
[
]
;
}
return
.
.
split
(
'\n'
)
.
filter
(
=>
!
!
)
;
}
async
buffer
(
:
string
,
:
string
)
:
Promise
<
>
{
const
=
this
.
sanitizeRelativePath
(
)
;
const
=
this
.
stream
(
[
'show'
,
'--textconv'
,
`${ref}:${relativePath}`
]
)
;
if
(
!
.
)
{
return
Promise
.
reject<Buffer>
(
'Can\'t open file from git'
)
;
}
const
{
,
,
}
=
await
exec
(
)
;
if
(
)
{
const
=
new
GitError
(
{
:
'Could not show object.'
,
}
)
;
if
(
/exists on disk, but not in/
.
test
(
)
)
{
.
=
.
;
}
return
Promise
.
reject<Buffer>
(
)
;
}
return
;
}
async
getObjectDetails
(
:
string
,
:
string
)
:
Promise
<
{
:
string
;
:
string
;
:
number
}
>
{
if
(
!
||
===
':1'
||
===
':2'
||
===
':3'
)
{
// index
const
=
await
this
.
lsfiles
(
)
;
if
(
.
===
0
)
{
throw
new
GitError
(
{
:
'Path not known by git'
,
:
.
}
)
;
}
const
{
,
}
=
!==
''
?
.
find
(
=>
.
===
.
substring
(
1
)
)
??
[
0
]
:
[
0
]
;
const
=
await
this
.
exec
(
[
'cat-file'
,
'-s'
,
]
)
;
const
=
parseInt
(
.
)
;
return
{
,
,
}
;
}
const
=
await
this
.
lstree
(
,
)
;
if
(
.
===
0
)
{
throw
new
GitError
(
{
:
'Path not known by git'
,
:
.
}
)
;
}
const
{
,
,
}
=
[
0
]
;
return
{
,
,
:
parseInt
(
)
||
0
}
;
}
async
lstree
(
:
string
,
?
:
string
,
?
:
{
?
:
boolean
}
)
:
Promise
<
[
]
>
{
const
=
[
'ls-tree'
,
'-l'
]
;
if
(
?.
)
{
.
push
(
'-r'
)
;
}
.
push
(
)
;
if
(
)
{
.
push
(
'--'
,
this
.
sanitizeRelativePath
(
)
)
;
}
const
{
}
=
await
this
.
exec
(
)
;
return
parseLsTree
(
)
;
}
async
lsfiles
(
:
string
)
:
Promise
<
[
]
>
{
const
=
[
'ls-files'
,
'--stage'
]
;
const
=
this
.
sanitizeRelativePath
(
)
;
if
(
)
{
.
push
(
'--'
,
)
;
}
const
{
}
=
await
this
.
exec
(
)
;
return
parseLsFiles
(
)
;
}
async
getGitFilePath
(
:
string
,
:
string
)
:
Promise
<
string
>
{
const
:
{
:
string
}
[
]
=
?
await
this
.
lstree
(
,
undefined
,
{
:
true
}
)
:
await
this
.
lsfiles
(
this
.
)
;
const
=
this
.
sanitizeRelativePath
(
)
.
toLowerCase
(
)
;
const
=
.
find
(
=>
.
.
toLowerCase
(
)
===
)
;
if
(
!
)
{
throw
new
GitError
(
{
:
`Git relative path not found. Was looking for ${relativePathLowercase} among ${JSON.stringify(elements.map(({ file })=> file),null,2)}`
,
}
)
;
}
return
.
join
(
this
.
,
.
)
;
}
async
detectObjectType
(
:
string
)
:
Promise
<
{
:
string
;
?
:
string
}
>
{
const
=
await
this
.
stream
(
[
'show'
,
'--textconv'
,
]
)
;
const
=
await
readBytes
(
.
!
,
4100
)
;
try
{
.
kill
(
)
;
}
catch
(
)
{
// noop
}
const
=
detectUnicodeEncoding
(
)
;
let
=
true
;
if
(
!==
.
&&
!==
.
)
{
for
(
let
=
0
;
<
.
;
++
)
{
if
(
.
readInt8
(
)
===
0
)
{
=
false
;
break
;
}
}
}
if
(
!
)
{
const
=
await
fileTypeFromBuffer
(
)
;
if
(
!
)
{
return
{
:
'application/octet-stream'
}
;
}
else
{
return
{
:
.
}
;
}
}
if
(
)
{
return
{
:
'text/plain'
,
}
;
}
else
{
// TODO@JOAO: read the setting OUTSIDE!
return
{
:
'text/plain'
}
;
}
}
async
apply
(
:
string
,
?
:
{
?
:
boolean
;
?
:
boolean
;
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'apply'
,
]
;
if
(
?.
)
{
.
push
(
'--allow-empty'
)
;
}
if
(
?.
)
{
.
push
(
'--reverse'
)
;
}
if
(
?.
)
{
.
push
(
'--3way'
)
;
}
try
{
await
this
.
exec
(
)
;
}
catch
(
)
{
if
(
/patch does not apply/
.
test
(
.
)
)
{
.
=
.
;
}
throw
;
}
}
async
diff
(
=
false
)
:
Promise
<
string
>
{
const
=
[
'diff'
]
;
if
(
)
{
.
push
(
'--cached'
)
;
}
const
=
await
this
.
exec
(
)
;
return
.
;
}
diffWithHEAD
(
)
:
Promise
<
[
]
>
;
diffWithHEAD
(
:
string
)
:
Promise
<
string
>
;
diffWithHEAD
(
?
:
string
|
undefined
)
:
Promise
<
string
|
[
]
>
;
async
diffWithHEAD
(
?
:
string
|
undefined
)
:
Promise
<
string
|
[
]
>
{
if
(
!
)
{
return
await
this
.
diffFiles
(
undefined
,
{
:
false
}
)
;
}
const
=
[
'diff'
,
'--'
,
this
.
sanitizeRelativePath
(
)
]
;
const
=
await
this
.
exec
(
)
;
return
.
;
}
async
diffWithHEADShortStats
(
?
:
string
)
:
Promise
<
>
{
return
this
.
diffFilesShortStat
(
undefined
,
{
:
false
,
}
)
;
}
diffWith
(
:
string
)
:
Promise
<
[
]
>
;
diffWith
(
:
string
,
:
string
)
:
Promise
<
string
>
;
diffWith
(
:
string
,
?
:
string
|
undefined
)
:
Promise
<
string
|
[
]
>
;
async
diffWith
(
:
string
,
?
:
string
)
:
Promise
<
string
|
[
]
>
{
if
(
!
)
{
return
await
this
.
diffFiles
(
,
{
:
false
}
)
;
}
const
=
[
'diff'
,
,
'--'
,
this
.
sanitizeRelativePath
(
)
]
;
const
=
await
this
.
exec
(
)
;
return
.
;
}
diffIndexWithHEAD
(
)
:
Promise
<
[
]
>
;
diffIndexWithHEAD
(
:
string
)
:
Promise
<
string
>
;
diffIndexWithHEAD
(
?
:
string
|
undefined
)
:
Promise
<
[
]
>
;
async
diffIndexWithHEAD
(
?
:
string
)
:
Promise
<
string
|
[
]
>
{
if
(
!
)
{
return
await
this
.
diffFiles
(
undefined
,
{
:
true
}
)
;
}
const
=
[
'diff'
,
'--cached'
,
'--'
,
this
.
sanitizeRelativePath
(
)
]
;
const
=
await
this
.
exec
(
)
;
return
.
;
}
async
diffIndexWithHEADShortStats
(
?
:
string
)
:
Promise
<
>
{
return
this
.
diffFilesShortStat
(
undefined
,
{
:
true
,
}
)
;
}
diffIndexWith
(
:
string
)
:
Promise
<
[
]
>
;
diffIndexWith
(
:
string
,
:
string
)
:
Promise
<
string
>
;
diffIndexWith
(
:
string
,
?
:
string
|
undefined
)
:
Promise
<
string
|
[
]
>
;
async
diffIndexWith
(
:
string
,
?
:
string
)
:
Promise
<
string
|
[
]
>
{
if
(
!
)
{
return
await
this
.
diffFiles
(
,
{
:
true
}
)
;
}
const
=
[
'diff'
,
'--cached'
,
,
'--'
,
this
.
sanitizeRelativePath
(
)
]
;
const
=
await
this
.
exec
(
)
;
return
.
;
}
async
diffBlobs
(
:
string
,
:
string
)
:
Promise
<
string
>
{
const
=
[
'diff'
,
,
]
;
const
=
await
this
.
exec
(
)
;
return
.
;
}
diffBetween
(
:
string
,
:
string
)
:
Promise
<
[
]
>
;
diffBetween
(
:
string
,
:
string
,
:
string
)
:
Promise
<
string
>
;
diffBetween
(
:
string
,
:
string
,
?
:
string
|
undefined
)
:
Promise
<
string
|
[
]
>
;
async
diffBetween
(
:
string
,
:
string
,
?
:
string
)
:
Promise
<
string
|
[
]
>
{
const
=
`${ref1}...${ref2}`
;
if
(
!
)
{
return
await
this
.
diffFiles
(
,
{
:
false
}
)
;
}
const
=
[
'diff'
,
,
'--'
,
this
.
sanitizeRelativePath
(
)
]
;
const
=
await
this
.
exec
(
)
;
return
.
.
trim
(
)
;
}
async
diffBetweenPatch
(
:
string
,
:
{
?
:
string
}
)
:
Promise
<
string
>
{
const
=
[
'diff'
,
,
'--'
]
;
if
(
.
)
{
.
push
(
this
.
sanitizeRelativePath
(
.
)
)
;
}
const
=
await
this
.
exec
(
)
;
return
.
;
}
async
diffBetweenWithStats
(
:
string
,
:
{
?
:
string
;
?
:
number
}
)
:
Promise
<
[
]
>
{
const
=
[
'diff'
,
'--raw'
,
'--numstat'
,
'--diff-filter=ADMR'
,
'-z'
,
]
;
if
(
.
)
{
.
push
(
`--find-renames=${options.similarityThreshold}%`
)
;
}
.
push
(
...
[
,
'--'
]
)
;
if
(
.
)
{
.
push
(
this
.
sanitizeRelativePath
(
.
)
)
;
}
const
=
await
this
.
exec
(
)
;
if
(
.
)
{
return
[
]
;
}
return
parseGitChangesRaw
(
this
.
,
.
)
;
}
private
async
diffFiles
(
:
string
|
undefined
,
:
{
:
boolean
;
?
:
number
}
)
:
Promise
<
[
]
>
{
const
=
[
'diff'
,
'--name-status'
,
'-z'
,
'--diff-filter=ADMR'
]
;
if
(
.
)
{
.
push
(
'--cached'
)
;
}
if
(
.
)
{
.
push
(
`--find-renames=${options.similarityThreshold}%`
)
;
}
if
(
)
{
.
push
(
)
;
}
.
push
(
'--'
)
;
const
=
await
this
.
exec
(
)
;
if
(
.
)
{
return
[
]
;
}
return
parseGitChanges
(
this
.
,
.
)
;
}
private
async
diffFilesShortStat
(
:
string
|
undefined
,
:
{
:
boolean
;
?
:
string
}
)
:
Promise
<
>
{
const
=
[
'diff'
,
'--shortstat'
]
;
if
(
.
)
{
.
push
(
'--cached'
)
;
}
if
(
!==
undefined
)
{
.
push
(
)
;
}
.
push
(
'--'
)
;
if
(
.
)
{
.
push
(
this
.
sanitizeRelativePath
(
.
)
)
;
}
const
=
await
this
.
exec
(
)
;
if
(
.
)
{
return
{
:
0
,
:
0
,
:
0
}
;
}
return
parseGitDiffShortStat
(
.
.
trim
(
)
)
;
}
async
diffTrees
(
:
string
,
?
:
string
,
?
:
{
?
:
number
}
)
:
Promise
<
[
]
>
{
const
=
[
'diff-tree'
,
'-r'
,
'--raw'
,
'--numstat'
,
'--diff-filter=ADMR'
,
'-z'
]
;
if
(
?.
)
{
.
push
(
`--find-renames=${options.similarityThreshold}%`
)
;
}
.
push
(
)
;
if
(
)
{
.
push
(
)
;
}
.
push
(
'--'
)
;
const
=
await
this
.
exec
(
)
;
if
(
.
)
{
return
[
]
;
}
return
parseGitChangesRaw
(
this
.
,
.
)
;
}
async
getMergeBase
(
:
string
,
:
string
,
...
:
string
[
]
)
:
Promise
<
string
|
undefined
>
{
try
{
const
=
[
'merge-base'
]
;
if
(
.
!==
0
)
{
.
push
(
'--octopus'
)
;
.
push
(
...
)
;
}
.
push
(
,
)
;
const
=
await
this
.
exec
(
)
;
return
.
.
trim
(
)
;
}
catch
(
)
{
return
undefined
;
}
}
async
hashObject
(
:
string
)
:
Promise
<
string
>
{
const
=
[
'hash-object'
,
'-w'
,
'--stdin'
]
;
const
=
await
this
.
exec
(
,
{
:
}
)
;
return
.
.
trim
(
)
;
}
async
add
(
:
string
[
]
,
?
:
{
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'add'
]
;
if
(
&&
.
)
{
.
push
(
'-u'
)
;
}
else
{
.
push
(
'-A'
)
;
}
if
(
&&
.
)
{
for
(
const
of
splitInChunks
(
.
map
(
=>
this
.
sanitizeRelativePath
(
)
)
,
MAX_CLI_LENGTH
)
)
{
await
this
.
exec
(
[
...
,
'--'
,
...
]
)
;
}
}
else
{
await
this
.
exec
(
[
...
,
'--'
,
'.'
]
)
;
}
}
async
rm
(
:
string
[
]
)
:
Promise
<
void
>
{
const
=
[
'rm'
,
'--'
]
;
if
(
!
||
!
.
)
{
return
;
}
.
push
(
...
.
map
(
=>
this
.
sanitizeRelativePath
(
)
)
)
;
await
this
.
exec
(
)
;
}
async
stage
(
:
string
,
:
)
:
Promise
<
void
>
{
const
=
this
.
sanitizeRelativePath
(
)
;
const
=
this
.
stream
(
[
'hash-object'
,
'--stdin'
,
'-w'
,
'--path'
,
]
,
{
:
[
null
,
null
,
null
]
}
)
;
if
(
!
.
)
{
throw
new
GitError
(
{
:
'Failed to spawn git process'
,
:
-
1
}
)
;
}
.
.
end
(
)
;
const
{
,
}
=
await
exec
(
)
;
const
=
.
toString
(
'utf8'
)
;
if
(
)
{
throw
new
GitError
(
{
:
'Could not hash object.'
,
:
}
)
;
}
const
=
await
this
.
getCommit
(
'HEAD'
)
.
then
(
(
)
=>
'HEAD'
,
(
)
=>
''
)
;
let
:
string
;
let
:
string
=
''
;
try
{
const
=
await
this
.
getObjectDetails
(
,
)
;
=
.
;
}
catch
(
)
{
if
(
.
!==
.
)
{
throw
;
}
=
'100644'
;
=
'--add'
;
}
await
this
.
exec
(
[
'update-index'
,
,
'--cacheinfo'
,
,
,
]
)
;
}
async
checkout
(
:
string
,
:
string
[
]
,
:
{
?
:
boolean
;
?
:
boolean
}
=
.
create
(
null
)
)
:
Promise
<
void
>
{
const
=
[
'checkout'
,
'-q'
]
;
if
(
.
)
{
.
push
(
'--track'
)
;
}
if
(
.
)
{
.
push
(
'--detach'
)
;
}
if
(
)
{
.
push
(
)
;
}
try
{
if
(
&&
.
>
0
)
{
for
(
const
of
splitInChunks
(
.
map
(
=>
this
.
sanitizeRelativePath
(
)
)
,
MAX_CLI_LENGTH
)
)
{
await
this
.
exec
(
[
...
,
'--'
,
...
]
)
;
}
}
else
{
await
this
.
exec
(
)
;
}
}
catch
(
)
{
if
(
/Please,? commit your changes or stash them/
.
test
(
.
||
''
)
)
{
.
=
.
;
.
=
;
}
else
if
(
/You are on a branch yet to be born/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
commit
(
:
string
|
undefined
,
:
=
.
create
(
null
)
)
:
Promise
<
void
>
{
const
=
[
'commit'
,
'--quiet'
]
;
const
:
=
{
}
;
if
(
)
{
.
=
;
.
push
(
'--allow-empty-message'
,
'--file'
,
'-'
)
;
}
if
(
.
)
{
.
push
(
'--verbose'
)
;
}
if
(
.
)
{
.
push
(
'--all'
)
;
}
if
(
.
)
{
.
push
(
'--amend'
)
;
}
if
(
!
.
)
{
if
(
!
)
{
if
(
.
)
{
.
push
(
'--no-edit'
)
;
}
else
{
.
=
''
;
.
push
(
'--file'
,
'-'
)
;
}
}
.
push
(
'--allow-empty-message'
)
;
}
if
(
.
)
{
.
push
(
'--signoff'
)
;
}
if
(
.
!==
undefined
)
{
if
(
.
)
{
.
push
(
'-S'
)
;
}
else
{
.
push
(
'--no-gpg-sign'
)
;
}
}
if
(
.
)
{
.
push
(
'--allow-empty'
)
;
}
if
(
.
)
{
.
push
(
'--no-verify'
)
;
}
if
(
.
??
true
)
{
// Stops git from guessing at user/email
.
splice
(
0
,
0
,
'-c'
,
'user.useConfigOnly=true'
)
;
}
try
{
await
this
.
exec
(
,
)
;
}
catch
(
)
{
await
this
.
handleCommitError
(
)
;
}
}
async
rebaseAbort
(
)
:
Promise
<
void
>
{
await
this
.
exec
(
[
'rebase'
,
'--abort'
]
)
;
}
async
rebaseContinue
(
)
:
Promise
<
void
>
{
const
=
[
'rebase'
,
'--continue'
]
;
try
{
await
this
.
exec
(
,
{
:
{
GIT_EDITOR
:
'true'
}
}
)
;
}
catch
(
)
{
await
this
.
handleCommitError
(
)
;
}
}
private
async
handleCommitError
(
:
unknown
)
:
Promise
<
void
>
{
if
(
instanceof
GitError
&&
/not possible because you have unmerged files/
.
test
(
.
||
''
)
)
{
.
=
.
;
throw
;
}
else
if
(
instanceof
GitError
&&
/Aborting commit due to empty commit message/
.
test
(
.
||
''
)
)
{
.
=
.
;
throw
;
}
try
{
await
this
.
exec
(
[
'config'
,
'--get-all'
,
'user.name'
]
)
;
}
catch
(
)
{
.
=
.
;
throw
;
}
try
{
await
this
.
exec
(
[
'config'
,
'--get-all'
,
'user.email'
]
)
;
}
catch
(
)
{
.
=
.
;
throw
;
}
throw
;
}
async
branch
(
:
string
,
:
boolean
,
?
:
string
)
:
Promise
<
void
>
{
const
=
?
[
'checkout'
,
'-q'
,
'-b'
,
,
'--no-track'
]
:
[
'branch'
,
'-q'
,
]
;
if
(
)
{
.
push
(
)
;
}
await
this
.
exec
(
)
;
}
async
deleteBranch
(
:
string
,
?
:
boolean
)
:
Promise
<
void
>
{
const
=
[
'branch'
,
?
'-D'
:
'-d'
,
]
;
await
this
.
exec
(
)
;
}
async
renameBranch
(
:
string
)
:
Promise
<
void
>
{
const
=
[
'branch'
,
'-m'
,
]
;
await
this
.
exec
(
)
;
}
async
move
(
:
string
,
:
string
)
:
Promise
<
void
>
{
const
=
[
'mv'
,
,
]
;
await
this
.
exec
(
)
;
}
async
setBranchUpstream
(
:
string
,
:
string
)
:
Promise
<
void
>
{
const
=
[
'branch'
,
'--set-upstream-to'
,
,
]
;
await
this
.
exec
(
)
;
}
async
deleteRef
(
:
string
)
:
Promise
<
void
>
{
const
=
[
'update-ref'
,
'-d'
,
]
;
await
this
.
exec
(
)
;
}
async
merge
(
:
string
)
:
Promise
<
void
>
{
const
=
[
'merge'
,
]
;
try
{
await
this
.
exec
(
)
;
}
catch
(
)
{
if
(
/^CONFLICT /m
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
mergeAbort
(
)
:
Promise
<
void
>
{
await
this
.
exec
(
[
'merge'
,
'--abort'
]
)
;
}
async
tag
(
:
{
:
string
;
?
:
string
;
?
:
string
}
)
:
Promise
<
void
>
{
let
=
[
'tag'
]
;
if
(
.
)
{
=
[
...
,
'-a'
,
.
,
'-m'
,
.
]
;
}
else
{
=
[
...
,
.
]
;
}
if
(
.
)
{
.
push
(
.
)
;
}
await
this
.
exec
(
)
;
}
async
deleteTag
(
:
string
)
:
Promise
<
void
>
{
const
=
[
'tag'
,
'-d'
,
]
;
await
this
.
exec
(
)
;
}
async
addWorktree
(
:
{
:
string
;
:
string
;
?
:
string
;
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'worktree'
,
'add'
]
;
if
(
.
)
{
.
push
(
'-b'
,
.
)
;
}
if
(
.
)
{
.
push
(
'--no-track'
)
;
}
.
push
(
.
,
.
)
;
await
this
.
exec
(
)
;
}
async
deleteWorktree
(
:
string
,
?
:
{
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'worktree'
,
'remove'
]
;
if
(
?.
)
{
.
push
(
'--force'
)
;
}
.
push
(
)
;
await
this
.
exec
(
)
;
}
async
deleteRemoteRef
(
:
string
,
:
string
,
?
:
{
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'push'
,
,
'--delete'
]
;
if
(
?.
)
{
.
push
(
'--force'
)
;
}
.
push
(
)
;
await
this
.
exec
(
)
;
}
async
clean
(
:
string
[
]
)
:
Promise
<
void
>
{
const
=
groupBy
(
.
map
(
)
,
=>
.
dirname
(
)
)
;
const
=
.
keys
(
)
.
map
(
=>
[
]
)
;
const
=
new
Limiter<IExecutionResult<string>>
(
5
)
;
const
:
Promise
<
<
string
>>
[
]
=
[
]
;
const
=
[
'clean'
,
'-f'
,
'-q'
]
;
for
(
const
of
)
{
for
(
const
of
splitInChunks
(
.
map
(
=>
this
.
sanitizeRelativePath
(
)
)
,
MAX_CLI_LENGTH
)
)
{
.
push
(
.
queue
(
(
)
=>
this
.
exec
(
[
...
,
'--'
,
...
]
)
)
)
;
}
}
await
Promise
.
all
(
)
;
}
async
undo
(
)
:
Promise
<
void
>
{
await
this
.
exec
(
[
'clean'
,
'-fd'
]
)
;
try
{
await
this
.
exec
(
[
'checkout'
,
'--'
,
'.'
]
)
;
}
catch
(
)
{
if
(
/did not match any file\(s\) known to git\./
.
test
(
.
||
''
)
)
{
return
;
}
throw
;
}
}
async
reset
(
:
string
,
:
boolean
=
false
)
:
Promise
<
void
>
{
const
=
[
'reset'
,
?
'--hard'
:
'--soft'
,
]
;
await
this
.
exec
(
)
;
}
async
revert
(
:
string
,
:
string
[
]
)
:
Promise
<
void
>
{
const
=
await
this
.
exec
(
[
'branch'
]
)
;
let
:
string
[
]
;
// In case there are no branches, we must use rm --cached
if
(
!
.
)
{
=
[
'rm'
,
'--cached'
,
'-r'
]
;
}
else
{
=
[
'reset'
,
'-q'
,
]
;
}
try
{
if
(
&&
.
>
0
)
{
for
(
const
of
splitInChunks
(
.
map
(
=>
this
.
sanitizeRelativePath
(
)
)
,
MAX_CLI_LENGTH
)
)
{
await
this
.
exec
(
[
...
,
'--'
,
...
]
)
;
}
}
else
{
await
this
.
exec
(
[
...
,
'--'
,
'.'
]
)
;
}
}
catch
(
)
{
// In case there are merge conflicts to be resolved, git reset will output
// some "needs merge" data. We try to get around that.
if
(
/([^:]+: needs merge\n)+/m
.
test
(
.
||
''
)
)
{
return
;
}
throw
;
}
}
async
restore
(
:
string
[
]
,
?
:
{
?
:
boolean
;
?
:
string
}
)
:
Promise
<
void
>
{
const
=
[
'restore'
]
;
if
(
?.
)
{
.
push
(
'--staged'
)
;
}
if
(
?.
)
{
.
push
(
'--source'
,
.
)
;
}
if
(
.
>
0
)
{
for
(
const
of
splitInChunks
(
.
map
(
=>
this
.
sanitizeRelativePath
(
)
)
,
MAX_CLI_LENGTH
)
)
{
await
this
.
exec
(
[
...
,
'--'
,
...
]
)
;
}
}
else
{
await
this
.
exec
(
[
...
,
'--'
,
'.'
]
)
;
}
}
async
addRemote
(
:
string
,
:
string
)
:
Promise
<
void
>
{
const
=
[
'remote'
,
'add'
,
,
]
;
await
this
.
exec
(
)
;
}
async
removeRemote
(
:
string
)
:
Promise
<
void
>
{
const
=
[
'remote'
,
'remove'
,
]
;
await
this
.
exec
(
)
;
}
async
renameRemote
(
:
string
,
:
string
)
:
Promise
<
void
>
{
const
=
[
'remote'
,
'rename'
,
,
]
;
await
this
.
exec
(
)
;
}
async
fetch
(
:
{
?
:
string
;
?
:
string
;
?
:
boolean
;
?
:
boolean
;
?
:
number
;
?
:
boolean
;
readonly
?
:
}
=
{
}
)
:
Promise
<
void
>
{
const
=
[
'fetch'
]
;
const
:
=
{
:
.
,
:
{
'GIT_HTTP_USER_AGENT'
:
this
.
.
}
}
;
if
(
.
)
{
.
push
(
.
)
;
if
(
.
)
{
.
push
(
.
)
;
}
}
else
if
(
.
)
{
.
push
(
'--all'
)
;
}
if
(
.
)
{
.
push
(
'--prune'
)
;
}
if
(
typeof
.
===
'number'
)
{
.
push
(
`--depth=${options.depth}`
)
;
}
if
(
.
)
{
.
!
[
'VSCODE_GIT_FETCH_SILENT'
]
=
'true'
;
}
try
{
await
this
.
exec
(
,
)
;
}
catch
(
)
{
if
(
/No remote repository specified\./
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/Could not read from remote repository/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/! \[rejected\].*\(non-fast-forward\)/m
.
test
(
.
||
''
)
)
{
// The local branch has outgoing changes and it cannot be fast-forwarded.
.
=
.
;
}
throw
;
}
}
async
fetchTags
(
:
{
:
string
;
:
string
[
]
;
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'fetch'
]
;
const
:
=
{
:
{
'GIT_HTTP_USER_AGENT'
:
this
.
.
}
}
;
.
push
(
.
)
;
for
(
const
of
.
)
{
.
push
(
`refs/tags/${tag}:refs/tags/${tag}`
)
;
}
if
(
.
)
{
.
push
(
'--force'
)
;
}
await
this
.
exec
(
,
)
;
}
async
pull
(
?
:
boolean
,
?
:
string
,
?
:
string
,
:
=
{
}
)
:
Promise
<
boolean
>
{
const
=
[
'pull'
]
;
if
(
.
)
{
.
push
(
'--tags'
)
;
}
if
(
.
)
{
.
push
(
'--unshallow'
)
;
}
// --auto-stash option is only available `git pull --merge` starting with git 2.27.0
if
(
.
&&
this
.
.
compareGitVersionTo
(
'2.27.0'
)
!==
-
1
)
{
.
push
(
'--autostash'
)
;
}
if
(
)
{
.
push
(
'-r'
)
;
}
if
(
&&
)
{
.
push
(
)
;
.
push
(
)
;
}
try
{
const
=
await
this
.
exec
(
,
{
:
.
,
:
{
'GIT_HTTP_USER_AGENT'
:
this
.
.
}
}
)
;
return
!
/Already up to date/i
.
test
(
.
)
;
}
catch
(
)
{
if
(
/^CONFLICT \([^)]+\): \b/m
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/Please tell me who you are\./
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/Could not read from remote repository/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/Pull(?:ing)? is not possible because you have unmerged files|Cannot pull with rebase: You have unstaged changes|Your local changes to the following files would be overwritten|Please, commit your changes before you can merge/i
.
test
(
.
)
)
{
.
=
.
.
replace
(
/Cannot pull with rebase: You have unstaged changes/i
,
'Cannot pull with rebase, you have unstaged changes'
)
;
.
=
.
;
}
else
if
(
/cannot lock ref|unable to update local ref/i
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/cannot rebase onto multiple branches/i
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/! \[rejected\].*\(would clobber existing tag\)/m
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
rebase
(
:
string
,
:
=
{
}
)
:
Promise
<
void
>
{
const
=
[
'rebase'
]
;
.
push
(
)
;
try
{
await
this
.
exec
(
,
)
;
}
catch
(
)
{
if
(
/^CONFLICT \([^)]+\): \b/m
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/cannot rebase onto multiple branches/i
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
push
(
?
:
string
,
?
:
string
,
:
boolean
=
false
,
=
false
,
?
:
,
=
false
)
:
Promise
<
void
>
{
const
=
[
'push'
]
;
if
(
===
.
||
===
.
)
{
.
push
(
'--force-with-lease'
)
;
if
(
===
.
&&
this
.
.
compareGitVersionTo
(
'2.30'
)
!==
-
1
)
{
.
push
(
'--force-if-includes'
)
;
}
}
else
if
(
===
.
)
{
.
push
(
'--force'
)
;
}
if
(
)
{
.
push
(
'-u'
)
;
}
if
(
)
{
.
push
(
'--follow-tags'
)
;
}
if
(
)
{
.
push
(
'--tags'
)
;
}
if
(
)
{
.
push
(
)
;
}
if
(
)
{
.
push
(
)
;
}
try
{
await
this
.
exec
(
,
{
:
{
'GIT_HTTP_USER_AGENT'
:
this
.
.
}
}
)
;
}
catch
(
)
{
if
(
/^error: failed to push some refs to\b/m
.
test
(
.
||
''
)
)
{
if
(
===
.
&&
/! \[rejected\].*\(stale info\)/m
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
===
.
&&
/! \[rejected\].*\(remote ref updated since checkout\)/m
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
{
.
=
.
;
}
}
else
if
(
/Permission.*denied/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/Could not read from remote repository/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/^fatal: The current branch .* has no upstream branch/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
cherryPick
(
:
string
)
:
Promise
<
void
>
{
try
{
await
this
.
exec
(
[
'cherry-pick'
,
]
)
;
}
catch
(
)
{
if
(
/The previous cherry-pick is now empty, possibly due to conflict resolution./
.
test
(
.
??
''
)
)
{
// Abort cherry-pick
await
this
.
cherryPickAbort
(
)
;
.
=
.
;
}
else
{
// Conflict during cherry-pick
.
=
.
;
}
throw
;
}
}
async
cherryPickAbort
(
)
:
Promise
<
void
>
{
await
this
.
exec
(
[
'cherry-pick'
,
'--abort'
]
)
;
}
async
blame
(
:
string
)
:
Promise
<
string
>
{
try
{
const
=
[
'blame'
,
'--'
,
this
.
sanitizeRelativePath
(
)
]
;
const
=
await
this
.
exec
(
)
;
return
.
.
trim
(
)
;
}
catch
(
)
{
if
(
/^fatal: no such path/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
blame2
(
:
string
,
?
:
string
,
?
:
boolean
)
:
Promise
<
[
]
|
undefined
>
{
try
{
const
=
[
'blame'
,
'--root'
,
'--incremental'
]
;
if
(
)
{
.
push
(
'-w'
)
;
}
if
(
)
{
.
push
(
)
;
}
.
push
(
'--'
,
this
.
sanitizeRelativePath
(
)
)
;
const
=
await
this
.
exec
(
)
;
return
parseGitBlame
(
.
.
trim
(
)
)
;
}
catch
(
)
{
return
undefined
;
}
}
async
createStash
(
?
:
string
,
?
:
boolean
,
?
:
boolean
)
:
Promise
<
void
>
{
try
{
const
=
[
'stash'
,
'push'
]
;
if
(
)
{
.
push
(
'-u'
)
;
}
if
(
)
{
.
push
(
'-S'
)
;
}
if
(
)
{
.
push
(
'-m'
,
)
;
}
await
this
.
exec
(
)
;
}
catch
(
)
{
if
(
/No local changes to save/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
popStash
(
?
:
number
,
?
:
{
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'stash'
,
'pop'
]
;
if
(
?.
)
{
.
push
(
'--index'
)
;
}
await
this
.
popOrApplyStash
(
,
)
;
}
async
applyStash
(
?
:
number
,
?
:
{
?
:
boolean
}
)
:
Promise
<
void
>
{
const
=
[
'stash'
,
'apply'
]
;
if
(
?.
)
{
.
push
(
'--index'
)
;
}
await
this
.
popOrApplyStash
(
,
)
;
}
private
async
popOrApplyStash
(
:
string
[
]
,
?
:
number
)
:
Promise
<
void
>
{
try
{
if
(
typeof
===
'number'
)
{
.
push
(
`stash@{${index}}`
)
;
}
await
this
.
exec
(
)
;
}
catch
(
)
{
if
(
/No stash found/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/error: Your local changes to the following files would be overwritten/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
else
if
(
/^CONFLICT/m
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
dropStash
(
?
:
number
)
:
Promise
<
void
>
{
const
=
[
'stash'
]
;
if
(
typeof
===
'number'
)
{
.
push
(
'drop'
)
;
.
push
(
`stash@{${index}}`
)
;
}
else
{
.
push
(
'clear'
)
;
}
try
{
await
this
.
exec
(
)
;
}
catch
(
)
{
if
(
/No stash found/
.
test
(
.
||
''
)
)
{
.
=
.
;
}
throw
;
}
}
async
showStash
(
:
number
)
:
Promise
<
[
]
|
undefined
>
{
const
=
[
'stash'
,
'show'
,
`stash@{${index}}`
,
'--name-status'
,
'-z'
,
'-u'
]
;
try
{
const
=
await
this
.
exec
(
)
;
if
(
.
)
{
return
[
]
;
}
return
parseGitChanges
(
this
.
,
.
.
trim
(
)
)
;
}
catch
(
)
{
if
(
/No stash found/
.
test
(
.
||
''
)
)
{
return
undefined
;
}
throw
;
}
}
async
getStatus
(
?
:
{
?
:
number
;
?
:
boolean
;
?
:
number
;
?
:
'mixed'
|
'separate'
|
'hidden'
;
?
:
}
)
:
Promise
<
{
:
[
]
;
:
number
;
:
boolean
}
>
{
if
(
?.
&&
?.
.
)
{
throw
new
CancellationError
(
)
;
}
const
:
[
]
=
[
]
;
const
=
{
GIT_OPTIONAL_LOCKS
:
'0'
}
;
const
=
[
'status'
,
'-z'
]
;
if
(
?.
===
'hidden'
)
{
.
push
(
'-uno'
)
;
}
else
{
.
push
(
'-uall'
)
;
}
if
(
?.
)
{
.
push
(
'--ignore-submodules'
)
;
}
// --find-renames option is only available starting with git 2.18.0