Skip to content

Add content hash support + support EARTH_GIT_* builtins#341

Open
gilescope wants to merge 9 commits intomainfrom
giles-content
Open

Add content hash support + support EARTH_GIT_* builtins#341
gilescope wants to merge 9 commits intomainfrom
giles-content

Conversation

@gilescope
Copy link

@gilescope gilescope commented Feb 25, 2026

Adds EARTH_GIT_CONTENT_HASH to surface git's HEAD^{tree} stable content hash.
This doesn't change with squashs, merges or rebases - as long as the git contents is the same the hash is the same.

While we're in the area, ensures all the existing EARTHLY_GIT_* can be used as EARTH_GIT_* also and docs refer to those now.

Fixes #339

Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope gilescope requested a review from a team as a code owner February 25, 2026 06:32
@gilescope gilescope requested review from kmannislands and removed request for a team February 25, 2026 06:32
@github-actions
Copy link

github-actions bot commented Feb 25, 2026

🎉 Are we earthbuild yet?

Great progress! You've reduced "earthly" occurrences by 11 (0.20%)

📈 Overall Progress

Branch Total Count
main 5626
This PR 5615
Difference -11 (0.2%)

📁 Changes by file type:

File Type Change
Go files (.go) ➖ No change
Documentation (.md) ✅ -11
Earthfiles ➖ No change

Keep up the great work migrating from Earthly to Earthbuild! 🚀

💡 Tips for finding more occurrences

Run locally to see detailed breakdown:

./.github/scripts/count-earthly.sh

Note that the goal is not to reach 0.
There is anticipated to be at least some occurences of earthly in the source code due to backwards compatibility with config files and language constructs.

@gemini-code-assist
Copy link

Summary of Changes

Hello @gilescope, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the build system by introducing support for Git's content hash, also known as the tree hash. This new capability allows users to access a stable, content-addressable identifier for the current state of the Git repository's working tree, which is crucial for ensuring build reproducibility and caching. The content hash is now exposed via the EARTHBUILD_GIT_CONTENT_HASH variable.

Highlights

  • Git Content Hash Support: Introduced support for Git content hash (tree hash) to be exposed via the EARTHBUILD_GIT_CONTENT_HASH variable.
  • Data Structure Enhancements: Added a contentHash field to resolvedGitProject and GitMetadata structs to store the Git tree hash.
  • Git Command Integration: Implemented logic to retrieve the Git tree hash using the git rev-parse HEAD^{tree} command.
  • Built-in Variable Exposure: Included EARTHBUILD_GIT_CONTENT_HASH as a new built-in argument, making the content hash accessible within the build system.
Changelog
  • buildcontext/git.go
    • Added contentHash field to resolvedGitProject struct.
    • Populated contentHash by executing git rev-parse HEAD^{tree}.
    • Passed the contentHash to the resolveEarthProject function.
  • util/gitutil/detectgit.go
    • Defined ErrCouldNotDetectGitContentHash for error handling.
    • Added ContentHash field to GitMetadata struct.
    • Implemented detectGitContentHash function to retrieve the Git tree hash.
    • Integrated detectGitContentHash into the Metadata function.
  • util/gitutil/detectgit_test.go
    • Added TestDetectGitContentHash to verify the correct detection of the Git content hash, including scenarios with amended commits.
  • variables/builtin.go
    • Added EarthbuildGitContentHash to the BuiltinArgs function, making the content hash available as a built-in variable.
  • variables/builtin_test.go
    • Added TestBuiltinArgsContentHash to confirm the content hash is correctly added to the scope.
    • Added TestBuiltinArgsContentHashNilGitMeta to handle cases where Git metadata is not available.
  • variables/reserved/names.go
    • Declared EarthbuildGitContentHash as a new constant.
    • Registered EarthbuildGitContentHash in the args map of reserved variable names.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively adds support for EARTHBUILD_GIT_CONTENT_HASH. The implementation is solid, and the accompanying tests are thorough and well-designed. My feedback focuses on improving maintainability by reducing code duplication in two areas by abstracting repeated logic into helper functions.

Signed-off-by: Giles Cope <gilescope@gmail.com>
Copy link

@kmannislands kmannislands left a comment

Choose a reason for hiding this comment

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

Very interesting. Definitely see how this could be useful.

Only feedback is one naming

Signed-off-by: Giles Cope <gilescope@gmail.com>
Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope
Copy link
Author

Refactored the code to remove the duplication and switched prefix. Potentially this PR is ready.

@gilescope gilescope changed the title Add content hash support Add content hash support + support EARTH_GIT_* builtins Feb 27, 2026
@gilescope gilescope enabled auto-merge (squash) February 27, 2026 08:35
Signed-off-by: Giles Cope <gilescope@gmail.com>
@gilescope gilescope requested a review from kmannislands March 4, 2026 20:02
@gilescope gilescope mentioned this pull request Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EARTHBUILD_GIT_CONTENT_HASH

2 participants