Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 29 additions & 4 deletions setup/setup.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,24 @@ async function main() {
}

// Set git identity from GitHub if not configured
try { execSync('git config user.name', { stdio: 'ignore' }); } catch {
try {
execSync('git config user.name', { stdio: 'ignore' });
execSync('git config user.email', { stdio: 'ignore' });
} catch {
try {
const ghUser = JSON.parse(execSync('gh api user', { encoding: 'utf-8', env: ghEnv() }));
execSync(`git config --global user.name "${ghUser.name || ghUser.login}"`, { stdio: 'ignore' });
execSync(`git config --global user.email "${ghUser.login}@users.noreply.github.com"`, { stdio: 'ignore' });
clack.log.success('Git identity set from GitHub');
} catch {}
} catch {
clack.log.error(
'Could not set git identity automatically. Git requires your name and email to make commits.\n' +
'Please run the following commands and re-run setup:\n\n' +
' git config --global user.name "Your Name"\n' +
' git config --global user.email "you@example.com"'
);
process.exit(1);
}
}

if (prereqs.git.remoteInfo) {
Expand All @@ -170,8 +181,22 @@ async function main() {
} catch {
const commitSpinner = clack.spinner();
commitSpinner.start('Creating initial commit...');
execSync('git commit -m "initial commit [skip ci]"', { stdio: 'ignore' });
commitSpinner.stop('Created initial commit');
try {
execSync('git commit -m "initial commit [skip ci]"', { stdio: 'ignore' });
commitSpinner.stop('Created initial commit');
} catch (err) {
commitSpinner.stop('Failed to create initial commit');
const errMsg = err.toString();
if (errMsg.includes('Author identity unknown') || errMsg.includes('unable to auto-detect email')) {
clack.log.error(
'Git identity not configured. Run:\n' +
' git config --global user.email "you@example.com"\n' +
' git config --global user.name "Your Name"'
);
process.exit(1);
}
throw err;
}
}

// Ask for project name
Expand Down