create-app: avoid conflicting tmp dir for reading git config

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2022-12-29 11:55:38 +01:00
parent e405fbf88a
commit 724b55689b
3 changed files with 10 additions and 7 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/create-app': patch
---
Avoid potential temporary directory conflict.
+4 -4
View File
@@ -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),
);
});
+1 -3
View File
@@ -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,