From 6b8b0d438b263a7712ecc7dee3a26c7675633c98 Mon Sep 17 00:00:00 2001 From: Vladimir Vagaytsev <10628074+vvagaytsev@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:29:57 +0200 Subject: [PATCH] chore(git): diagnostic flag to log action files untracked by Git (#6484) * chore(git): log filenames of Git-untracked files on debug level * chore(git): control flag for untracked file logging --- core/src/constants.ts | 1 + core/src/vcs/git-sub-tree.ts | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+) 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 265b89fadf..5d73dae21e 100644 --- a/core/src/vcs/git-sub-tree.ts +++ b/core/src/vcs/git-sub-tree.ts @@ -28,6 +28,8 @@ import type { } from "./vcs.js" 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 @@ -251,6 +253,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 +300,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats: undefined, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } @@ -324,6 +329,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } catch (err) { if (isErrnoException(err) && err.code === "ENOENT") { @@ -338,6 +344,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } } else { @@ -346,6 +353,7 @@ export class GitSubTreeHandler extends AbstractGitHandler { stats, modifiedFiles, hashUntrackedFiles, + untrackedHashedFilesCollector, }) } } catch (err) { @@ -411,6 +419,15 @@ export class GitSubTreeHandler extends AbstractGitHandler { `Found ${scannedFiles.length} files in ${pathDescription} ${path} ${renderDuration(gitLog.getDuration())}` ) + 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 // before we can return @@ -491,11 +508,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 +541,9 @@ async function ensureHash({ if (hash !== "") { file.hash = hash } + if (gardenEnv.GARDEN_GIT_LOG_UNTRACKED_FILES) { + untrackedHashedFilesCollector.push(file.path) + } return file }