Skip to content

core: add GitCommit type - #13088

Merged
vito merged 20 commits into
mainfrom
core-git-commit
Aug 6, 2026
Merged

vito merged 20 commits into
mainfrom
core-git-commit

Conversation

@shykes

@shykes shykes commented May 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds a GitCommit object to the Git API, plus commit-oriented helpers on GitRef.

  • Use GitRef.targetCommit to get commit details from a branch, tag, or ref. Use GitRepository.commit(id:) to look up a commit directly.
  • Use GitRef.log to list the commits reachable from a ref as GitCommit values, newest first — with an optional path filter and an optional base ref to exclude (i.e. base..ref; the base may even live in a different repository).
  • Use GitCommit.releaseTag / ancestorReleaseTag to find the latest semver tag pointing at (or reachable from) a commit, without running git fetch --tags.
  • GitRef gains commitSHA and name as clearer names for commit and ref, which are now deprecated.

All of the new surface is version-gated behind v1.0.0-0; older module views are unchanged.

Schema diff: https://github.com/dagger/dagger/pull/13088/files#diff-bb8fba2a10b96c16befe2b145e4e580f38839f20e0518cfd8c678d2296c27cb1

extend type GitRepository {
  """Returns details of a commit."""
  commit(id: String!): GitCommit!
}

extend type GitRef {
  """The commit this ref resolves to."""
  targetCommit: GitCommit!

  """The resolved commit SHA at this ref."""
  commitSHA: String!

  """The resolved name of this ref."""
  name: String!

  """
  Commits reachable from this ref, newest first, starting with the commit
  this ref resolves to.
  """
  log(
    """Maximum number of commits to return."""
    limit: Int = 10

    """Only include commits touching these paths, relative to the root of the repository."""
    paths: [String!]

    """Exclude commits reachable from this ref, i.e. only list commits added on top of it."""
    base: GitRefID
  ): [GitCommit!]!

  """The resolved commit id at this ref."""
  commit: String! @deprecated(reason: "Use \"commitSHA\" instead.")

  """The resolved ref name at this ref."""
  ref: String! @deprecated(reason: "Use \"name\" instead.")
}

"""An immutable git commit."""
type GitCommit {
  """The full commit SHA."""
  sha: String!

  """The abbreviated commit SHA."""
  shortSha: String!

  """Git author date, in RFC3339 format."""
  authoredDate: String!

  """Git committer date, in RFC3339 format."""
  committedDate: String!

  """Git author name."""
  authorName: String!

  """Git author email."""
  authorEmail: String!

  """Git committer name."""
  committerName: String!

  """Git committer email."""
  committerEmail: String!

  """Full commit message."""
  message: String!

  """First line of the commit message."""
  messageHeadline: String!

  """Commit message body, excluding the headline."""
  messageBody: String!

  """Parent commit SHAs."""
  parentShas: [String!]!

  """The latest semver release tag that points directly at this commit."""
  releaseTag(includePreRelease: Boolean = false): GitRef

  """The latest semver release tag reachable from this commit."""
  ancestorReleaseTag(includePreRelease: Boolean = false): GitRef

  """The filesystem tree at this commit."""
  tree(discardGitDir: Boolean = false, depth: Int = 1, includeTags: Boolean = false): Directory!
}

Notes

  • GitCommit is keyed by its SHA, so a log entry is the same object — same ID, same cache entry — as the commit looked up directly via GitRepository.commit. Reading a log prefills the metadata onto each entry, so an N-commit log doesn't cost N further mounts.
  • GitRef.log fetches the full history of the refs involved (the same tradeoff commonAncestor makes); local repositories are unaffected. A shallow local checkout silently truncates at its boundary, and a base with no common ancestor simply excludes nothing.
  • Workspaces inherit all of this for free: workspace.git.head is an ordinary GitRef, so a workspace can walk from its own git state to the tree as of any commit in its history.
  • The release tag lookups work against remote repositories without git fetch --tags; for local repositories they overlay the default fetch remote's tags over the local ones (the remote wins if a tag diverges, e.g. after a force-push), and fall back to local tags alone when the remote can't be reached.

Breaking Change

For current clients, GitRepository.commit(id:) changes return type from GitRef to GitCommit. Code that used git(...).commit(id).commit should use git(...).commit(id).sha; code that needs ref behavior should use git(...).ref(id).

Older schema views keep the previous GitRef return for compatibility, along with the undecorated commit/ref fields they shipped with.

Fixes #13086

@shykes
shykes force-pushed the core-git-commit branch 6 times, most recently from dab65fd to a907efb Compare May 11, 2026 17:39
@shykes
shykes force-pushed the core-git-commit branch from a907efb to 6d0fa22 Compare May 12, 2026 16:51
@shykes
shykes marked this pull request as ready for review May 12, 2026 17:38
@shykes
shykes requested a review from a team as a code owner May 12, 2026 17:38
@shykes
shykes requested review from a team as code owners May 12, 2026 21:16
@dagger-codex
dagger-codex Bot force-pushed the core-git-commit branch from f017705 to 7adf9ca Compare May 21, 2026 00:21
@github-actions

