From 7f10c6b97b67913d3f7e430259162e3e3faa326c Mon Sep 17 00:00:00 2001 From: Shiv Bhonde Date: Wed, 4 Dec 2024 14:57:59 +0530 Subject: [PATCH] update diffFilter D to get all the deleted throughout history --- src/dev/create-extension.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/dev/create-extension.ts b/src/dev/create-extension.ts index 03d05a371..e68ad4c57 100644 --- a/src/dev/create-extension.ts +++ b/src/dev/create-extension.ts @@ -44,13 +44,33 @@ const getDiffFilesFromFirstCommit = async ({ projectPath: string; diffFilter?: "d" | "D"; }): Promise => { + if (diffFilter === "D") { + // all files that have ever existed in the repo's history + const { stdout: allFiles } = await execa( + "git", + ["log", "--all", "--diff-filter=ACDMRT", "--name-only", "--format="], + { cwd: projectPath }, + ); + + const { stdout: currentFiles } = await execa("git", ["ls-files"], { + cwd: projectPath, + }); + + const allFilesSet = new Set(allFiles.split("\n").filter(Boolean)); + const currentFilesSet = new Set(currentFiles.split("\n").filter(Boolean)); + + return Array.from(allFilesSet).filter(file => !currentFilesSet.has(file)); + } + const { stdout: firstCommit } = await execa("git", ["rev-list", "--max-parents=0", "HEAD"], { cwd: projectPath, }); + const diffFilterArg = diffFilter ? `--diff-filter=${diffFilter}` : ""; const { stdout } = await execa("git", ["diff", diffFilterArg, "--name-only", `${firstCommit.trim()}..HEAD`], { cwd: projectPath, }); + return stdout.split("\n").filter(Boolean); };