feat(CLI): don't attempt to commit if user.name/email is not set
This commit is contained in:
@@ -26,7 +26,12 @@ export interface Tasks {
|
||||
readonly gitEmail: string;
|
||||
readonly gitName: string;
|
||||
}>;
|
||||
readonly initialCommit: (hash: string, projectDir: string) => Promise<void>;
|
||||
readonly initialCommit: (
|
||||
hash: string,
|
||||
projectDir: string,
|
||||
name: string,
|
||||
email: string
|
||||
) => Promise<boolean>;
|
||||
readonly install: (
|
||||
shouldInstall: boolean,
|
||||
runner: Runner,
|
||||
@@ -104,7 +109,9 @@ export const getUserInfo = (spawner: ExecaStatic) => async () => {
|
||||
|
||||
export const initialCommit = (spawner: ExecaStatic) => async (
|
||||
hash: string,
|
||||
projectDir: string
|
||||
projectDir: string,
|
||||
name: string,
|
||||
email: string
|
||||
) => {
|
||||
const opts: Options = {
|
||||
cwd: projectDir,
|
||||
@@ -113,6 +120,9 @@ export const initialCommit = (spawner: ExecaStatic) => async (
|
||||
};
|
||||
await spawner('git', ['init'], opts);
|
||||
await spawner('git', ['add', '-A'], opts);
|
||||
if (name === Placeholders.name || email === Placeholders.email) {
|
||||
return false;
|
||||
}
|
||||
await spawner(
|
||||
'git',
|
||||
[
|
||||
@@ -122,6 +132,7 @@ export const initialCommit = (spawner: ExecaStatic) => async (
|
||||
],
|
||||
opts
|
||||
);
|
||||
return true;
|
||||
};
|
||||
|
||||
export const install = (spawner: ExecaStatic) => async (
|
||||
|
||||
@@ -120,10 +120,29 @@ test('getUserInfo: suppresses errors and returns empty strings', async t => {
|
||||
});
|
||||
|
||||
test('initialCommit: throws generated errors', async t => {
|
||||
const error = await t.throws(initialCommit(mockErr(1))('deadbeef', 'fail'));
|
||||
const error = await t.throws(
|
||||
initialCommit(mockErr(1))('deadbeef', 'fail', 'name', 'bitjson@github.com')
|
||||
);
|
||||
t.is(error.code, 1);
|
||||
});
|
||||
|
||||
test("initialCommit: don't attempt to commit if user.name/email is not set", async t => {
|
||||
// tslint:disable-next-line:no-let
|
||||
let calls = 0;
|
||||
const errorIf3 = ((() => {
|
||||
calls++;
|
||||
calls === 1 ? t.pass() : calls === 2 ? t.pass() : t.fail();
|
||||
}) as any) as ExecaStatic;
|
||||
t.false(
|
||||
await initialCommit(errorIf3)(
|
||||
'deadbeef',
|
||||
'fail',
|
||||
Placeholders.name,
|
||||
Placeholders.email
|
||||
)
|
||||
);
|
||||
});
|
||||
|
||||
test('install: uses the correct runner', async t => {
|
||||
const mock = (((runner: Runner) => {
|
||||
runner === Runner.Yarn ? t.pass() : t.fail();
|
||||
|
||||
@@ -144,8 +144,11 @@ export async function typescriptStarter(
|
||||
await tasks.install(install, runner, projectPath);
|
||||
|
||||
const spinner7 = ora(`Initializing git repository`).start();
|
||||
await tasks.initialCommit(commitHash, projectPath);
|
||||
spinner7.succeed();
|
||||
(await tasks.initialCommit(commitHash, projectPath, gitName, gitEmail))
|
||||
? spinner7.succeed()
|
||||
: spinner7.fail(
|
||||
"Git config user.name and user.email are not configured. You'll need to `git commit` yourself."
|
||||
);
|
||||
|
||||
console.log(`\n${chalk.blue.bold(`Created ${name} 🎉`)}\n`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user