Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(git): diagnostic flag to log action files untracked by Git #6484

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}