| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
Overlay analysis depends on `getFileOidsUnderPath`, which uses `git ls-files --format` option that requires Git 2.38.0+. This change adds a check for the git version before enabling overlay analysis. Co-authored-by: henrymercer <14129055+henrymercer@users.noreply.github.com>
- Add test for Windows-style git version format - Add comment clarifying regex extracts major.minor.patch - Replace dynamic import with static import for semver Co-authored-by: henrymercer <14129055+henrymercer@users.noreply.github.com>
There was a problem hiding this comment.
This PR adds Git version checking to ensure overlay analysis is only enabled when Git 2.38.0 or newer is available. Overlay analysis depends on the git ls-files --format option introduced in Git 2.38.0, and this change prevents runtime failures when an older Git version is installed.
Key changes:
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file| File | Description |
|---|---|
| src/git-utils.ts | Added version constants, parsing function, and comparison utilities for Git version checking |
| src/git-utils.test.ts | Added comprehensive test coverage for version parsing and comparison logic |
| src/config-utils.ts | Integrated Git version check into overlay database mode determination |
| src/config-utils.test.ts | Added test cases for overlay fallback scenarios with old/missing Git versions |
| lib/*.js | Generated JavaScript output from TypeScript compilation |
Sorry, something went wrong.
|
@copilot Please address the following feedback: Error handling improvements
Telemetry
|
Sorry, something went wrong.
…metry - Cache the git version to avoid recomputing on repeated calls - Refactor getGitVersion to getGitVersionOrThrow with detailed errors - Add getGitVersion that logs errors and handles caching - Add makeTelemetryDiagnostic helper to diagnostics.ts - Add logGitVersionTelemetry function to log git version telemetry - Call logGitVersionTelemetry in init-action.ts - Add resetCachedGitVersion for testing - Update tests to work with new function signatures and caching Co-authored-by: henrymercer <14129055+henrymercer@users.noreply.github.com>
Refactored bundle-download-telemetry and zstd-availability diagnostics in init-action.ts to use the new makeTelemetryDiagnostic helper function. Also added guard for empty languages array in logGitVersionTelemetry. Co-authored-by: henrymercer <14129055+henrymercer@users.noreply.github.com>
... Addressed in commits c3dc529 and 393c074: Error handling improvements:
Telemetry:
|
Sorry, something went wrong.
There was a problem hiding this comment.
I have given this an initial review. Two primary points:
Sorry, something went wrong.
| import type { Config } from "./config-utils"; | ||
| import { addDiagnostic, makeTelemetryDiagnostic } from "./diagnostics"; | ||
| import { Logger } from "./logging"; |
There was a problem hiding this comment.
I am not overly keen on having this in git-utils. I think it would make more sense to keep this file for the git-related utility functions and then perform the version check / logging / diagnostic stuff elsewhere.
Sorry, something went wrong.
There was a problem hiding this comment.
I've moved the logging/diagnostics elsewhere, so now it's just the ability to get the git version. I think that's not worth moving to a new file.
Sorry, something went wrong.
| * displayed on the status page or CLI summary table. | ||
| * | ||
| * @param id An identifier under which it makes sense to group this diagnostic message. | ||
| * @param name Display name for the ID. |
There was a problem hiding this comment.
| * @param name Display name for the ID. | |
| * @param name Display name for the diagnostic. |
Sorry, something went wrong.
| languages: [KnownLanguage.javascript], | ||
| codeqlVersion: CODEQL_OVERLAY_MINIMUM_VERSION, | ||
| gitRoot: "/some/git/root", | ||
| gitVersion: "2.40.0", // Default to a version that supports overlay analysis |
There was a problem hiding this comment.
Why is this not GIT_MINIMUM_VERSION_FOR_OVERLAY by default? Having a different version here might mislead someone into thinking that 2.40.0 is the minimum required, and it means we don't test the case for where the git version is exactly 2.38.0.
Sorry, something went wrong.
| const version = await gitUtils.getGitVersionOrThrow(); | ||
| t.is(version, "2.40.0"); | ||
| } finally { | ||
| runGitCommandStub.restore(); |
There was a problem hiding this comment.
This is not necessary.
Sorry, something went wrong.
| runGitCommandStub.restore(); | ||
| gitUtils.resetCachedGitVersion(); |
There was a problem hiding this comment.
As above.
Sorry, something went wrong.
| const messages: LoggedMessage[] = []; | ||
| const logger = getRecordingLogger(messages); |
There was a problem hiding this comment.
As above.
Sorry, something went wrong.
| t.true( | ||
| messages.some( | ||
| (m) => | ||
| m.type === "debug" && | ||
| typeof m.message === "string" && | ||
| m.message.includes("Could not determine Git version"), | ||
| ), | ||
| ); |
There was a problem hiding this comment.
As above.
Sorry, something went wrong.
| runGitCommandStub.restore(); | ||
| gitUtils.resetCachedGitVersion(); |
There was a problem hiding this comment.
As above.
Sorry, something went wrong.
| export const GIT_MINIMUM_VERSION_FOR_OVERLAY = "2.38.0"; | ||
|
|
||
| /** Cached git version to avoid recomputing it multiple times. */ | ||
| let cachedGitVersion: string | undefined; |
There was a problem hiding this comment.
Observation: This will cache the git version for one step in a workflow (e.g. init), but not across steps (e.g. init and analyze).
I think that's probably OK based on the current usage where logGitVersionTelemetry is only called once in init, but does lead to two points:
So this only becomes useful if we need the git version multiple times in the same action.
Sorry, something went wrong.
There was a problem hiding this comment.
The caching makes for an easier API since we don't need to pass the git version around the program, but as you mention, we're not really making use of it now. I've removed it.
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks! Most of my feedback is addressed now, I think. I responded to the question in one of the conversations and added one new question. Other than those, this looks good now.
Sorry, something went wrong.
| // Git version output can vary: "git version 2.40.0" or "git version 2.40.0.windows.1" | ||
| // We capture just the major.minor.patch portion to ensure semver compatibility. | ||
| const match = stdout.match(/git version (\d+\.\d+\.\d+)/); |
There was a problem hiding this comment.
It's probably OK for now, especially if we report the git version in telemetry. We can keep an eye out for unusual version formats that we might care about.
One possible improvement might be to document in the JSDoc that only the first three components are considered or, indeed, return a more structured type than string which also makes it clear that the version might be truncated to just those parts.
Sorry, something went wrong.
| logger.info(`Using Git version ${gitVersion}`); | ||
| await logGitVersionTelemetry(config, gitVersion); | ||
| } catch (e) { | ||
| logger.debug(`Could not determine Git version: ${getErrorMessage(e)}`); |
There was a problem hiding this comment.
Question about the log-levels here. The actual failure here is logged at debug level, and so wouldn't ordinarily be visible (especially in dynamic workflows).
Meanwhile, the subsequent message in getOverlayDatabaseMode is logged at warning level and so would show up quite prominently in the log (including workflow annotations).
That could lead to a situation where the actual problem is not easily debuggable. Should this be a warning instead / in addition to the gitVersion === undefined message?
Sorry, something went wrong.
| /** | ||
| * Git version information | ||
| * | ||
| * The full version string as reported by `git --version` may not be | ||
| * semver-compatible (e.g., "2.40.0.windows.1"). This class captures both | ||
| * the full version string and a truncated semver-compatible version string | ||
| * (e.g., "2.40.0"). | ||
| */ | ||
| export class GitVersionInfo { | ||
| constructor( | ||
| /** Truncated semver-compatible version */ | ||
| public truncatedVersion: string, | ||
| /** Full version string as reported by `git --version` */ | ||
| public fullVersion: string, | ||
| ) {} | ||
|
|
||
| isAtLeast(minVersion: string): boolean { | ||
| return semver.gte(this.truncatedVersion, minVersion); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
Thanks for adding this! This should make it more obvious what's going on.
Sorry, something went wrong.
| const match = stdout.match(/^git version ((\d+\.\d+\.\d+).*)$/); | ||
| if (match?.[1]) { | ||
| return match[1]; | ||
| return new GitVersionInfo(match[2], match[1]); |
There was a problem hiding this comment.
One comment: we might want to think about whether it is worthwhile to store whatever we get from git --version after ^git version as the fullVersion and then only store truncatedVersion if it matches the \d+\.\d+\.\d+ pattern. As it stands, we only store the fullVersion if it starts with the semver-like pattern.
I don't think this is a big deal since I'd expect the git versions to always start with at least three numeric components, so this probably doesn't need to be addressed at this point unless we find that we are missing data for troubleshooting purposes.
Sorry, something went wrong.
There was a problem hiding this comment.
I don't think this is a big deal since I'd expect the git versions to always start with at least three numeric components, so this probably doesn't need to be addressed at this point unless we find that we are missing data for troubleshooting purposes.
Agreed, I'll leave this as-is for now.
Sorry, something went wrong.
| .resolves("git version 2.40.0.windows.1"); | ||
|
|
||
| const version = await gitUtils.getGitVersionOrThrow(); | ||
| // Should extract just the major.minor.patch portion |
There was a problem hiding this comment.
| // Should extract just the major.minor.patch portion | |
| // Should extract just the major.minor.patch portion as `truncatedVersion` |
Sorry, something went wrong.
|
|
||
| test("getGitVersionOrThrow returns version for valid git output", async (t) => { | ||
| sinon.stub(gitUtils as any, "runGitCommand").resolves("git version 2.40.0\n"); | ||
| sinon.stub(gitUtils as any, "runGitCommand").resolves("git version 2.40.0"); |
There was a problem hiding this comment.
I am not sure what motivated this change, but it reminded me that we might want to check that this works correctly across platforms depending on what git uses for line endings in its output there. I think I tried to do something like that for my tests in #3318
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM, aside from one oversight(?)
Sorry, something went wrong.
| // Docker container where git may not be available. | ||
| if ( | ||
| isInTestMode() && | ||
| process.env.CODEQL_ACTION_TOLERATE_MISSING_GIT_VERSION !== "true" |
There was a problem hiding this comment.
You added TOLERATE_MISSING_GIT_VERSION to the EnvVar enum, but aren't using it here.
Sorry, something went wrong.
There was a problem hiding this comment.
![]()
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Overlay analysis depends on getFileOidsUnderPath, which uses git ls-files --format option introduced in Git 2.38.0. This adds a version check to ensure overlay analysis is only enabled when the git version is new enough.
Changes
When git version is insufficient, users will see:
Risk assessment
Which use cases does this change impact?
Workflow types:
Products:
Environments:
How did/will you validate this change?
If something goes wrong after this change is released, what are the mitigation and rollback strategies?
How will you know if something goes wrong after this change is released?
Are there any special considerations for merging or releasing this change?
Merge / deployment checklist
- Confirm this change is backwards compatible with existing workflows.
- Consider adding a changelog entry for this change.
- Confirm the readme and docs have been updated if necessary.
Original prompt💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.