github-actions Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@sagikazarmark

Copy link
Copy Markdown
Contributor

Bump, not stale 😄

@github-actions

Copy link
Copy Markdown
Contributor

This PR is stale because it has been open 14 days with no activity. Remove stale label or comment or this will be closed in 7 days.

@github-actions

Copy link
Copy Markdown
Contributor

This PR was closed because it has been stalled for 7 days with no activity.

@github-actions github-actions Bot closed this Jul 25, 2026
@vito vito reopened this Jul 26, 2026
@vito
vito force-pushed the core-git-commit branch 3 times, most recently from a500ef0 to 526494d Compare July 30, 2026 20:55
@vito
vito force-pushed the core-git-commit branch 2 times, most recently from c9c3fc4 to 3bc308b Compare August 5, 2026 13:48
@grouville
grouville self-requested a review August 5, 2026 19:37

@grouville grouville left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, found 2 edge cases. No storng opinion on those

Comment thread core/schema/git.go Resolved
Comment thread core/git.go Resolved
@vito
vito force-pushed the core-git-commit branch 2 times, most recently from d840670 to be1b4ff Compare August 6, 2026 04:01
shykes and others added 20 commits August 5, 2026 22:55
Adds GitCommit as the commit-metadata object for the core Git API. Refs can resolve to it with GitRef.asCommit, and direct commit lookup returns it in the current schema.

Breaking change: for current clients, GitRepository.commit(id:) changes return type from GitRef to GitCommit. Code that used git(...).commit(id).commit should use git(...).commit(id).sha; code that needs ref behavior should use git(...).ref(id). Older schema views keep the previous GitRef return for compatibility.

Signed-off-by: Solomon Hykes <[email protected]>
Keep GitCommit keyed by its SHA so commit tree checkouts do not inherit branch or tag identity. Keep the original ref name only as a fetch fallback for remotes that cannot fetch by SHA.

Cache commit metadata on the GitCommit object and share the GitRef/GitCommit repo attachment code.

Signed-off-by: Solomon Hykes <[email protected]>
Adds commitSHA and name as clearer aliases for commit and ref. Deprecates the old field names so the API can move away from commit later.

Signed-off-by: Solomon Hykes <[email protected]>
Renames GitRef.asCommit to targetCommit and regenerates the Go SDK so clients use the clearer field name.

Signed-off-by: Solomon Hykes <[email protected]>
GitCommit now has releaseTag and ancestorReleaseTag.

They choose the latest semver tag without running git fetch --tags. For local repositories, the lookup combines local tags with tags from the default fetch remote and errors if the same tag name points at two different commits.

Signed-off-by: Solomon Hykes <[email protected]>
MergeBase already knew how to mount a set of refs with full history: refs
sharing a repository go through a single backend mount, refs from different
repositories get joined into a temporary repository. Pull that topology out
into mountRefs so other multi-ref git operations can reuse it, and rewrite
MergeBase on top of it. No behavior change.

Signed-off-by: Alex Suraci <[email protected]>
GitRef.log lists the commits reachable from a ref as GitCommit values, newest
first, starting with the commit the ref resolves to. It takes a limit
(default 10), an optional set of paths to restrict the log to commits touching
them, and an optional base ref whose reachable commits are excluded, i.e.
base..ref. The base ref may live in a different repository, which is why this
builds on mountRefs.

Each entry is built by selecting the repository's commit field for its SHA
rather than constructed inline, so a log entry is the same object, with the
same ID and cache entry, as the commit looked up directly by that SHA. Since
the whole log is read within a single mount, the metadata is prefilled onto
each commit, sparing an N-commit log N further mounts to read its fields back.

Reading a log fetches the full history of the refs involved, the same tradeoff
commonAncestor already makes; local repositories are unaffected. A shallow
local checkout silently truncates at its boundary, and a base ref with no
common ancestor is not an error - it just excludes nothing.

Workspaces inherit this for free: workspace.git.head is an ordinary GitRef.

Signed-off-by: Alex Suraci <[email protected]>
The point of returning GitCommit from GitRef.log rather than bare metadata is
that each entry is a whole commit, so a workspace can walk from its own git
state to the tree as of any commit in its history. Assert that end to end:
each log entry's tree checks out that commit's content, not HEAD's.

Signed-off-by: Alex Suraci <[email protected]>
GitRef.commit and GitRef.ref were deprecated in favor of commitSHA and name,
which resolve through the same underlying resolvers, so the switch is purely
cosmetic. Updating the callers clears the SA1019 staticcheck warnings without
changing any assertions.

Signed-off-by: Alex Suraci <[email protected]>
Gate the GitCommit class itself behind v1.0.0-0, following the same pattern
as Volume and the Workspace types. The class-level view filter propagates
through the install hooks, so the GitCommitID scalar, loadGitCommitFromID,
and the Env/Binding extensions are all hidden from older module views by the
single InstallObject call.

