Skip to content

Commit 2f40b39

Browse files
fix: build command
1 parent a648c90 commit 2f40b39

File tree

2 files changed

+33
-4
lines changed

2 files changed

+33
-4
lines changed

lib/utils/command.js

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,18 @@ const cloneForBranch = (pushDir, branch, context) => __awaiter(this, void 0, voi
3939
signale_1.default.info(`Cloning the branch %s from the remote repo`, branch);
4040
const url = misc_1.getGitUrl(context);
4141
yield execAsync(`git -C ${pushDir} clone --quiet --branch=${branch} --depth=1 ${url} .`, true, 'git clone', true);
42+
if (!fs_1.default.existsSync(path_1.default.resolve(pushDir, '.git'))) {
43+
yield gitInit(pushDir);
44+
yield gitCheckout(pushDir, branch);
45+
}
46+
});
47+
const gitInit = (pushDir) => __awaiter(this, void 0, void 0, function* () {
48+
signale_1.default.info('Initializing local git repo');
49+
yield execAsync(`git -C ${pushDir} init .`);
50+
});
51+
const gitCheckout = (pushDir, branch) => __awaiter(this, void 0, void 0, function* () {
52+
signale_1.default.info('Checking out orphan branch %s', branch);
53+
yield execAsync(`git -C ${pushDir} checkout --orphan "${branch}"`);
4254
});
4355
const config = (pushDir) => __awaiter(this, void 0, void 0, function* () {
4456
const name = misc_1.getCommitName();
@@ -56,7 +68,7 @@ const commit = (pushDir) => __awaiter(this, void 0, void 0, function* () {
5668
const push = (pushDir, branch, context) => __awaiter(this, void 0, void 0, function* () {
5769
signale_1.default.info('Pushing to %s@%s', misc_1.getRepository(context), branch);
5870
const url = misc_1.getGitUrl(context);
59-
yield execAsync(`git -C ${pushDir} push --quiet "${url}" "${branch}":"${branch}"`, false, 'git push');
71+
yield execAsync(`git -C ${pushDir} push --quiet "${url}" "${branch}":"${branch}"`, true, 'git push');
6072
});
6173
const cloneForBuild = (buildDir, context) => __awaiter(this, void 0, void 0, function* () {
6274
signale_1.default.info('Cloning the working commit from the remote repo for build');
@@ -93,7 +105,7 @@ const copyFiles = (buildDir, pushDir) => __awaiter(this, void 0, void 0, functio
93105
const execAsync = (command, quiet = false, altCommand = null, suppressError = false) => new Promise((resolve, reject) => {
94106
if ('string' === typeof altCommand)
95107
signale_1.default.info(`Run command: ${altCommand}`);
96-
if (!quiet)
108+
else if (!quiet)
97109
signale_1.default.info(`Run command: ${command}`);
98110
child_process_1.exec(command + (quiet ? ' > /dev/null 2>&1' : '') + (suppressError ? ' || :' : ''), (error, stdout) => {
99111
if (error) {

src/utils/command.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,23 @@ const cloneForBranch = async (pushDir: string, branch: string, context: Context)
3333

3434
const url = getGitUrl(context);
3535
await execAsync(`git -C ${pushDir} clone --quiet --branch=${branch} --depth=1 ${url} .`, true, 'git clone', true);
36+
if (!fs.existsSync(path.resolve(pushDir, '.git'))) {
37+
await gitInit(pushDir);
38+
await gitCheckout(pushDir, branch);
39+
}
40+
};
41+
42+
const gitInit = async (pushDir: string) => {
43+
signale.info('Initializing local git repo');
44+
45+
await execAsync(`git -C ${pushDir} init .`);
46+
47+
};
48+
49+
const gitCheckout = async (pushDir: string, branch: string) => {
50+
signale.info('Checking out orphan branch %s', branch);
51+
52+
await execAsync(`git -C ${pushDir} checkout --orphan "${branch}"`);
3653
};
3754

3855
const config = async (pushDir: string) => {
@@ -55,7 +72,7 @@ const push = async (pushDir: string, branch: string, context: Context) => {
5572
signale.info('Pushing to %s@%s', getRepository(context), branch);
5673

5774
const url = getGitUrl(context);
58-
await execAsync(`git -C ${pushDir} push --quiet "${url}" "${branch}":"${branch}"`, false, 'git push');
75+
await execAsync(`git -C ${pushDir} push --quiet "${url}" "${branch}":"${branch}"`, true, 'git push');
5976
};
6077

6178
const cloneForBuild = async (buildDir: string, context: Context) => {
@@ -98,7 +115,7 @@ const copyFiles = async (buildDir: string, pushDir: string) => {
98115

99116
const execAsync = (command: string, quiet: boolean = false, altCommand: string | null = null, suppressError: boolean = false) => new Promise<string>((resolve, reject) => {
100117
if ('string' === typeof altCommand) signale.info(`Run command: ${altCommand}`);
101-
if (!quiet) signale.info(`Run command: ${command}`);
118+
else if (!quiet) signale.info(`Run command: ${command}`);
102119
exec(command + (quiet ? ' > /dev/null 2>&1' : '') + (suppressError ? ' || :' : ''), (error, stdout) => {
103120
if (error) {
104121
if ('string' === typeof altCommand) reject(new Error(`command [${altCommand}] exited with code ${error.code}.`));

0 commit comments

Comments
 (0)