Skip to content

feat: add contextual git - #10847

Merged
jedevc merged 5 commits into
dagger:mainfrom
jedevc:contextual-git
Sep 4, 2025
Merged

jedevc merged 5 commits into
dagger:mainfrom
jedevc:contextual-git

Conversation

@jedevc

@jedevc jedevc commented Aug 5, 2025 •

Copy link
Copy Markdown
Contributor

Fixes #8520. Follow-up to #10195.

This allows a module to get git information about itself - it can do this through the core Git type.

The defaultPath annotation is extended to allow setting a default value for a GitRepository/GitRef parameter. If the caller does not provide a value, the method uses the specified default - either a local path (e.g., "./.git") or a remote repository URL (e.g., "https://github.com/dagger/dagger.git").

@jedevc
jedevc marked this pull request as draft August 5, 2025 15:35
@jedevc
jedevc force-pushed the contextual-git branch 5 times, most recently from a22b4e8 to 0de9ec0 Compare August 7, 2025 10:15
@jedevc
jedevc marked this pull request as ready for review August 7, 2025 10:15
@jedevc
jedevc requested review from a team as code owners August 7, 2025 10:15
@jedevc
jedevc force-pushed the contextual-git branch 3 times, most recently from 7cfb282 to 5741762 Compare August 7, 2025 12:05
@jedevc jedevc mentioned this pull request Aug 7, 2025
@shykes

shykes commented Aug 7, 2025

Copy link
Copy Markdown
Contributor

Love the feature but a little worried about a proliferation of +defaultXYZ, it's not exactly intuitive and will get worse the more we add...

What would happen if we just made this +default ?

Comment thread docs/docs-graphql/schema.graphqls Resolved
@helderco

This comment was marked as resolved.

@jedevc

jedevc commented Aug 11, 2025

Copy link
Copy Markdown
Contributor Author

Love the feature but a little worried about a proliferation of +defaultXYZ, it's not exactly intuitive and will get worse the more we add...

What would happen if we just made this +default ?

I'd be a big fan. But for consistency, we'd probably want to make +default work with Files/Directorys right? Then the question is what we do with defaultPath (deprecate it?)

@jedevc

jedevc commented Aug 12, 2025

Copy link
Copy Markdown
Contributor Author

Hm, one reason to have a separate defaultGit is that in Python/TS/maybe others, the // +default is just part of the syntax: param: Directory = defaultValue.

But you can't do that with Directory as easily param: Directory = "./path/to/directory" because "./path/to/directory" isn't a Directory.

Maybe there's a clever solution here?

@shykes

shykes commented Aug 18, 2025

Copy link
Copy Markdown
Contributor

Hm, one reason to have a separate defaultGit is that in Python/TS/maybe others, the // +default is just part of the syntax: param: Directory = defaultValue.

But you can't do that with Directory as easily param: Directory = "./path/to/directory" because "./path/to/directory" isn't a Directory.

Maybe there's a clever solution here?

I was wondering if the work on standardized "object address" #10770 could help with that? Since it will give us a standardized way to load various objects from a string representation...

Maybe that's a motivation to revisit the language discrepancy problem?

@shykes

shykes commented Aug 19, 2025

Copy link
Copy Markdown
Contributor

I found the original discussion that led to +defaultPath instead of +default. The decision was made because some languages (Python, Typescript) have their own syntax for default values, and we didn't want to perpetually confuse them with two generic ways to set defaults. By narrowing +default to +defaultPath, the idea was to avoid the ambiguity.

@jedevc

jedevc commented Aug 19, 2025

Copy link
Copy Markdown
Contributor Author

@shykes, as discussed (in discord), updated to re-use defaultPath.

@jedevc
jedevc force-pushed the contextual-git branch 2 times, most recently from 4a5e744 to bc898dc Compare August 20, 2025 11:18
@jedevc

jedevc commented Aug 20, 2025

Copy link
Copy Markdown
Contributor Author

Also updated to include dag.CurrentModule().Git() to correspond with dag.CurrentModule().Source().

This can be different from the contextual arg in the case of blueprints. The upstream module will always be at CurrentModule, while the contextual arg will also be the downstream module.

@jedevc
jedevc force-pushed the contextual-git branch 2 times, most recently from c26d07a to 130f97a Compare August 21, 2025 09:02
@jedevc
jedevc requested review from TomChv, helderco and shykes August 21, 2025 09:02
@eunomie
eunomie requested a review from a team as a code owner August 21, 2025 09:35
@eunomie
eunomie force-pushed the contextual-git branch 2 times, most recently from bb42611 to 463fd43 Compare August 21, 2025 09:43
@sipsma

sipsma commented Aug 27, 2025

Copy link
Copy Markdown
Contributor

Was chatting live with @jedevc about this; the relationship between dag.CurrentModule().Git() and caching is tricky and will have some caveats. Module function calls are obviously not cached yet, but they do have cache keys and they will be cached in the near future. Those cache keys are based on the content of the module source itself and any contextual args provided to the function call (or its parents).

This means that even if you specify a branch like main for the ref of the module being invoked, where you'd expect to use the latest commit off main, you can easily get cache hits from old commits if it just so happens that all the file contents for the module source + contextual args are the same.

Example scenario:

  1. You execute dagger -m github.com/foo/bar@main ..., which resolves the module source to github.com/foo/bar@abc123, make some function calls
  2. You push a bunch of commits to main that don't change the module source or any relevant contextual dir args at all. New head is at def456
  3. You execute dagger -m github.com/foo/bar@main ... again

In that scenario, at step 3 the function calls will not actually execute and instead be cached. So if you were expecting the function call to run again and the dag.CurrentModule().Git() call to return the latest commit (def456), you'd be wrong.


I don't think this is the end of the world now that I type it out, but it probably will result in some confusion. If there's no immediate need for dag.CurrentModule().Git() I'd probably air on the side of skipping it for now and sorting more of this out later.

@jedevc

jedevc commented Sep 1, 2025 •

Copy link
Copy Markdown
Contributor Author

Mm, good point. I'm gonna hold off on adding that method just for now - I think just having contextual git should be fine.

I've dropped f1c6d8e (#10847) now, but can easily bring it back if neccessary.

@TomChv TomChv 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.

Left a small review, code lgtm

Comment thread core/modfunc.go Resolved
@jedevc jedevc added this to the v0.18.17 milestone Sep 4, 2025
Also use contextual dirs.

Signed-off-by: Justin Chadwell <[email protected]>
This is *already* done in parsePragmaComment now.

Signed-off-by: Justin Chadwell <[email protected]>
And also track the module source git refs in more detail, this is so
that we can use these for contextual git in a little moment.

Signed-off-by: Justin Chadwell <[email protected]>

@TomChv TomChv 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!

@helderco helderco left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM :shipit:

@TomChv

TomChv commented Sep 4, 2025

Copy link
Copy Markdown
Member

I retriggered the failed job, if they green after I'll merge that PR :)

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.

API to query current git context

6 participants