Skip to content

Workspace.git(): contextual information about a workspace's git repository#13074

Merged
dagger-codex[bot] merged 1 commit into
1.0-betafrom
workspace-git
Jun 3, 2026
Merged

Workspace.git(): contextual information about a workspace's git repository#13074
dagger-codex[bot] merged 1 commit into
1.0-betafrom
workspace-git

Conversation

@shykes
Copy link
Copy Markdown
Contributor

@shykes shykes commented May 1, 2026

This adds Workspace.git, a local git view for the current workspace.

extend type Workspace {
  """Git state for this workspace. Errors if the workspace is not in a git repository."""
  git: WorkspaceGit!
}

"""Local git state for a workspace."""
type WorkspaceGit {
  """The checked-out HEAD of this workspace."""
  head: GitRef!

  """Uncommitted changes in this workspace, using the same rules as GitRepository.uncommitted."""
  uncommitted: Changeset!
}

Schema diff (tracks latest workspace-git branch / PR head): https://github.com/dagger/dagger/pull/13074/files#diff-1b91750d917ed604e8eb08e4f5325f167511cd697317187b56d84b3736662e5f

uncommitted checks the whole repository, even when the current workspace is a nested directory. Worktrees are not supported yet; .git points outside the workspace boundary, so this returns an explicit unsupported-worktree error instead of following it.

Semver tag helpers are left for the GitCommit proposal in #13086.

Tests

dagger -m github.com/dagger/dagger/toolchains/engine-dev@pull/13074/head call test --progress=report --pkg=./core/workspace --timeout=20m
dagger -m github.com/dagger/dagger/toolchains/engine-dev@pull/13074/head call test --progress=report --pkg=./core/schema --timeout=20m
dagger -m github.com/dagger/dagger/toolchains/engine-dev@pull/13074/head call test --progress=report --pkg=./core/integration --run=TestWorkspace/TestWorkspaceGit --test-verbose --timeout=20m

