FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
commitforge/src/git.ts at main · doubleSlashde/commitforge · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
doubleSlashde
/
commitforge
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
commitforge
/
src
/
git.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
81 lines (69 loc) · 2.34 KB
Breadcrumbs
commitforge
/
src
/
git.ts
Copy path
File metadata and controls
81 lines (69 loc) · 2.34 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
import
*
as
vscode
from
'vscode'
;
import
{
execFile
}
from
'child_process'
;
import
{
promisify
}
from
'util'
;
const
execFileAsync
=
promisify
(
execFile
)
;
export
interface
GitExtension
{
getAPI
(
version
:
1
)
:
GitAPI
;
}
export
interface
GitAPI
{
repositories
:
Repository
[
]
;
}
export
interface
Repository
{
inputBox
:
{
value
:
string
}
;
rootUri
:
vscode
.
Uri
;
state
:
{
indexChanges
:
Change
[
]
;
workingTreeChanges
:
Change
[
]
;
}
;
diff
(
staged
?:
boolean
)
:
Promise
<
string
>
;
diffIndexWithHEAD
(
)
:
Promise
<
string
>
;
}
export
interface
Change
{
uri
:
vscode
.
Uri
;
status
:
number
;
}
export
function
getRepository
(
)
:
Repository
|
undefined
{
const
gitExt
=
vscode
.
extensions
.
getExtension
<
GitExtension
>
(
'vscode.git'
)
;
if
(
!
gitExt
?.
isActive
)
{
return
undefined
;
}
const
api
=
gitExt
.
exports
.
getAPI
(
1
)
;
const
activeUri
=
vscode
.
window
.
activeTextEditor
?.
document
.
uri
;
if
(
activeUri
)
{
const
match
=
api
.
repositories
.
find
(
(
r
)
=>
activeUri
.
fsPath
.
startsWith
(
r
.
rootUri
.
fsPath
)
)
;
if
(
match
)
return
match
;
}
return
api
.
repositories
[
0
]
;
}
export
async
function
getDiff
(
cwd
:
string
,
staged
:
boolean
)
:
Promise
<
string
>
{
const
args
=
staged
?
[
'diff'
,
'--staged'
]
:
[
'diff'
]
;
const
{
stdout
}
=
await
execFileAsync
(
'git'
,
args
,
{
cwd
,
maxBuffer
:
1024
*
1024
*
5
}
)
;
return
stdout
;
}
export
async
function
getDiffAgainstBranch
(
cwd
:
string
,
targetBranch
:
string
)
:
Promise
<
string
>
{
const
{
stdout
}
=
await
execFileAsync
(
'git'
,
[
'diff'
,
`
${
targetBranch
}
...HEAD`
]
,
{
cwd
,
maxBuffer
:
1024
*
1024
*
5
,
}
)
;
return
stdout
;
}
export
async
function
getCommitsSinceBranch
(
cwd
:
string
,
targetBranch
:
string
)
:
Promise
<
string
>
{
const
{
stdout
}
=
await
execFileAsync
(
'git'
,
[
'log'
,
`
${
targetBranch
}
..HEAD`
,
'--pretty=format:%s'
]
,
{
cwd
,
maxBuffer
:
1024
*
1024
,
}
)
;
return
stdout
;
}
export
async
function
getCurrentBranch
(
cwd
:
string
)
:
Promise
<
string
>
{
const
{
stdout
}
=
await
execFileAsync
(
'git'
,
[
'rev-parse'
,
'--abbrev-ref'
,
'HEAD'
]
,
{
cwd
}
)
;
return
stdout
.
trim
(
)
;
}
export
async
function
getLocalBranches
(
cwd
:
string
)
:
Promise
<
string
[
]
>
{
const
{
stdout
}
=
await
execFileAsync
(
'git'
,
[
'branch'
,
'--format=%(refname:short)'
]
,
{
cwd
}
)
;
return
stdout
.
split
(
'\n'
)
.
map
(
(
b
)
=>
b
.
trim
(
)
)
.
filter
(
Boolean
)
;
}
export
async
function
stageAll
(
cwd
:
string
)
:
Promise
<
void
>
{
await
execFileAsync
(
'git'
,
[
'add'
,
'-A'
]
,
{
cwd
}
)
;
}
Back
|
FazBrowse Home
|
New Git URL