Skip to content

Commit

Permalink
chore(git): diagnostic flag to log action files untracked by Git (#6484)
Browse files Browse the repository at this point in the history
* chore(git): log filenames of Git-untracked files on debug level

* chore(git): control flag for untracked file logging
  • Loading branch information
vvagaytsev authored Sep 25, 2024
1 parent d97e036 commit 6b8b0d4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
22 changes: 22 additions & 0 deletions core/src/vcs/git-sub-tree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -296,6 +300,7 @@ export class GitSubTreeHandler extends AbstractGitHandler {
stats: undefined,
modifiedFiles,
hashUntrackedFiles,
untrackedHashedFilesCollector,
})
}

Expand Down Expand Up @@ -324,6 +329,7 @@ export class GitSubTreeHandler extends AbstractGitHandler {
stats,
modifiedFiles,
hashUntrackedFiles,
untrackedHashedFilesCollector,
})
} catch (err) {
if (isErrnoException(err) && err.code === "ENOENT") {
Expand All @@ -338,6 +344,7 @@ export class GitSubTreeHandler extends AbstractGitHandler {
stats,
modifiedFiles,
hashUntrackedFiles,
untrackedHashedFilesCollector,
})
}
} else {
Expand All @@ -346,6 +353,7 @@ export class GitSubTreeHandler extends AbstractGitHandler {
stats,
modifiedFiles,
hashUntrackedFiles,
untrackedHashedFilesCollector,
})
}
} catch (err) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -491,11 +508,13 @@ async function ensureHash({
stats,
modifiedFiles,
hashUntrackedFiles,
untrackedHashedFilesCollector,
}: {
file: VcsFile
stats: fsExtra.Stats | undefined
modifiedFiles: Set<string>
hashUntrackedFiles: boolean
untrackedHashedFilesCollector: string[]
}): Promise<VcsFile> {
// If the file has not been modified, then it's either committed or untracked.
if (!modifiedFiles.has(file.path)) {
Expand All @@ -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
}

0 comments on commit 6b8b0d4

Please sign in to comment.