Skip to content

Commit

Permalink
fix: don't initialize git repo if we're already under a git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Sep 29, 2023
1 parent bf94f69 commit 2c1c4e7
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions packages/create-react-native-library/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -775,16 +775,27 @@ async function create(argv: yargs.Arguments<any>) {
}

if (!local) {
let isInGitRepo = false;

try {
await spawn('git', ['init'], { cwd: folder });
await spawn('git', ['branch', '-M', 'main'], { cwd: folder });
await spawn('git', ['add', '.'], { cwd: folder });
await spawn('git', ['commit', '-m', 'chore: initial commit'], {
cwd: folder,
});
isInGitRepo =
(await spawn('git', ['rev-parse', '--is-inside-work-tree'])) === 'true';
} catch (e) {
// Ignore error
}

if (!isInGitRepo) {
try {
await spawn('git', ['init'], { cwd: folder });
await spawn('git', ['branch', '-M', 'main'], { cwd: folder });
await spawn('git', ['add', '.'], { cwd: folder });
await spawn('git', ['commit', '-m', 'chore: initial commit'], {
cwd: folder,
});
} catch (e) {
// Ignore error
}
}
}

spinner.succeed(
Expand Down

0 comments on commit 2c1c4e7

Please sign in to comment.