Skip to content

feat: add git diff functionality - #9968

Closed
jedevc wants to merge 2 commits into
dagger:mainfrom
jedevc:git-diff-dirty
Closed

jedevc wants to merge 2 commits into
dagger:mainfrom
jedevc:git-diff-dirty

Conversation

@jedevc

@jedevc jedevc commented Mar 25, 2025 •

Copy link
Copy Markdown
Contributor

Opening as a base to discuss!

x-linking #8520 for how this should interact with modules (tl;dr we can use contextual git).

Usage

# get the diff of the working directory
$ dagger core host directory --path=. as-git working diff

# get the diff to a specified target
$ dagger core host directory --path=. as-git working diff --target=<commit-sha>

# determine if a git directory is dirty or not
$ dagger core host directory --path=. as-git working dirty

Changes

  • All GitRefs can now be diffed against arbitrary commits.
  • GitRepository.working is a variant of Git.head that gets the current state, but includes any changes to the working directory. This means that:
    • GitRef.diff with no args will return a non-empty diff
    • GitRef.dirty will return true
    • GitRef.tree will return a directory with the working directory changes
    • GitRef.commit returns a <commit>-dirty

Caveats

To debate

  • Is this at all the right API?
    • We can always add more, but it's harder to take it away.
    • Can this be used as useful info for LLMs?
  • Should GitRef.diff take a String? Or a GitRef?

Let the bikeshedding begin!

jedevc added 2 commits March 25, 2025 15:51
Additionally, allow working with dirty working directories. A
potentially dirty directory can be created by calling
`Directory.asGit.working`.

Signed-off-by: Justin Chadwell <[email protected]>
Signed-off-by: Justin Chadwell <[email protected]>
@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.

@jedevc

jedevc commented Apr 22, 2025

Copy link
Copy Markdown
Contributor Author

Leaving this as a note - but I don't think this is the right API.

Having dirty state encoded as refs is weird, and can result in inconsistencies. I was thinking about adding a new type, like GitState? That would at least keep operations type-safe.

But yeah, not particularly sure. Essentially, this just needs to be discoverable somehow so we could build it into agent tooling.

@github-actions

github-actions Bot commented May 7, 2025

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 May 14, 2025
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.

1 participant