Skip to content

Commit bb5054a

Browse files
committed
Remove from source too
1 parent fc2222a commit bb5054a

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

src/prepare-repository.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
unique,
66
commitChanges,
77
resetToCommitHash,
8+
removeFilesCannotAdd,
89
} from "./utilities.ts";
910
import fs from "node:fs/promises";
1011
import { cloneRepository, type Repository } from "./repositories.ts";
@@ -42,7 +43,15 @@ export async function prepareRepository(
4243
await preparePrettierIgnoreFile(directory, repository);
4344
await spawn("git", ["init"], { cwd: directory });
4445

45-
const commitHash = await commitChanges(directory, "Initialize", true);
46+
// There are junk files in `microsoft/vscode` can't commit
47+
const files = await removeFilesCannotAdd(directory);
48+
await Promise.all(
49+
files.map((file) =>
50+
fs.rm(path.join(repository.directory, file), { recursive: true }),
51+
),
52+
);
53+
54+
const commitHash = await commitChanges(directory, "Initialize");
4655

4756
return {
4857
async reset() {

src/utilities.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,9 @@ export async function readFile(file: string) {
4242

4343
export const unique = <T>(array: T[]): T[] => [...new Set(array)];
4444

45-
async function gitAddFiles(cwd: string) {
45+
export async function removeFilesCannotAdd(cwd: string, files: string[] = []) {
4646
try {
4747
await spawn("git", ["add", "."], { cwd });
48-
return;
4948
} catch (error) {
5049
if (error instanceof SubprocessError) {
5150
const { stderr } = error;
@@ -55,30 +54,25 @@ async function gitAddFiles(cwd: string) {
5554
const filename = match?.groups?.filename;
5655
if (filename) {
5756
console.log(`File '${filename}' can't be added, ignored.`);
57+
files.push(filename);
5858
await fs.rm(path.join(cwd, filename), { force: true });
59-
return gitAddFiles(cwd);
59+
return removeFilesCannotAdd(cwd, files);
6060
}
6161
}
6262

6363
throw error;
6464
}
65+
66+
return files;
6567
}
6668

67-
export const commitChanges = async (
68-
directory: string,
69-
message: string,
70-
ignoreFilesCannotAdded?: boolean,
71-
) => {
69+
export const commitChanges = async (directory: string, message: string) => {
7270
await fs.rm(path.join(directory, ".gitattributes"), { force: true });
7371
await spawn("git", ["config", "set", "core.autocrlf", "false"], {
7472
cwd: directory,
7573
});
7674

77-
if (ignoreFilesCannotAdded) {
78-
await gitAddFiles(directory);
79-
} else {
80-
await spawn("git", ["add", "."], { cwd: directory });
81-
}
75+
await spawn("git", ["add", "."], { cwd: directory });
8276

8377
await spawn(
8478
"git",

0 commit comments

Comments
 (0)