Skip to content

Commit b4767ae

Browse files
alan-agius4clydin
authored andcommitted
test: change git utils to async/await
Minor cleanups in git utils code
1 parent 5321b3d commit b4767ae

File tree

1 file changed

+25
-29
lines changed
  • tests/legacy-cli/e2e/utils

1 file changed

+25
-29
lines changed

tests/legacy-cli/e2e/utils/git.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,33 @@
11
import { git, silentGit } from './process';
22

3-
export function gitClean() {
3+
export async function gitClean(): Promise<void> {
44
console.log(' Cleaning git...');
5-
return silentGit('clean', '-df')
6-
.then(() => silentGit('reset', '--hard'))
7-
.then(() => {
8-
// Checkout missing files
9-
return silentGit('status', '--porcelain')
10-
.then(({ stdout }) =>
11-
stdout
12-
.split(/[\n\r]+/g)
13-
.filter((line) => line.match(/^ D/))
14-
.map((line) => line.replace(/^\s*\S+\s+/, '')),
15-
)
16-
.then((files) => silentGit('checkout', ...files));
17-
})
18-
.then(() => expectGitToBeClean());
5+
6+
await silentGit('clean', '-df');
7+
await silentGit('reset', '--hard');
8+
9+
// Checkout missing files
10+
const { stdout } = await silentGit('status', '--porcelain');
11+
const files = stdout
12+
.split(/[\n\r]+/g)
13+
.filter((line) => line.match(/^ D/))
14+
.map((line) => line.replace(/^\s*\S+\s+/, ''));
15+
16+
await silentGit('checkout', ...files);
17+
await expectGitToBeClean();
1918
}
2019

21-
export function expectGitToBeClean() {
22-
return silentGit('status', '--porcelain').then(({ stdout }) => {
23-
if (stdout != '') {
24-
throw new Error('Git repo is not clean...\n' + stdout);
25-
}
26-
});
20+
export async function expectGitToBeClean(): Promise<void> {
21+
const { stdout } = await silentGit('status', '--porcelain');
22+
if (stdout != '') {
23+
throw new Error('Git repo is not clean...\n' + stdout);
24+
}
2725
}
2826

29-
export function gitCommit(message: string) {
30-
return git('add', '-A')
31-
.then(() => silentGit('status', '--porcelain'))
32-
.then(({ stdout }) => {
33-
if (stdout != '') {
34-
return git('commit', '-am', message);
35-
}
36-
});
27+
export async function gitCommit(message: string): Promise<void> {
28+
await git('add', '-A');
29+
const { stdout } = await silentGit('status', '--porcelain');
30+
if (stdout != '') {
31+
await git('commit', '-am', message);
32+
}
3733
}

0 commit comments

Comments
 (0)