@shykes shykes requested review from a team as code owners May 1, 2026 16:25
@shykes shykes changed the title core: add Workspace.git API core API: Workspace.git() May 1, 2026
@shykes shykes changed the title core API: Workspace.git() Workspace.git() May 1, 2026
@shykes shykes changed the title Workspace.git() Workspace.git(): contextual git information about a workspace May 1, 2026
@shykes shykes changed the title Workspace.git(): contextual git information about a workspace Workspace.git(): contextual information about a workspace's git repository May 1, 2026
@shykes shykes force-pushed the workspace-git branch 3 times, most recently from cb13ac3 to 47e0712 Compare May 5, 2026 07:56
Comment thread core/schema/workspace.go
if err != nil {
return fmt.Errorf("workspace git metadata: %w", err)
}
if st.FileType == core.FileTypeRegular {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: if !st.IsDir() { below would also cover this case if I'm not mistaken.

@shykes
Copy link
Copy Markdown
Contributor Author

shykes commented May 5, 2026

I'm reducing the scope of this - removing fields related to semver tags. Moving that part to #13086 instead (it's cleaner attached to GitCommit).

@shykes shykes force-pushed the workspace-git branch 9 times, most recently from 00ebda2 to b684ab1 Compare May 12, 2026 16:51
@dagger-codex dagger-codex Bot force-pushed the workspace-git branch 2 times, most recently from b19e833 to 6b77086 Compare May 22, 2026 06:09
@dagger-codex dagger-codex Bot force-pushed the workspace-git branch 3 times, most recently from da07a4f to e161c1e Compare May 29, 2026 23:18
@dagger-codex dagger-codex Bot changed the base branch from main to 1.0-beta June 1, 2026 19:52
@dagger-codex dagger-codex Bot changed the base branch from 1.0-beta to main June 1, 2026 19:53
@dagger-codex dagger-codex Bot force-pushed the workspace-git branch 2 times, most recently from 1537f05 to 20de32d Compare June 1, 2026 21:45
@dagger-codex dagger-codex Bot changed the base branch from main to 1.0-beta June 1, 2026 21:46
Expose local git state from the current Workspace without requiring users to model the workspace as a remote-oriented GitRepository.

Workspace.git returns a WorkspaceGit object. WorkspaceGit.head returns the checked-out HEAD as a GitRef, and WorkspaceGit.uncommitted returns the same Changeset shape and dirty/clean semantics as GitRepository.uncommitted.

On 1.0-beta, workspace detection is already rooted at the git boundary, so Workspace.git validates the .git entry at call time instead of persisting a separate HasGit bit. The repository is materialized from the workspace root, not the current workspace cwd, so nested cwd calls still report whole-repository dirty state.

Git worktrees remain an explicit first-pass boundary because their .git file points at metadata outside the workspace boundary.

Generated GraphQL docs and SDK bindings were refreshed with:

    DAGGER_CLOUD_ENGINE=1 dagger --cloud generate --progress=plain -y

Verification:

    GOMAXPROCS=2 go test ./core/workspace ./core/schema

    DAGGER_CLOUD_ENGINE=1 dagger --cloud -m toolchains/engine-dev call test --progress=plain --pkg=./core/integration --run=TestWorkspace/TestWorkspaceGit --test-verbose --timeout=20m

Signed-off-by: Solomon Hykes <solomon@dagger.io>
@dagger-codex dagger-codex Bot merged commit fdce7fc into 1.0-beta Jun 3, 2026
76 checks passed
@dagger-codex dagger-codex Bot deleted the workspace-git branch June 3, 2026 01:12
tiborvass pushed a commit that referenced this pull request Jun 3, 2026
Add an auto-acquired *dagger.GitRepository input to the Go builder's New
constructor. When present (default: the workspace root), read HEAD commit
and uncommitted state, and append -X github.com/dagger/go/buildinfo.Injected*=
values to the -ldflags pipeline.

Binaries that import buildinfo (transitively via
github.com/dagger/dagger/internal/version, after P1) self-report VCS info
through runtime/debug.ReadBuildInfo without needing .git inside the build
container.

GitRepository was chosen over a Directory input because it's lazier — no
full repo upload, the engine fetches only what GraphQL operations actually
need. The dirty signal uses GitRepository.uncommitted, which the engine
already implements with the right gitignore semantics.

Inspection errors are swallowed silently — builds proceed without VCS info
rather than aborting (matches the deleted version/ module's failure mode).

TODO: switch to Workspace.git (PR #13074) when Dagger >= 1.0.0-beta.2.
It's lazier still, supports nested workspaces cleanly, and will expose
commit time once the GitCommit proposal (#13086) lands.

No caller changes needed: cli-dev/engine-dev/release continue calling
dag.Go(GoOpts{...}) unchanged. The new input auto-acquires from the
workspace root at module-call time. dagger.gen.go for consumers will pick
up the new optional field next time they run `dagger develop`.
tiborvass pushed a commit that referenced this pull request Jun 3, 2026
Add an auto-acquired *dagger.GitRepository input to the Go builder's New
constructor. When present (default: the workspace root), read HEAD commit
and uncommitted state, and append -X github.com/dagger/go/buildinfo.Injected*=
values to the -ldflags pipeline.

Binaries that import buildinfo (transitively via
github.com/dagger/dagger/internal/version, after P1) self-report VCS info
through runtime/debug.ReadBuildInfo without needing .git inside the build
container.

GitRepository was chosen over a Directory input because it's lazier — no
full repo upload, the engine fetches only what GraphQL operations actually
need. The dirty signal uses GitRepository.uncommitted, which the engine
already implements with the right gitignore semantics.

Inspection errors are swallowed silently — builds proceed without VCS info
rather than aborting (matches the deleted version/ module's failure mode).

TODO: switch to Workspace.git (PR #13074) when Dagger >= 1.0.0-beta.2.
It's lazier still, supports nested workspaces cleanly, and will expose
commit time once the GitCommit proposal (#13086) lands.

No caller changes needed: cli-dev/engine-dev/release continue calling
dag.Go(GoOpts{...}) unchanged. The new input auto-acquires from the
workspace root at module-call time. dagger.gen.go for consumers will pick
up the new optional field next time they run `dagger develop`.

Signed-off-by: Solomon Hykes <solomon@dagger.io>
tiborvass pushed a commit that referenced this pull request Jun 4, 2026
Add an auto-acquired *dagger.GitRepository input to the Go builder's New
constructor. When present (default: the workspace root), read HEAD commit
and uncommitted state, and append -X github.com/dagger/go/buildinfo.Injected*=
values to the -ldflags pipeline.

Binaries that import buildinfo (transitively via
github.com/dagger/dagger/internal/version, after P1) self-report VCS info
through runtime/debug.ReadBuildInfo without needing .git inside the build
container.

GitRepository was chosen over a Directory input because it's lazier — no
full repo upload, the engine fetches only what GraphQL operations actually
need. The dirty signal uses GitRepository.uncommitted, which the engine
already implements with the right gitignore semantics.

Inspection errors are swallowed silently — builds proceed without VCS info
rather than aborting (matches the deleted version/ module's failure mode).

TODO: switch to Workspace.git (PR #13074) when Dagger >= 1.0.0-beta.2.
It's lazier still, supports nested workspaces cleanly, and will expose
commit time once the GitCommit proposal (#13086) lands.

No caller changes needed: cli-dev/engine-dev/release continue calling
dag.Go(GoOpts{...}) unchanged. The new input auto-acquires from the
workspace root at module-call time. dagger.gen.go for consumers will pick
up the new optional field next time they run `dagger develop`.

Signed-off-by: Solomon Hykes <solomon@dagger.io>
dagger-codex Bot pushed a commit that referenced this pull request Jun 4, 2026
Add an auto-acquired *dagger.GitRepository input to the Go builder's New
constructor. When present (default: the workspace root), read HEAD commit
and uncommitted state, and append -X github.com/dagger/go/buildinfo.Injected*=
values to the -ldflags pipeline.

Binaries that import buildinfo (transitively via
github.com/dagger/dagger/internal/version, after P1) self-report VCS info
through runtime/debug.ReadBuildInfo without needing .git inside the build
container.

GitRepository was chosen over a Directory input because it's lazier — no
full repo upload, the engine fetches only what GraphQL operations actually
need. The dirty signal uses GitRepository.uncommitted, which the engine
already implements with the right gitignore semantics.

Inspection errors are swallowed silently — builds proceed without VCS info
rather than aborting (matches the deleted version/ module's failure mode).

TODO: switch to Workspace.git (PR #13074) when Dagger >= 1.0.0-beta.2.
It's lazier still, supports nested workspaces cleanly, and will expose
commit time once the GitCommit proposal (#13086) lands.

No caller changes needed: cli-dev/engine-dev/release continue calling
dag.Go(GoOpts{...}) unchanged. The new input auto-acquires from the
workspace root at module-call time. dagger.gen.go for consumers will pick
up the new optional field next time they run `dagger develop`.

Signed-off-by: Solomon Hykes <solomon@dagger.io>
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.

2 participants