Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Git inputs cannot reference tags with the ref option #2932

Closed
mloesch opened this issue Apr 30, 2024 · 2 comments · Fixed by #3095
Closed

Git inputs cannot reference tags with the ref option #2932

mloesch opened this issue Apr 30, 2024 · 2 comments · Fixed by #3095
Assignees
Labels
Bug Something isn't working

Comments

@mloesch
Copy link

mloesch commented Apr 30, 2024

As far as I understand, git branches and tags are types of git refs (they are stored under .git/refs).

IMO it should therefore be possible to use the ref option as a generic way for referencing commits, branches, and tags.

This is actually stated in the documentation:

Any ref that is a valid input to git checkout is accepted.

https://buf.build/docs/reference/inputs#other-options

However, while git checkout remote-tag is working, buf generate "ssh://git@github.com/path-to-repo.git#ref=remote-tag" is not.

IMO this feature would make parameterizing CI pipelines easier, e.g.:

  • ssh://git@github.com/path-to-repo.git#ref=develop - build against latest changes on the develop branch
  • ssh://git@github.com/path-to-repo.git#ref=v1.0.0 - build against a stable release tag

Note: this is also how kubectl kustomize is implementing the refoption:

ref - a git fetch-able ref, typically a branch, tag, or full commit hash (short hashes are not supported)

https://github.com/kubernetes-sigs/kustomize/blob/master/examples/remoteBuild.md#remote-directories

@srikrsna-buf
Copy link
Member

I can reproduce this with:

buf build "https://github.com/bufbuild/buf.git#ref=v1.27.0,subdir=proto"

The same works when I use tag:

buf build "https://github.com/bufbuild/buf.git#tag=v1.27.0,subdir=proto"

Thank you for reporting, we'll look into this.

@srikrsna-buf srikrsna-buf added the Bug Something isn't working label Apr 30, 2024
@bufdev bufdev changed the title git inputs: ref option should allow branches and tags Git inputs cannot reference tags with the ref option May 18, 2024
emcfarlane added a commit that referenced this issue Jul 23, 2024
This changes the git ref input to align with the git notion of a ref as
a tag or branch. We now always try to fetch a given ref before falling
back to fetching the HEAD to resolve partial refs. If both a ref and
branch are provided, the branch is fetched directly before resolving the
ref. The inputs `tag` and `commit` can still be used but can now be
replaced by setting the `ref`.

For example:
 - Branch `ref=main` will fetch and checkout the `main` branch
 - Tag `ref=v1.0.0` will fetch and checkout the `v1.0.0` tag
 - Partial `ref=123456` will fetch `HEAD` and checkout `123456`
- Branch with partial `ref=123456,branch=feature` will fetch `feature`
and checkout `123456`
 - Commit `ref=<sha>` will fetch `<sha>` and checkout `<sha>`
- Branch with commit `ref=<sha>,branch=feature` with fetch `feature` and
checkout `<sha>`

Fixes #2932
@emcfarlane
Copy link
Contributor

Fix will go out in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants