Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 16, 2025

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

  • src/git-utils.ts:
    • Added GIT_MINIMUM_VERSION_FOR_OVERLAY constant ("2.38.0")
    • Added getGitVersionOrThrow() function that throws with detailed error messages
    • Added getGitVersion() function with caching and error logging
    • Added gitVersionAtLeast() function for semver comparison
    • Added logGitVersionTelemetry() function to log git version as telemetry diagnostic
    • Added resetCachedGitVersion() for testing support
  • src/config-utils.ts: Added git version check in getOverlayDatabaseMode() that falls back to non-overlay analysis with a warning if git is too old
  • src/diagnostics.ts: Added makeTelemetryDiagnostic() helper function for creating telemetry-only diagnostics
  • src/init-action.ts:
    • Added call to logGitVersionTelemetry() for git version telemetry
    • Refactored bundle-download-telemetry and zstd-availability diagnostics to use makeTelemetryDiagnostic()
  • Tests: Added tests for version parsing (including Windows-style versions like 2.40.0.windows.1), caching behavior, and overlay fallback scenarios

When git version is insufficient, users will see:

Cannot build an overlay database because the installed Git version is older than 2.38.0. Falling back to creating a normal full database instead.

Risk assessment

  • Low risk: Changes add a precondition check to existing overlay analysis feature. Falls back gracefully to full database creation.

Which use cases does this change impact?

Workflow types:

  • Advanced setup - Impacts users who have custom CodeQL workflows.
  • Managed - Impacts users with dynamic workflows (Default Setup, CCR, ...).

Products:

  • Code Scanning - The changes impact analyses when analysis-kinds: code-scanning.

Environments:

  • Dotcom - Impacts CodeQL workflows on github.com and/or GitHub Enterprise Cloud with Data Residency.
  • GHES - Impacts CodeQL workflows on GitHub Enterprise Server.

How did/will you validate this change?

  • Unit tests - I am depending on unit test coverage (i.e. tests in .test.ts files).

If something goes wrong after this change is released, what are the mitigation and rollback strategies?

  • Rollback - Change can only be disabled by rolling back the release or releasing a new version with a fix.

How will you know if something goes wrong after this change is released?

  • Telemetry - I rely on existing telemetry or have made changes to the telemetry.
    • Dashboards - I will watch relevant dashboards for issues after the release.

Are there any special considerations for merging or releasing this change?

  • No special considerations - This change can be merged at any time.

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

Overlay analysis depends on getFileOidsUnderPath, which requires a git version of at least 2.38.0. Update the enablement check for overlay to ensure the git version is new enough


💡 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.

Copilot AI and others added 2 commits December 16, 2025 16:22
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>
@github-actions github-actions bot added the size/M Should be of average difficulty to review label Dec 16, 2025
Copilot AI changed the title [WIP] Update enablement check for overlay with git version requirement Add git version check for overlay analysis enablement Dec 16, 2025
Copilot AI requested a review from henrymercer December 16, 2025 16:32
@henrymercer henrymercer marked this pull request as ready for review December 16, 2025 16:56
@henrymercer henrymercer requested a review from a team as a code owner December 16, 2025 16:56
Copilot AI review requested due to automatic review settings December 16, 2025 16:56
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

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:

  • Added Git version detection and comparison utilities
  • Integrated version check into overlay analysis enablement logic
  • Falls back to full database analysis with a warning when Git is too old

Reviewed 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

@henrymercer henrymercer removed their request for review December 16, 2025 16:56
@henrymercer
Copy link
Contributor

@copilot Please address the following feedback:

Error handling improvements

  • Cache the version of git, so we don't need to recompute it if we call gitVersionAtLeast multiple times
  • Refactor getGitVersion to getGitVersionOrThrow, and log the error message in gitVersionAtLeast, so we can debug using the original error message.

Telemetry

  • Add a helper function to diagnostics.ts that creates a telemetry diagnostic like the one we're creating for codeql-action/bundle-download-telemetry.
  • Modify getGitVersion to log a telemetry diagnostic with the git version number.

Copilot AI and others added 2 commits December 16, 2025 17:19
…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>
Copy link
Contributor Author

Copilot AI commented Dec 16, 2025

@copilot Please address the following feedback:

Error handling improvements

...

Addressed in commits c3dc529 and 393c074:

Error handling improvements:

  • Added caching for git version via cachedGitVersion module variable
  • Refactored to getGitVersionOrThrow() that throws with detailed error messages
  • getGitVersion() now logs errors with original message via getErrorMessage(e)
  • Added resetCachedGitVersion() for testing

Telemetry:

  • Added makeTelemetryDiagnostic() helper in diagnostics.ts
  • Added logGitVersionTelemetry() function that logs git version to telemetry
  • Called from init-action.ts after bundle download telemetry
  • Refactored existing bundle-download-telemetry and zstd-availability diagnostics to use the new helper

Copilot AI requested a review from henrymercer December 16, 2025 17:27
@henrymercer henrymercer removed their request for review December 16, 2025 17:30
@github-actions github-actions bot added size/L May be hard to review and removed size/M Should be of average difficulty to review labels Dec 16, 2025
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have given this an initial review. Two primary points:

  • I am not keen on having the logging/diagnostic code in git-utils. That should essentially just have getGitVersionOrThrow in it along with maybe the caching.
  • The quality of the tests is somewhat poor.

src/git-utils.ts Outdated
Comment on lines 11 to 13
import type { Config } from "./config-utils";
import { addDiagnostic, makeTelemetryDiagnostic } from "./diagnostics";
import { Logger } from "./logging";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

* 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* @param name Display name for the ID.
* @param name Display name for the diagnostic.

languages: [KnownLanguage.javascript],
codeqlVersion: CODEQL_OVERLAY_MINIMUM_VERSION,
gitRoot: "/some/git/root",
gitVersion: "2.40.0", // Default to a version that supports overlay analysis
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

const version = await gitUtils.getGitVersionOrThrow();
t.is(version, "2.40.0");
} finally {
runGitCommandStub.restore();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not necessary.

Comment on lines 557 to 558
runGitCommandStub.restore();
gitUtils.resetCachedGitVersion();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Comment on lines 550 to 551
const messages: LoggedMessage[] = [];
const logger = getRecordingLogger(messages);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Comment on lines 574 to 581
t.true(
messages.some(
(m) =>
m.type === "debug" &&
typeof m.message === "string" &&
m.message.includes("Could not determine Git version"),
),
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

Comment on lines 583 to 584
runGitCommandStub.restore();
gitUtils.resetCachedGitVersion();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above.

src/git-utils.ts Outdated
export const GIT_MINIMUM_VERSION_FOR_OVERLAY = "2.38.0";

/** Cached git version to avoid recomputing it multiple times. */
let cachedGitVersion: string | undefined;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  • What is the point of caching this if we only use it once right now?
  • If we start needing this elsewhere, then we still might not make use of the caching if the other uses are in steps other than init.

So this only becomes useful if we need the git version multiple times in the same action.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions bot added size/M Should be of average difficulty to review and removed size/L May be hard to review labels Dec 17, 2025
@henrymercer henrymercer requested a review from mbg December 17, 2025 15:21
Copy link
Member

@mbg mbg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

src/git-utils.ts Outdated
Comment on lines 49 to 51
// 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+)/);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

logger.info(`Using Git version ${gitVersion}`);
await logGitVersionTelemetry(config, gitVersion);
} catch (e) {
logger.debug(`Could not determine Git version: ${getErrorMessage(e)}`);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Should be of average difficulty to review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants