Repository navigation
Description
Problem
The core Git API currently models branches, tags, HEAD, and commit IDs through GitRef. That works well for ref lookup and tree checkout, because a commit ID can be used as a ref-like revision.
But commit metadata does not belong directly on GitRef. A ref is a pointer or name that resolves to a commit; the commit itself is the immutable object that has author, committer, message, parent, tree, and release-tag metadata.
Today this leaves no clean place to expose commit details such as committer date, author date, message, parent SHAs, or the semver release tag associated with a commit.
Solution
Add a GitCommit object and let refs resolve to it.
extend type GitRepository {
"""Returns details of a commit."""
commit(id: String!): GitCommit!
}
extend type GitRef {
"""The commit this ref resolves to."""
asCommit: GitCommit!
}
"""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 filesystem tree at this commit."""
tree(
discardGitDir: Boolean = false
depth: Int = 1
includeTags: Boolean = false
): Directory!
"""Highest semver tag pointing directly at this commit, if any."""
releaseTag(includePreRelease: Boolean = false): GitRef
"""Highest semver tag reachable from this commit, if any."""
ancestorReleaseTag(includePreRelease: Boolean = false): GitRef
}GitRef.commit should remain the existing SHA string for compatibility.
GitRepository.commit(id:) can return GitCommit, because GitRepository.ref(name:) already covers the “treat this name or commit ID as a ref” use case.
Release Tags
releaseTag returns the highest semver tag that points directly at the commit.
ancestorReleaseTag returns the highest semver tag reachable from the commit.
“Highest” means semver order, not newest tag date or closest ancestor. If multiple semver tags point at the same commit, the highest semver tag wins.
By default, pre-release tags are ignored. When includePreRelease is true, stable and pre-release tags are considered together.
Tag lookup should be pure and reusable across WorkspaceGit and GitRepository.
Do not implement this with git fetch --tags. Fetching tags mutates local tag refs and object state, which is awkward for a GitCommit that should work for both a mutable local workspace repo and an immutable GitRepository.
Instead, build an effective tag set by reconciling local tags with remote tags:
- include local-only tags
- include remote-only tags
- include matching local and remote tags
- if local and remote have the same full tag ref but resolve to different commits, return an error
Compare peeled commit SHAs, not raw tag object SHAs, so annotated tags do not produce false conflicts.
For local repositories, choose the remote the same way git fetch --tags does when no remote is specified: use the current branch’s upstream remote if configured, otherwise use origin. If neither exists, use local tags only.
For remote GitRepository, use the repository’s configured remote URL.
Ancestor lookup may fetch commit objects needed for reachability checks, but it must not fetch tags into local tag refs.
Example
{
git(url: "https://github.com/dagger/dagger") {
head {
ref
commit
asCommit {
committedDate
messageHeadline
releaseTag {
ref
}
ancestorReleaseTag(includePreRelease: true) {
ref
}
}
}
commit(id: "b6315d8f2810962c601af73f86831f6866ea798b") {
sha
authoredDate
committedDate
parentShas
}
}
}Workspace git composes through the same commit API:
{
currentWorkspace {
git {
head {
asCommit {
releaseTag {
ref
}
ancestorReleaseTag {
ref
}
}
}
}
}
}Laziness
Scalar fields on GitCommit should read only commit object metadata. They should not hydrate or checkout the filesystem tree.
GitCommit.tree should be the boundary where Dagger fetches or materializes tree contents.
Release tag lookup should not checkout the tree or mutate .git. Ancestor release tag lookup should only materialize the commit objects needed to answer reachability.
Activity
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
core: add Workspace.git API
8 remaining items
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
toolchains/go: stamp VCS info into binaries via buildinfo ldflags
Merge pull request #13313 from dagger/better-version-strings