-
-
Notifications
You must be signed in to change notification settings - Fork 535
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use git to check that you're in a Git repository (#689)
* test(core): added init-git tests to cover known cases * test(core): add failing test for init-git catches case where init-git is run within a subdirectory of a known repository and forge should not create a nested .git directory * fix(core): do not initialize when in an existing git repository
- Loading branch information
1 parent
d15a8cc
commit 72b8eea
Showing
2 changed files
with
83 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { execSync } from 'child_process'; | ||
import fs from 'fs-extra'; | ||
import os from 'os'; | ||
import path from 'path'; | ||
|
||
import { expect } from 'chai'; | ||
|
||
import initGit from '../../src/api/init-scripts/init-git'; | ||
|
||
let dir: string; | ||
let dirID = Date.now(); | ||
|
||
const ensureTestDirIsNonexistent = async () => { | ||
dir = path.resolve(os.tmpdir(), `electron-forge-git-test-${dirID}`); | ||
dirID += 1; | ||
await fs.remove(dir); | ||
}; | ||
|
||
describe('init-git', () => { | ||
beforeEach(async () => { | ||
await ensureTestDirIsNonexistent(); | ||
await fs.mkdir(dir); | ||
}); | ||
|
||
it('creates Git repository when run inside non-Git directory', async () => { | ||
await initGit(dir); | ||
const gitDir = path.join(dir, '.git'); | ||
expect(await fs.pathExists(gitDir), 'the .git directory inside the folder').to.equal(true); | ||
}); | ||
|
||
it('skips when run at root of Git repository', async () => { | ||
await execSync('git init', { cwd: dir }); | ||
|
||
const gitDir = path.join(dir, '.git'); | ||
const config = path.join(gitDir, 'config'); | ||
const statBefore = await fs.lstat(config); | ||
const before = statBefore.mtimeMs; | ||
|
||
await initGit(dir); | ||
|
||
const statAfter = await fs.lstat(config); | ||
const after = statAfter.mtimeMs; | ||
|
||
expect(after, 'the config file in the repository').to.equal(before); | ||
}); | ||
|
||
it('skips when run in subdirectory of Git repository', async () => { | ||
await execSync('git init', { cwd: dir }); | ||
|
||
const gitDir = path.join(dir, '.git'); | ||
const config = path.join(gitDir, 'config'); | ||
const statBefore = await fs.lstat(config); | ||
const before = statBefore.mtimeMs; | ||
|
||
const subdir = path.join(dir, 'some', 'other', 'folder'); | ||
const innerGitDir = path.join(subdir, '.git'); | ||
|
||
await fs.mkdirp(subdir); | ||
|
||
await initGit(subdir); | ||
|
||
const statAfter = await fs.lstat(config); | ||
const after = statAfter.mtimeMs; | ||
|
||
expect(after, 'the config file in the repository').to.equal(before); | ||
expect(await fs.pathExists(innerGitDir), 'a nested .git directory inside the repository').to.equal(false); | ||
}); | ||
}); |