generated from actions/typescript-action
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgit.ts
44 lines (40 loc) · 1.09 KB
/
git.ts
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
import {exec, getExecOutput} from '@actions/exec'
async function execForStdOut(
commandLine: string,
args?: string[],
cwd?: string
): Promise<string> {
const output = await getExecOutput(commandLine, args, {cwd})
return output.stdout
}
async function getMergeBase(
shaA: string,
shaB: string,
cwd?: string
): Promise<string> {
return execForStdOut('git', ['merge-base', shaA, shaB], cwd)
}
export async function getChangedFiles(
baseSha: string,
headSha: string,
cwd?: string
): Promise<string[]> {
const mergeBase = (await getMergeBase(baseSha, headSha, cwd)).trim()
return (
await execForStdOut(
'git',
['diff', '--name-only', `${mergeBase}..${headSha}`, '--'],
cwd
)
)
.split('\n')
.map(x => x.trim())
.filter(x => x.length > 0)
}
export async function revParse(rev: string, cwd?: string): Promise<string> {
const output = await execForStdOut('git', ['rev-parse', rev], cwd)
return output.trim()
}
export async function unshallowHistories(): Promise<number> {
return exec('git', ['fetch', '--prune', '--unshallow', '--filter=blob:none'])
}