create-app: avoid conflicting tmp dir for reading git config
Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/create-app': patch
|
||||
---
|
||||
|
||||
Avoid potential temporary directory conflict.
|
||||
@@ -284,7 +284,7 @@ describe('tasks', () => {
|
||||
});
|
||||
|
||||
describe('readGitConfig', () => {
|
||||
const tmpDir = resolvePath(os.tmpdir(), 'git-temp-dir');
|
||||
const tmpDirPrefix = resolvePath(os.tmpdir(), 'git-temp-dir-');
|
||||
|
||||
it('should return git config if git package is installed and git credentials are set', async () => {
|
||||
mockExec.mockImplementation((_command, _options, callback) => {
|
||||
@@ -299,17 +299,17 @@ describe('tasks', () => {
|
||||
expect(mockExec).toHaveBeenCalledTimes(3);
|
||||
expect(mockExec).toHaveBeenCalledWith(
|
||||
'git init',
|
||||
{ cwd: tmpDir },
|
||||
{ cwd: expect.stringContaining(tmpDirPrefix) },
|
||||
expect.any(Function),
|
||||
);
|
||||
expect(mockExec).toHaveBeenCalledWith(
|
||||
'git commit --allow-empty -m "Initial commit"',
|
||||
{ cwd: tmpDir },
|
||||
{ cwd: expect.stringContaining(tmpDirPrefix) },
|
||||
expect.any(Function),
|
||||
);
|
||||
expect(mockExec).toHaveBeenCalledWith(
|
||||
'git branch --format="%(refname:short)"',
|
||||
{ cwd: tmpDir },
|
||||
{ cwd: expect.stringContaining(tmpDirPrefix) },
|
||||
expect.any(Function),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -248,11 +248,9 @@ export async function moveAppTask(
|
||||
* @throws if `exec` fails
|
||||
*/
|
||||
export async function readGitConfig(): Promise<GitConfig | undefined> {
|
||||
const tempDir = resolvePath(os.tmpdir(), 'git-temp-dir');
|
||||
const tempDir = await fs.mkdtemp(resolvePath(os.tmpdir(), 'git-temp-dir-'));
|
||||
|
||||
try {
|
||||
await fs.mkdir(tempDir);
|
||||
|
||||
await exec('git init', { cwd: tempDir });
|
||||
await exec('git commit --allow-empty -m "Initial commit"', {
|
||||
cwd: tempDir,
|
||||
|
||||
Reference in New Issue
Block a user