Skip to content

Commit 55c4dcb

Browse files
committed
cherry-pick init commits
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parent 40a57fb commit 55c4dcb

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

src/utils/cherryPick.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { exec as cpExec } from "child_process";
2+
import { promisify } from "util";
3+
4+
const asyncExec = promisify(cpExec);
5+
6+
export const exec = (
7+
command: string,
8+
cwd: string
9+
): Promise<{ stdout: string; stderr: string }> | never => {
10+
return asyncExec(command, { cwd });
11+
};
12+
13+
export function gitPCherryPick(cwd: string) {
14+
return async function cherryPick(commits: string[]): Promise<void> {
15+
for (const commit of commits) {
16+
try {
17+
const { stdout } = await exec(
18+
`git cherry-pick -X theirs ${commit}`,
19+
cwd
20+
);
21+
if (!stdout) {
22+
console.warn(`No cherry-pick output for ${commit}`);
23+
}
24+
} catch (e) {
25+
console.warn(`Cherry-pick failed for ${commit}`);
26+
}
27+
}
28+
};
29+
}

src/validate.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as fs from "fs-extra";
33
import * as yamlParser from "js-yaml";
44
import { getArg } from "./utils/args";
55
import gitP, { SimpleGit } from "simple-git/promise";
6+
import { gitPCherryPick } from "./utils/cherryPick";
67
import { getCommits, CommitLogObject } from "./utils/commits";
78

89
async function validate(args: string[]) {
@@ -46,10 +47,18 @@ async function validate(args: string[]) {
4647
await fs.emptyDir(tmpDir);
4748
}
4849
const tempGit: SimpleGit = gitP(tmpDir);
50+
51+
console.log(Object.keys(gitP));
52+
4953
await tempGit.init();
54+
await tempGit.addRemote("origin", skeleton.config.repo.uri);
55+
await tempGit.fetch("origin", skeleton.config.repo.branch);
56+
// no js cherry pick implementation
57+
const cherryPick = gitPCherryPick(tmpDir);
5058

5159
// VALIDATE TUTORIAL TESTS
5260
if (commits.INIT) {
61+
cherryPick(commits.INIT);
5362
}
5463

5564
// run test runner setup command(s)
@@ -71,7 +80,7 @@ async function validate(args: string[]) {
7180
console.error(e.message);
7281
} finally {
7382
// cleanup
74-
await fs.emptyDir(tmpDir);
83+
// await fs.emptyDir(tmpDir);
7584
}
7685
}
7786

0 commit comments

Comments
 (0)