Skip to content

✨ Add remote fetching (tags, branches) to Git functionality #10200

Closed

Description

@nipuna-perera

What are you trying to do?

I'm running source.AsGit().WithAuthToken().Tags(ctx) and realized it won't show the remote tags because it doesn't do a fetch. Would it be possible to add a AsGit().Fetch(branch or all)?

Why is this important to you?

The AsGit is very useful but I can't use it because I need to fetch before doing much with the repo. The fetch itself requires a PAT so I have to set up all of that whereas AsGit().WithAuthToken() handles it.

How are you currently working around this?

Setting up all the plumbing necessary inside the container like this #9858

I also think some of this is related to the work @jedevc is doing in #10195, #7637, #9980 and #9968

@shykes suggested source.AsGit().Remote("origin").Tags() as that preents side-effects.

Activity

  1. jedevc commented on Apr 22, 2025

    @jedevc
    Contributor

    Mm, very reasonable, I've also wanted this.

    I like source.AsGit().Remote("origin").Tags(), which would then look up "origin" in the target repository, which would then be the remote "origin", and return it as another GitRepository.

    A couple little notes:

    • Where do the auths go? I'm kind of leaning towards putting them as args to Remote which mirrors how the args in the git top-level constructor work. I think being able to do WithAuthToken on a result from AsGit is a bit of an anti-pattern, since an auth token isn't used for a directory here (so I'd like to deprecated those).
    • Remote naming becomes pretty important. e.g. origin/upstream/etc - users might name these differently - is that an issue?
  2. shykes commented on Apr 23, 2025

    @shykes
    Contributor

    @jedevc would the host's auth be loaded implicitly by default? PAT etc?

  3. jedevc commented on Apr 24, 2025

    @jedevc
    Contributor

    Likely, yes, just as if you were to do dag.Git("url").

    I think that makes the most sense (and probably easiest to implement in terms of behavior).

    Edit: actually, we should probably do in this order:

    1. Attempt to use the same credentials as accessing the base git object
    2. Otherwise load from the client
    3. Just skip over this, and the next git operations will fail (unless then followed by the to-be-deprecated WithAuthToken/WithAuthHeader methods)
  4. jedevc commented on May 15, 2025

    @jedevc
    Contributor

    Hm, just realized that it's really not possible to implement this for remote git providers - it's only valid for local git: Directory.asGit.remote is valid, git.remote isn't.

    It would be really cool if we could somehow have it follow fork/upstream relationships, but there's no way to get this generically from the Git API - we'd have to implement provider-specific integrations (which I was hoping to avoid, since it's a pain).

  5. jedevc commented on Jul 31, 2025

    @jedevc
    Contributor

    Authentication aside, I ran into a super concrete thing we need in our own CI.

    If I specify a high --depth, and the local directory for dir.asGit is a shallow clone, we should fallback to fetching any history from the remotes.

  6. locked and limited conversation to collaborators on Mar 25, 2026
  7. converted this issue into a discussion #12646 on Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions