Skip to content

API to query current git context #8520

Closed

Description

@shykes

Problem

Sometimes I need information about the current state of the git repository for my context. Things like:

  • What's the current commit?
  • What's the current branch?
  • What tags point to the current commit?
  • Is this a clean checkout? If not, what are the uncommitted changes?
  • What's the remote?

I can get some of this information indirectly with hacks, but it's not 100% reliable.

Solution

Add a core API to introspect git information about the context.

Activity

  1. jedevc commented on Sep 23, 2024

    @jedevc
    Contributor

    Is this essentially "contextual git repo" arguments?

    Here's my suggestion:

    • We extend // +defaultPath=<path> to allow annotating dagger.Git args. The path in this case becomes a path to a .git directory (or maybe to a directory containing a .git directory).
    • We extend // +defaultPath=<path> to allow annotating dagger.GitRef args. The path in this case becomes a path to a checkout of a directory.
    • Then, we modify the core Git type - the default implementation is still created from the dag.Git query, but we also allow sourcing it from the client automatically using a session attachable.
      • While we're here, we could also allow creating a git directory using Directory.AsGit.
    • We extend the Git API to allow getting better information about the current commit/branch/tags, working out dirtiness, remotes, etc.

    We need to be careful though, and make sure that this behaves the same as the contextual directory - i.e. loading from the callee. When I get a contextual git repo, I want the repo for the callee. But need to think through this - I think it's a much less common use case, the common case is going to be things like our suggestion version module.

  2. shykes commented on Dec 6, 2024

    @shykes
    ContributorAuthor

    @jedevc did I understand correctly that you're working on this? If so, I'll assign so you can take it over

  3. beingminimal commented on Dec 10, 2024

    @beingminimal

    @jedevc git diff command will be supported?

  4. jedevc commented on Dec 19, 2024

    @jedevc
    Contributor

    x-linking #8720 (which is related, because it establishes the concept of "git backends", which we'd use for this)

  5. jedevc commented on Dec 19, 2024

    @jedevc
    Contributor

    @jedevc git diff command will be supported?

    Design still up in the air, but essentially you'll get back a Git type in the API - whatever you can do with that, you can do with the current git context.

    I don't think diff will directly be supported - but you'll still be able to call Git.tree and then mount it into a container with git installed to do the operation yourself. We'll see 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions