Skip to content

Commit 847aa92

Browse files
authored
fix: skip creating a git repo when inside existing repo (#920)
* test: skip creating a git repo when inside existing repo * fix: skip creating git repo inside existing repo * test: use proper paths for project files * test: use absolute paths when checking existence to avoid quantum tangling multiple dimensions and causing the universe to stop existing
1 parent e6d411d commit 847aa92

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

__tests__/index-test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,29 @@ describe('yes', () => {
141141
expect(fileExists(projectName, '.gitignore')).toBeTruthy();
142142
expect(fileExists(projectName, 'node_modules')).not.toBeTruthy();
143143
});
144+
it('does not create a new git repository inside an existing repository', async () => {
145+
const workspaceName = 'yes-skip-git-in-repo';
146+
const workspaceRoot = getRoot(workspaceName);
147+
148+
// Create the workspace root, and basic monorepo structure
149+
await fs.mkdirp(workspaceRoot);
150+
await execa('git', ['init'], { cwd: workspaceRoot });
151+
152+
// Create the app within a basic monorepo structure
153+
const projectRoot = path.join(workspaceRoot, 'apps', workspaceName);
154+
await fs.mkdirp(projectRoot);
155+
156+
const results = await execa('node', [cli, '--yes'], { cwd: projectRoot });
157+
expect(results.exitCode).toBe(0);
158+
159+
expect(existsSync(path.join(workspaceRoot, '.git'))).toBe(true);
160+
expect(existsSync(path.join(projectRoot, '.git'))).not.toBe(true);
161+
162+
expect(existsSync(path.join(projectRoot, 'package.json'))).toBe(true);
163+
expect(existsSync(path.join(projectRoot, 'App.js'))).toBe(true);
164+
expect(existsSync(path.join(projectRoot, '.gitignore'))).toBe(true);
165+
expect(existsSync(path.join(projectRoot, 'node_modules'))).toBe(true);
166+
});
144167
});
145168

146169
describe('templates', () => {

src/Template.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export async function initGitRepoAsync(
110110
try {
111111
await spawnAsync('git', ['rev-parse', '--is-inside-work-tree'], { stdio: 'ignore', cwd: root });
112112
!flags.silent && Logger.gray('New project is already inside of a Git repo, skipping git init.');
113+
return false;
113114
} catch (e) {
114115
if (e.errno === 'ENOENT') {
115116
!flags.silent && Logger.gray('Unable to initialize Git repo. `git` not in PATH.');

0 commit comments

Comments
 (0)