Skip to content

Commit ab42855

Browse files
committed
fix: allow project creation in directories with only .git folder
- Enable creating projects in freshly cloned empty repositories - Resolves issue where users couldn't create projects in cloned repos
1 parent 6445bc6 commit ab42855

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

  • packages/create-react-native-library/src

packages/create-react-native-library/src/input.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,23 @@ export async function createQuestions({
210210
return 'Cannot be empty';
211211
}
212212

213-
if (fs.pathExistsSync(path.join(process.cwd(), input))) {
214-
return 'Directory already exists';
213+
const targetPath = path.join(process.cwd(), input);
214+
215+
if (fs.pathExistsSync(targetPath)) {
216+
const stat = fs.statSync(targetPath);
217+
218+
if (!stat.isDirectory()) {
219+
return 'Path exists and is not a directory';
220+
}
221+
222+
const files = fs.readdirSync(targetPath);
223+
224+
const isEmpty =
225+
files.length === 0 || (files.length === 1 && files[0] === '.git');
226+
227+
if (!isEmpty) {
228+
return 'Directory already exists';
229+
}
215230
}
216231

217232
return true;

0 commit comments

Comments
 (0)