@@ -27,41 +27,48 @@ export interface GitCommit extends RawGitCommit {
27
27
isBreaking : boolean ;
28
28
}
29
29
30
- export async function getLastGitTag ( ) {
30
+ export async function getLastGitTag ( cwd ?: string ) {
31
31
try {
32
- return execCommand ( "git describe --tags --abbrev=0" ) ?. split ( "\n" ) . at ( - 1 ) ;
32
+ return execCommand ( "git describe --tags --abbrev=0" , cwd )
33
+ ?. split ( "\n" )
34
+ . at ( - 1 ) ;
33
35
} catch {
34
36
// Ignore
35
37
}
36
38
}
37
39
38
- export function getCurrentGitBranch ( ) {
39
- return execCommand ( "git rev-parse --abbrev-ref HEAD" ) ;
40
+ export function getCurrentGitBranch ( cwd ?: string ) {
41
+ return execCommand ( "git rev-parse --abbrev-ref HEAD" , cwd ) ;
40
42
}
41
43
42
- export function getCurrentGitTag ( ) {
43
- return execCommand ( "git tag --points-at HEAD" ) ;
44
+ export function getCurrentGitTag ( cwd ?: string ) {
45
+ return execCommand ( "git tag --points-at HEAD" , cwd ) ;
44
46
}
45
47
46
- export function getCurrentGitRef ( ) {
47
- return getCurrentGitTag ( ) || getCurrentGitBranch ( ) ;
48
+ export function getCurrentGitRef ( cwd ?: string ) {
49
+ return getCurrentGitTag ( cwd ) || getCurrentGitBranch ( cwd ) ;
48
50
}
49
51
50
52
export function getGitRemoteURL ( cwd : string , remote = "origin" ) {
51
- return execCommand ( `git --work-tree="${ cwd } " remote get-url "${ remote } "` ) ;
53
+ return execCommand (
54
+ `git --work-tree="${ cwd } " remote get-url "${ remote } "` ,
55
+ cwd
56
+ ) ;
52
57
}
53
58
54
- export async function getCurrentGitStatus ( ) {
55
- return execCommand ( "git status --porcelain" ) ;
59
+ export async function getCurrentGitStatus ( cwd ?: string ) {
60
+ return execCommand ( "git status --porcelain" , cwd ) ;
56
61
}
57
62
58
63
export async function getGitDiff (
59
64
from : string | undefined ,
60
- to = "HEAD"
65
+ to = "HEAD" ,
66
+ cwd ?: string
61
67
) : Promise < RawGitCommit [ ] > {
62
68
// https://git-scm.com/docs/pretty-formats
63
69
const r = execCommand (
64
- `git --no-pager log "${ from ? `${ from } ...` : "" } ${ to } " --pretty="----%n%s|%h|%an|%ae%n%b" --name-status`
70
+ `git --no-pager log "${ from ? `${ from } ...` : "" } ${ to } " --pretty="----%n%s|%h|%an|%ae%n%b" --name-status` ,
71
+ cwd
65
72
) ;
66
73
return r
67
74
. split ( "----\n" )
0 commit comments