From e554cd1eb5bef12315329cdf6101bc13bd95a67a Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev <10628074+vvagaytsev@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:25:13 +0200 Subject: [PATCH 1/2] chore(git): log filenames of Git-untracked files on debug level --- core/src/vcs/git-sub-tree.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/src/vcs/git-sub-tree.ts b/core/src/vcs/git-sub-tree.ts index 265b89fadf..83e55ef414 100644 --- a/core/src/vcs/git-sub-tree.ts +++ b/core/src/vcs/git-sub-tree.ts @@ -28,6 +28,7 @@ import type { } from "./vcs.js" import { styles } from "../logger/styles.js" import type { Log } from "../logger/log-entry.js" +import dedent from "dedent" const { lstat, pathExists, readlink, realpath, stat } = fsExtra @@ -251,6 +252,8 @@ export class GitSubTreeHandler extends AbstractGitHandler { }) } + const untrackedHashedFilesCollector: string[] = [] + // This function is called for each line output from the ls-files commands that we run const handleEntry = async ( entry: GitEntry | undefined, @@ -296,6 +299,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats: undefined, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } @@ -324,6 +328,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } catch (err) { if (isErrnoException(err) && err.code === "ENOENT") { @@ -338,6 +343,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } } else { @@ -346,6 +352,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } } catch (err) { @@ -411,6 +418,13 @@ export class GitSubTreeHandler extends AbstractGitHandler { `Found ${scannedFiles.length} files in ${pathDescription} ${path} ${renderDuration(gitLog.getDuration())}` ) + gitLog.debug( + dedent` + Found and hashed ${untrackedHashedFilesCollector.length} files that are not tracked by Git: + ${untrackedHashedFilesCollector.join("\n")} + ` + ) + // We have done the processing of this level of files // So now we just have to wait for all the recursive submodules to resolve as well // before we can return @@ -491,11 +505,13 @@ async function ensureHash({ stats, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }: { file: VcsFile stats: fsExtra.Stats | undefined modifiedFiles: Set hashUntrackedFiles: boolean + untrackedHashedFilesCollector: string[] }): Promise { // If the file has not been modified, then it's either committed or untracked. if (!modifiedFiles.has(file.path)) { @@ -522,6 +538,7 @@ async function ensureHash({ if (hash !== "") { file.hash = hash } + untrackedHashedFilesCollector.push(file.path) return file } From 5dd19b012ced0350bad950c83896ae75726c0b18 Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev <10628074+vvagaytsev@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:29:18 +0200 Subject: [PATCH 2/2] chore(git): control flag for untracked file logging --- core/src/constants.ts | 1 + core/src/vcs/git-sub-tree.ts | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/core/src/constants.ts b/core/src/constants.ts index 597ead2aa2..13786f91bb 100644 --- a/core/src/constants.ts +++ b/core/src/constants.ts @@ -83,6 +83,7 @@ export const gardenEnv = { .required(false) .default(defaultGitScanMode) .asEnum(gitScanModes), + GARDEN_GIT_LOG_UNTRACKED_FILES: env.get("GARDEN_GIT_LOG_UNTRACKED_FILES").required(false).default("false").asBool(), GARDEN_LEGACY_BUILD_STAGE: env.get("GARDEN_LEGACY_BUILD_STAGE").required(false).asBool(), GARDEN_LOG_LEVEL: env.get("GARDEN_LOG_LEVEL").required(false).asString(), GARDEN_LOGGER_TYPE: env.get("GARDEN_LOGGER_TYPE").required(false).asString(), diff --git a/core/src/vcs/git-sub-tree.ts b/core/src/vcs/git-sub-tree.ts index 83e55ef414..5d73dae21e 100644 --- a/core/src/vcs/git-sub-tree.ts +++ b/core/src/vcs/git-sub-tree.ts @@ -29,6 +29,7 @@ import type { import { styles } from "../logger/styles.js" import type { Log } from "../logger/log-entry.js" import dedent from "dedent" +import { gardenEnv } from "../constants.js" const { lstat, pathExists, readlink, realpath, stat } = fsExtra @@ -418,12 +419,14 @@ export class GitSubTreeHandler extends AbstractGitHandler { `Found ${scannedFiles.length} files in ${pathDescription} ${path} ${renderDuration(gitLog.getDuration())}` ) - gitLog.debug( - dedent` - Found and hashed ${untrackedHashedFilesCollector.length} files that are not tracked by Git: - ${untrackedHashedFilesCollector.join("\n")} - ` - ) + if (gardenEnv.GARDEN_GIT_LOG_UNTRACKED_FILES) { + gitLog.debug( + dedent` + Found and hashed ${untrackedHashedFilesCollector.length} files that are not tracked by Git: + ${untrackedHashedFilesCollector.join("\n")} + ` + ) + } // We have done the processing of this level of files // So now we just have to wait for all the recursive submodules to resolve as well @@ -538,7 +541,9 @@ async function ensureHash({ if (hash !== "") { file.hash = hash } - untrackedHashedFilesCollector.push(file.path) + if (gardenEnv.GARDEN_GIT_LOG_UNTRACKED_FILES) { + untrackedHashedFilesCollector.push(file.path) + } return file }