The new GitRef fields (targetCommit, commitSHA, name) get the same gate;
targetCommit previously claimed AllVersion despite returning a type old
views cannot see. The commit and ref deprecations are split into view-scoped
definitions so pre-v1.0.0 views keep the undecorated fields they shipped
with, keeping the base schema allowlist byte-identical - the deprecation
reasons point at replacement fields those views do not have.

GitCommit.tree also reused GitRef.tree's args struct, dragging the
pre-v0.12.0 sshKnownHosts/sshAuthSocket compat args onto a brand-new type;
it now has its own args struct without them.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
Splitting commit() into a GitCommit resolver and a legacy commitRef dropped
the strict-refs guard from the legacy path, which serves every view before
v1.0.0-0. Views in [v0.19.0, v1.0.0-0) regressed to resolving arbitrary
refs: commit("main") silently resolved the branch instead of erroring, and
worse, entered the workspace lockfile path that non-SHA lookups trigger in
ref(), recording lock entries the strict guard used to make unreachable.

Restore the guard in commitRef, and pin a legacy test inside the affected
window; existing coverage only exercised the latest view and a pre-v0.19.0
module, bracketing the regression on both sides without hitting it.

Signed-off-by: Alex Suraci <[email protected]>
reconcileGitTagRefs errored whenever a tag name resolved to different
commits locally and remotely, and it ran before the semver filter, so a
moved nightly/latest tag or any local-only divergence failed the whole
releaseTag query even when the offending tag could never be selected.

The error was dubious anyway: mistakes happen, people push over semver
tags, and a local checkout that predates a force-push is stale, not
broken. An error that clears up by asking a different engine - one whose
checkout postdates the force-push - is not protecting anything. Drop the
conflict check and let the remote SHA win, which is what a fresh clone
would report.

Signed-off-by: Alex Suraci <[email protected]>
For local repositories, releaseTag consulted the default fetch remote via
ls-remote on the mounted checkout and failed the whole field if that call
failed. The mounted local repo is a bare CLI with none of the auth wiring
RemoteGitRepository sets up (SSH sock, tokens, headers, resolv override),
so a private origin, an SSH remote, or an offline machine turned a tag
lookup into an error even though the local tags could answer it.

Make the remote consultation best-effort: on ls-remote failure, warn and
fall back to local tags. Context cancellation still propagates as an
error rather than masquerading as an empty remote.

Signed-off-by: Alex Suraci <[email protected]>
The release tag fixture had no fetch remote at all, so the remote
consultation path was never exercised. Point origin at an unreachable
host and assert the lookup still answers from local tags instead of
propagating the ls-remote failure.

Signed-off-by: Alex Suraci <[email protected]>
parseGitTimezoneOffset required exactly +/-HHMM, but git reads the digits
as hours*100+minutes at any width, so offsets like +051800 (real, common
in history imported from CVS/SVN) parse fine for git and errored here.
Since every GitCommit field funnels through Metadata() and GitRef.log
parses each commit in the window inline, one such commit anywhere in the
range failed the entire log call.

Parse offsets the way git does, and when the result is garbage or beyond
what RFC3339 can express (+/-23:59), render the date in UTC instead of
erroring: the timestamp is exact regardless, only the displayed zone
degrades.

Signed-off-by: Alex Suraci <[email protected]>
The content digests for GitRef and GitCommit hash the repository URL
plus the resolved SHA, but URL is only populated for remote backends, so
every local repository hashed as "". Two different local checkouts at
the same commit unified to one cache entry. That was latent for GitRef
(the checked-out tree is the same either way), but releaseTag and
ancestorReleaseTag are the first fields whose answer depends on which
repository you're standing in - local tag sets differ - so the collision
became observable, e.g. a fork and an upstream clone on the same host.

Mix the backing Directory's content digest into both results for local
backends. As a bonus this keys cached answers to the actual repository
state, so re-tagging a local repo produces a fresh digest instead of a
stale cached releaseTag.

Signed-off-by: Alex Suraci <[email protected]>
A commit is identified by its URL and SHA, so the same GitCommit result is
shared across sessions - including the GitRepository it hangs off, and the
ls-remote snapshot taken when that repository was resolved. Tags aren't
immutable, so releaseTag and ancestorReleaseTag could answer a later session
from an older session's advertised tags, and keep doing so forever: a tag
pushed after the first lookup would never show up.

Scope both fields per-session and have selectGitReleaseTag re-resolve the
remote rather than reading the snapshot carried by the commit. Both parts are
needed - per-session scoping alone still computes the answer from the shared
parent's stale snapshot. This leaves the commit's identity alone, so tagging a
repository no longer invalidates cached metadata and trees for every commit in
it, and it covers local repositories too, whose tag lookups consult their fetch
remote the same way. The freshness guarantee now matches GitRepository.tags and
latestVersion: one resolution per session, against that session's remote.

Signed-off-by: Alex Suraci <[email protected]>
Signed-off-by: Alex Suraci <[email protected]>
@vito
vito merged commit 76437f1 into main Aug 6, 2026
88 checks passed
@vito
vito deleted the core-git-commit branch August 6, 2026 13:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

New core type: GitCommit

5 participants